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