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