updated RadioSwatch to new color config
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
3825488d0e
commit
66c39fb701
@ -13,6 +13,15 @@ import Combine
|
||||
|
||||
@objc(VDSRadioSwatch)
|
||||
public class RadioSwatch: RadioSwatchBase{
|
||||
//for groups allows "toggle"
|
||||
open override func toggle() {
|
||||
print("toggle: \(text)")
|
||||
isSelected.toggle()
|
||||
}
|
||||
}
|
||||
|
||||
@objc(VDSSoloRadioSwatch)
|
||||
public class SolorRadioSwatch: RadioSwatchBase{
|
||||
public override func initialSetup() {
|
||||
super.initialSetup()
|
||||
publisher(for: .touchUpInside)
|
||||
@ -92,15 +101,10 @@ open class RadioSwatchBase: Control, Accessable, DataTrackable, BinaryColorable
|
||||
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(selectorView)
|
||||
|
||||
selectorView.isUserInteractionEnabled = false
|
||||
selectorView.addSubview(fillView)
|
||||
|
||||
selectorView.pinToSuperView()
|
||||
@ -153,6 +157,7 @@ open class RadioSwatchBase: Control, Accessable, DataTrackable, BinaryColorable
|
||||
setAccessibilityHint()
|
||||
setAccessibilityValue(isSelected)
|
||||
setAccessibilityLabel(isSelected)
|
||||
print("updateView: \(text)")
|
||||
layer.setNeedsDisplay()
|
||||
}
|
||||
|
||||
@ -165,33 +170,12 @@ open class RadioSwatchBase: Control, Accessable, DataTrackable, BinaryColorable
|
||||
public let fillSize = CGSize(width: 36, height: 36)
|
||||
public let disabledAlpha = 0.5
|
||||
|
||||
private var radioSwatchBackgroundColorConfiguration = BinaryDisabledSurfaceColorConfiguration().with {
|
||||
$0.forFalse.enabled.lightColor = VDSFormControlsColor.backgroundOnlight
|
||||
$0.forFalse.enabled.darkColor = VDSFormControlsColor.backgroundOndark
|
||||
$0.forFalse.disabled.lightColor = VDSFormControlsColor.backgroundOnlight
|
||||
$0.forFalse.disabled.darkColor = VDSFormControlsColor.backgroundOndark
|
||||
$0.forTrue.enabled.lightColor = VDSFormControlsColor.backgroundOnlight
|
||||
$0.forTrue.enabled.darkColor = VDSFormControlsColor.backgroundOndark
|
||||
$0.forTrue.disabled.lightColor = VDSFormControlsColor.backgroundOnlight
|
||||
$0.forTrue.disabled.darkColor = VDSFormControlsColor.backgroundOndark
|
||||
}
|
||||
|
||||
private var radioSwatchBorderColorConfiguration = BinaryDisabledSurfaceColorConfiguration().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
|
||||
}
|
||||
|
||||
private var radioSwatchFillBorderColorConfiguration = DisabledSurfaceColorConfiguration().with {
|
||||
$0.enabled.lightColor = VDSColor.elementsPrimaryOnlight
|
||||
$0.enabled.darkColor = VDSColor.elementsPrimaryOndark
|
||||
$0.disabled.lightColor = VDSColor.interactiveDisabledOnlight
|
||||
$0.disabled.darkColor = VDSColor.interactiveDisabledOndark
|
||||
private var borderColorConfiguration = ControlColorConfiguration().with {
|
||||
$0.setSurfaceColors(VDSFormControlsColor.borderOnlight, VDSFormControlsColor.borderOndark, forState: .normal)
|
||||
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled)
|
||||
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .highlighted)
|
||||
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .selected)
|
||||
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled])
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -213,14 +197,15 @@ open class RadioSwatchBase: Control, Accessable, DataTrackable, BinaryColorable
|
||||
}
|
||||
|
||||
open override func draw(_ layer: CALayer, in ctx: CGContext) {
|
||||
|
||||
let backgroundColor = radioSwatchBackgroundColorConfiguration.getColor(self)
|
||||
let borderColor = isSelected ? radioSwatchBorderColorConfiguration.getColor(self) : .clear
|
||||
let fillBorderColor = radioSwatchFillBorderColorConfiguration.getColor(self)
|
||||
print("draw:\(text)")
|
||||
let drawOuterBorder = isSelected || isHighlighted
|
||||
let backgroundColor = UIColor.clear
|
||||
let borderColor = isSelected ? borderColorConfiguration.getColor(self) : .clear
|
||||
let fillBorderColor = borderColorConfiguration.getColor(self)
|
||||
selectorView.backgroundColor = backgroundColor
|
||||
selectorView.layer.borderColor = borderColor.cgColor
|
||||
selectorView.layer.cornerRadius = selectorView.bounds.width * 0.5
|
||||
selectorView.layer.borderWidth = isSelected ? selectorBorderWidth : 0
|
||||
selectorView.layer.borderWidth = drawOuterBorder ? selectorBorderWidth : 0
|
||||
selectorView.layer.masksToBounds = true
|
||||
|
||||
gradientLayer?.removeFromSuperlayer()
|
||||
@ -258,7 +243,7 @@ open class RadioSwatchBase: Control, Accessable, DataTrackable, BinaryColorable
|
||||
shapeLayer = nil
|
||||
|
||||
if strikethrough {
|
||||
let strikeThroughBorderColor = radioSwatchBorderColorConfiguration.getColor(self)
|
||||
let strikeThroughBorderColor = borderColorConfiguration.getColor(self)
|
||||
let bounds = selectorView.bounds
|
||||
let length = max(bounds.size.height, bounds.size.width)
|
||||
guard length > 0.0, shapeLayer == nil else { return }
|
||||
|
||||
@ -16,6 +16,7 @@ public class RadioSwatchGroup: RadioSwatchGroupBase<RadioSwatch> {
|
||||
selectedHandler?.toggle()
|
||||
selector.toggle()
|
||||
label.text = selector.text
|
||||
didChange()
|
||||
valueChanged()
|
||||
}
|
||||
|
||||
@ -157,7 +158,11 @@ public class RadioSwatchGroupBase<HandlerType: RadioSwatchBase>: SelectorGroupSe
|
||||
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath)
|
||||
let handler = selectorViews[indexPath.row]
|
||||
handler.isUserInteractionEnabled = false
|
||||
handler.subscribers.forEach{ $0.cancel() }
|
||||
handler.subscribers.removeAll()
|
||||
handler.publisher(for: .touchUpInside).sink { [weak self] handler in
|
||||
self?.didSelect(selector: handler)
|
||||
}.store(in: &handler.subscribers)
|
||||
cell.subviews.forEach { $0.removeFromSuperview() }
|
||||
cell.addSubview(handler)
|
||||
handler.pinToSuperView()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user