refactored button
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
9fcff48752
commit
431ea81ad9
@ -39,7 +39,7 @@ open class Button: ButtonBase, Useable {
|
|||||||
open var width: CGFloat? { didSet { didChange() }}
|
open var width: CGFloat? { didSet { didChange() }}
|
||||||
|
|
||||||
open override var textColor: UIColor {
|
open override var textColor: UIColor {
|
||||||
buttonTitleColorConfiguration.getColor(self)
|
textColorConfiguration.getColor(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
open override var typograpicalStyle: TypographicalStyle {
|
open override var typograpicalStyle: TypographicalStyle {
|
||||||
@ -49,58 +49,52 @@ open class Button: ButtonBase, Useable {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Configuration Properties
|
// MARK: - Configuration Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private var buttonBackgroundColorConfiguration = UseableColorConfiguration().with {
|
|
||||||
$0.primary.enabled.lightColor = VDSColor.backgroundPrimaryDark
|
// Background Color Config
|
||||||
$0.primary.enabled.darkColor = VDSColor.backgroundPrimaryLight
|
private var primaryBackgroundColorConfiguration = ControlColorConfiguration().with {
|
||||||
$0.primary.disabled.lightColor = VDSColor.interactiveDisabledOnlight
|
$0.setSurfaceColors(VDSColor.backgroundPrimaryDark, VDSColor.backgroundPrimaryLight, forState: .normal)
|
||||||
$0.primary.disabled.darkColor = VDSColor.interactiveDisabledOndark
|
$0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted)
|
||||||
|
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled)
|
||||||
|
}
|
||||||
|
|
||||||
$0.primaryHighlighted.lightColor = VDSColor.interactiveActiveOnlight
|
private var secondaryBackgroundColorConfiguration = ControlColorConfiguration()
|
||||||
$0.primaryHighlighted.darkColor = VDSColor.interactiveActiveOndark
|
|
||||||
|
|
||||||
$0.secondary.enabled.lightColor = UIColor.clear
|
|
||||||
$0.secondary.enabled.darkColor = UIColor.clear
|
|
||||||
$0.secondary.disabled.lightColor = UIColor.clear
|
|
||||||
$0.secondary.disabled.darkColor = UIColor.clear
|
|
||||||
|
|
||||||
$0.secondaryHighlighted.lightColor = UIColor.clear
|
private var backgroundColorConfiguration: ControlColorConfiguration{
|
||||||
$0.secondaryHighlighted.darkColor = UIColor.clear
|
use == .primary ? primaryBackgroundColorConfiguration : secondaryBackgroundColorConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
private var buttonBorderColorConfiguration = UseableColorConfiguration().with {
|
// Border Color Config
|
||||||
$0.primary.enabled.lightColor = VDSColor.elementsPrimaryOndark
|
private var primaryBorderColorConfiguration = ControlColorConfiguration().with {
|
||||||
$0.primary.enabled.darkColor = VDSColor.elementsPrimaryOnlight
|
$0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: .normal)
|
||||||
$0.primary.disabled.lightColor = VDSColor.interactiveDisabledOnlight
|
$0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: .highlighted)
|
||||||
$0.primary.disabled.darkColor = VDSColor.interactiveDisabledOndark
|
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled)
|
||||||
|
|
||||||
$0.primaryHighlighted.lightColor = VDSColor.elementsPrimaryOndark
|
|
||||||
$0.primaryHighlighted.darkColor = VDSColor.elementsPrimaryOnlight
|
|
||||||
|
|
||||||
$0.secondary.enabled.lightColor = VDSColor.elementsPrimaryOnlight
|
|
||||||
$0.secondary.enabled.darkColor = VDSColor.elementsPrimaryOndark
|
|
||||||
$0.secondary.disabled.lightColor = VDSColor.interactiveDisabledOnlight
|
|
||||||
$0.secondary.disabled.darkColor = VDSColor.interactiveDisabledOndark
|
|
||||||
|
|
||||||
$0.secondaryHighlighted.lightColor = VDSColor.interactiveActiveOnlight
|
|
||||||
$0.secondaryHighlighted.darkColor = VDSColor.interactiveActiveOndark
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var buttonTitleColorConfiguration = UseableColorConfiguration().with {
|
private var secondaryBorderColorConfiguration = ControlColorConfiguration().with {
|
||||||
$0.primary.enabled.lightColor = VDSColor.elementsPrimaryOndark
|
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .normal)
|
||||||
$0.primary.enabled.darkColor = VDSColor.elementsPrimaryOnlight
|
$0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted)
|
||||||
$0.primary.disabled.lightColor = VDSColor.elementsPrimaryOndark
|
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled)
|
||||||
$0.primary.disabled.darkColor = VDSColor.elementsPrimaryOnlight
|
}
|
||||||
|
|
||||||
|
private var borderColorConfiguration: ControlColorConfiguration {
|
||||||
|
use == .primary ? primaryBorderColorConfiguration : secondaryBorderColorConfiguration
|
||||||
|
}
|
||||||
|
|
||||||
$0.primaryHighlighted.lightColor = VDSColor.elementsPrimaryOndark
|
// Text Color Config
|
||||||
$0.primaryHighlighted.darkColor = VDSColor.elementsPrimaryOnlight
|
private var primaryTextColorConfiguration = ControlColorConfiguration().with {
|
||||||
|
$0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: .normal)
|
||||||
$0.secondary.enabled.lightColor = VDSColor.elementsPrimaryOnlight
|
$0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: .highlighted)
|
||||||
$0.secondary.enabled.darkColor = VDSColor.elementsPrimaryOndark
|
$0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: .disabled)
|
||||||
$0.secondary.disabled.lightColor = VDSColor.interactiveDisabledOnlight
|
}
|
||||||
$0.secondary.disabled.darkColor = VDSColor.interactiveDisabledOndark
|
|
||||||
|
private var secondaryTextColorConfiguration = ControlColorConfiguration().with {
|
||||||
$0.secondaryHighlighted.lightColor = VDSColor.interactiveActiveOnlight
|
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .normal)
|
||||||
$0.secondaryHighlighted.darkColor = VDSColor.interactiveActiveOndark
|
$0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted)
|
||||||
|
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var textColorConfiguration: ControlColorConfiguration {
|
||||||
|
use == .primary ? primaryTextColorConfiguration : secondaryTextColorConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -150,8 +144,8 @@ open class Button: ButtonBase, Useable {
|
|||||||
|
|
||||||
open override func updateView() {
|
open override func updateView() {
|
||||||
super.updateView()
|
super.updateView()
|
||||||
let bgColor = buttonBackgroundColorConfiguration.getColor(self)
|
let bgColor = backgroundColorConfiguration.getColor(self)
|
||||||
let borderColor = buttonBorderColorConfiguration.getColor(self)
|
let borderColor = borderColorConfiguration.getColor(self)
|
||||||
let borderWidth = use == .secondary ? 1.0 : 0.0
|
let borderWidth = use == .secondary ? 1.0 : 0.0
|
||||||
let buttonHeight = size.height
|
let buttonHeight = size.height
|
||||||
let cornerRadius = size.cornerRadius
|
let cornerRadius = size.cornerRadius
|
||||||
@ -183,27 +177,20 @@ open class Button: ButtonBase, Useable {
|
|||||||
|
|
||||||
private class UseableColorConfiguration: ObjectColorable {
|
private class UseableColorConfiguration: ObjectColorable {
|
||||||
typealias ObjectType = Buttonable & Useable
|
typealias ObjectType = Buttonable & Useable
|
||||||
public var primary = DisabledSurfaceColorConfiguration()
|
public var primary = ControlStateColorConfiguration()
|
||||||
public var secondary = DisabledSurfaceColorConfiguration()
|
public var secondary = ControlStateColorConfiguration()
|
||||||
|
|
||||||
public var primaryHighlighted = SurfaceColorConfiguration()
|
|
||||||
public var secondaryHighlighted = SurfaceColorConfiguration()
|
|
||||||
|
|
||||||
required public init(){}
|
required public init(){}
|
||||||
|
|
||||||
public func getColor(_ object: ObjectType) -> UIColor {
|
public func getColor(_ object: ObjectType) -> UIColor {
|
||||||
if object.isHighlighted {
|
return object.use == .primary ? primary.getColor(object) : secondary.getColor(object)
|
||||||
return object.use == .primary ? primaryHighlighted.getColor(object) : secondaryHighlighted.getColor(object)
|
|
||||||
} else {
|
|
||||||
return object.use == .primary ? primary.getColor(object) : secondary.getColor(object)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ButtonSize {
|
fileprivate extension ButtonSize {
|
||||||
|
|
||||||
public var height: CGFloat {
|
var height: CGFloat {
|
||||||
switch self {
|
switch self {
|
||||||
case .large:
|
case .large:
|
||||||
return 44
|
return 44
|
||||||
@ -212,11 +199,11 @@ extension ButtonSize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public var cornerRadius: CGFloat {
|
var cornerRadius: CGFloat {
|
||||||
height / 2
|
height / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
public var minimumWidth: CGFloat {
|
var minimumWidth: CGFloat {
|
||||||
switch self {
|
switch self {
|
||||||
case .large:
|
case .large:
|
||||||
return 76
|
return 76
|
||||||
@ -225,7 +212,7 @@ extension ButtonSize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public var edgeInsets: UIEdgeInsets {
|
var edgeInsets: UIEdgeInsets {
|
||||||
var verticalPadding = 0.0
|
var verticalPadding = 0.0
|
||||||
var horizontalPadding = 0.0
|
var horizontalPadding = 0.0
|
||||||
switch self {
|
switch self {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user