refacored checkbox to new color states
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
4ac73e3d38
commit
77f957b23f
@ -125,8 +125,25 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er
|
||||
}
|
||||
}
|
||||
|
||||
open var showError: Bool = false { didSet { didChange() }}
|
||||
open var showError: Bool = false {
|
||||
didSet {
|
||||
if showError && isSelected {
|
||||
isSelected.toggle()
|
||||
}
|
||||
didChange()
|
||||
}
|
||||
}
|
||||
|
||||
open override var state: UIControl.State {
|
||||
get {
|
||||
var state = super.state
|
||||
if showError {
|
||||
state.insert(.error)
|
||||
}
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
open var errorText: String? { didSet { didChange() }}
|
||||
|
||||
open var inputId: String? { didSet { didChange() }}
|
||||
@ -162,18 +179,13 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er
|
||||
//--------------------------------------------------
|
||||
// MARK: - Lifecycle
|
||||
//--------------------------------------------------
|
||||
|
||||
open override func setup() {
|
||||
super.setup()
|
||||
|
||||
//add tapGesture to self
|
||||
publisher(for: UITapGestureRecognizer()).sink { [weak self] _ in
|
||||
self?.sendActions(for: .touchUpInside)
|
||||
}.store(in: &subscribers)
|
||||
|
||||
|
||||
isAccessibilityElement = true
|
||||
accessibilityTraits = .button
|
||||
addSubview(mainStackView)
|
||||
mainStackView.isUserInteractionEnabled = false
|
||||
|
||||
mainStackView.addArrangedSubview(selectorStackView)
|
||||
mainStackView.addArrangedSubview(errorLabel)
|
||||
@ -313,45 +325,34 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er
|
||||
//--------------------------------------------------
|
||||
public let checkboxSize = CGSize(width: 20, height: 20)
|
||||
|
||||
private var checkboxBackgroundColorConfiguration: ErrorBinaryDisabledSurfaceColorConfiguration = {
|
||||
return ErrorBinaryDisabledSurfaceColorConfiguration().with {
|
||||
$0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOnlight
|
||||
$0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark
|
||||
$0.forTrue.disabled.lightColor = VDSColor.interactiveDisabledOnlight
|
||||
$0.forTrue.disabled.darkColor = VDSColor.interactiveDisabledOndark
|
||||
//error doesn't care enabled/disable
|
||||
$0.error.forTrue.lightColor = VDSColor.elementsPrimaryOnlight
|
||||
$0.error.forTrue.darkColor = VDSColor.elementsPrimaryOndark
|
||||
$0.error.forFalse.lightColor = VDSColor.feedbackErrorBackgroundOnlight
|
||||
$0.error.forFalse.darkColor = VDSColor.feedbackErrorBackgroundOndark
|
||||
}
|
||||
}()
|
||||
|
||||
private var checkboxBorderColorConfiguration: ErrorBinaryDisabledSurfaceColorConfiguration = {
|
||||
return ErrorBinaryDisabledSurfaceColorConfiguration().with {
|
||||
$0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOnlight
|
||||
$0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark
|
||||
$0.forFalse.enabled.lightColor = VDSFormControlsColor.borderOnlight
|
||||
$0.forFalse.enabled.darkColor = VDSFormControlsColor.borderOndark
|
||||
$0.forTrue.disabled.lightColor = VDSColor.interactiveDisabledOnlight
|
||||
$0.forTrue.disabled.darkColor = VDSColor.interactiveDisabledOndark
|
||||
$0.forFalse.disabled.lightColor = VDSColor.interactiveDisabledOnlight
|
||||
$0.forFalse.disabled.darkColor = VDSColor.interactiveDisabledOndark
|
||||
//error doesn't care enabled/disable
|
||||
$0.error.forTrue.lightColor = VDSColor.elementsPrimaryOnlight
|
||||
$0.error.forTrue.darkColor = VDSColor.elementsPrimaryOndark
|
||||
$0.error.forFalse.lightColor = VDSColor.feedbackErrorOnlight
|
||||
$0.error.forFalse.darkColor = VDSColor.feedbackErrorOndark
|
||||
}
|
||||
private var checkboxBackgroundColorConfig: ControlColorConfiguration = {
|
||||
var config = ControlColorConfiguration()
|
||||
config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.selected])
|
||||
config.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled])
|
||||
config.setSurfaceColors(VDSColor.feedbackErrorBackgroundOnlight, VDSColor.feedbackErrorBackgroundOndark, forState: [.error])
|
||||
return config
|
||||
}()
|
||||
|
||||
private var checkboxCheckColorConfiguration: BinarySurfaceColorConfiguration = {
|
||||
return BinarySurfaceColorConfiguration().with {
|
||||
$0.forTrue.lightColor = VDSColor.elementsPrimaryOndark
|
||||
$0.forTrue.darkColor = VDSColor.elementsPrimaryOnlight
|
||||
}
|
||||
private var checkboxBorderColorConfig: ControlColorConfiguration = {
|
||||
var config = ControlColorConfiguration()
|
||||
config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.selected])
|
||||
config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.highlighted])
|
||||
config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.error, .highlighted])
|
||||
config.setSurfaceColors(VDSFormControlsColor.borderOnlight, VDSFormControlsColor.borderOndark, forState: [.normal])
|
||||
config.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled])
|
||||
config.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.normal, .disabled])
|
||||
config.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.error, .disabled])
|
||||
config.setSurfaceColors(VDSColor.feedbackErrorOnlight, VDSColor.feedbackErrorOndark, forState: [.error])
|
||||
return config
|
||||
}()
|
||||
|
||||
|
||||
private var checkboxCheckColorConfig: ControlColorConfiguration = {
|
||||
var config = ControlColorConfiguration()
|
||||
config.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: .selected)
|
||||
config.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: [.selected, .disabled])
|
||||
return config
|
||||
}()
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Checkbox View
|
||||
//--------------------------------------------------
|
||||
@ -364,9 +365,9 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er
|
||||
|
||||
open func updateSelector() {
|
||||
//get the colors
|
||||
let backgroundColor = checkboxBackgroundColorConfiguration.getColor(self)
|
||||
let borderColor = checkboxBorderColorConfiguration.getColor(self)
|
||||
let checkColor = checkboxCheckColorConfiguration.getColor(self)
|
||||
let backgroundColor = checkboxBackgroundColorConfig.getColor(self)
|
||||
let borderColor = checkboxBorderColorConfig.getColor(self)
|
||||
let checkColor = checkboxCheckColorConfig.getColor(self)
|
||||
|
||||
if let shapeLayer = shapeLayer, let sublayers = layer.sublayers, sublayers.contains(shapeLayer) {
|
||||
shapeLayer.removeFromSuperlayer()
|
||||
@ -413,27 +414,3 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Color Class Configurations
|
||||
//--------------------------------------------------
|
||||
internal class ErrorBinaryDisabledSurfaceColorConfiguration: BinaryDisabledSurfaceColorable {
|
||||
typealias ObjectType = Errorable & Disabling & Surfaceable & BinaryColorable
|
||||
var error = BinarySurfaceColorConfiguration()
|
||||
var forTrue = DisabledSurfaceColorConfiguration()
|
||||
var forFalse = DisabledSurfaceColorConfiguration()
|
||||
|
||||
required init() {}
|
||||
|
||||
func getColor(_ object: ObjectType) -> UIColor {
|
||||
//only show error is enabled and showError == true
|
||||
let showErrorColor = !object.disabled && object.showError
|
||||
|
||||
if showErrorColor {
|
||||
return error.getColor(object)
|
||||
} else {
|
||||
return getBinaryColor(object)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user