updated color logic
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
0b8d585354
commit
5cfd3c379d
@ -25,44 +25,40 @@ import Combine
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Private Properties
|
// MARK: - Private Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private var toggleTintColor: (on: UIColor, off: UIColor) {
|
private func getToggleColor(viewModel: ModelType) -> UIColor {
|
||||||
return getToggleColor(for: disabled, surface: surface)
|
var colors: (on: UIColor, off: UIColor)
|
||||||
}
|
if viewModel.disabled {
|
||||||
|
if viewModel.surface == .light {
|
||||||
private var knobTintColor: (on: UIColor, off: UIColor) {
|
colors = (on: VDSColor.interactiveDisabledOnlight, off: VDSColor.interactiveDisabledOnlight)
|
||||||
return getKnobColor(for: disabled, surface: surface)
|
|
||||||
}
|
|
||||||
|
|
||||||
private func getToggleColor(for disabled: Bool, surface: Surface) -> (on: UIColor, off: UIColor) {
|
|
||||||
if disabled {
|
|
||||||
if surface == .light {
|
|
||||||
return (on: VDSColor.interactiveDisabledOnlight, off: VDSColor.interactiveDisabledOnlight)
|
|
||||||
} else {
|
} else {
|
||||||
return (on: VDSColor.interactiveDisabledOndark, off: VDSColor.interactiveDisabledOndark)
|
colors = (on: VDSColor.interactiveDisabledOndark, off: VDSColor.interactiveDisabledOndark)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if surface == .light {
|
if viewModel.surface == .light {
|
||||||
return (on: VDSColor.paletteGreen26, off: VDSColor.elementsSecondaryOnlight)
|
colors = (on: VDSColor.paletteGreen26, off: VDSColor.elementsSecondaryOnlight)
|
||||||
} else {
|
} else {
|
||||||
return (on: VDSColor.paletteGreen34, off: VDSColor.paletteGray44)
|
colors = (on: VDSColor.paletteGreen34, off: VDSColor.paletteGray44)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return viewModel.on ? colors.on : colors.off
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getKnobColor(for disabled: Bool, surface: Surface) -> (on: UIColor, off: UIColor) {
|
private func getKnobColor(viewModel: ModelType) -> UIColor {
|
||||||
if disabled {
|
var colors: (on: UIColor, off: UIColor)
|
||||||
if surface == .light {
|
if viewModel.disabled {
|
||||||
return (on: VDSColor.paletteGray95, off: VDSColor.paletteGray95)
|
if viewModel.surface == .light {
|
||||||
|
colors = (on: VDSColor.paletteGray95, off: VDSColor.paletteGray95)
|
||||||
} else {
|
} else {
|
||||||
return (on: VDSColor.paletteGray44, off: VDSColor.paletteGray44)
|
colors = (on: VDSColor.paletteGray44, off: VDSColor.paletteGray44)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if surface == .light {
|
if viewModel.surface == .light {
|
||||||
return (on: VDSColor.elementsPrimaryOndark, off: VDSColor.elementsPrimaryOndark)
|
colors = (on: VDSColor.elementsPrimaryOndark, off: VDSColor.elementsPrimaryOndark)
|
||||||
} else {
|
} else {
|
||||||
return (on: VDSColor.elementsPrimaryOndark, off: VDSColor.elementsPrimaryOndark)
|
colors = (on: VDSColor.elementsPrimaryOndark, off: VDSColor.elementsPrimaryOndark)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return viewModel.on ? colors.on : colors.off
|
||||||
}
|
}
|
||||||
|
|
||||||
private var showTextSpacing: CGFloat {
|
private var showTextSpacing: CGFloat {
|
||||||
@ -225,7 +221,7 @@ import Combine
|
|||||||
toggleView.layer.cornerRadius = toggleSize.height / 2.0
|
toggleView.layer.cornerRadius = toggleSize.height / 2.0
|
||||||
knobView.layer.cornerRadius = knobSize.height / 2.0
|
knobView.layer.cornerRadius = knobSize.height / 2.0
|
||||||
|
|
||||||
toggleView.backgroundColor = toggleTintColor.off
|
toggleView.backgroundColor = getToggleColor(viewModel: model)
|
||||||
|
|
||||||
toggleView.addSubview(knobView)
|
toggleView.addSubview(knobView)
|
||||||
|
|
||||||
@ -261,9 +257,8 @@ import Combine
|
|||||||
|
|
||||||
public override func reset() {
|
public override func reset() {
|
||||||
super.reset()
|
super.reset()
|
||||||
|
toggleView.backgroundColor = getToggleColor(viewModel: model)
|
||||||
toggleView.backgroundColor = toggleTintColor.off
|
knobView.backgroundColor = getKnobColor(viewModel: model)
|
||||||
knobView.backgroundColor = knobTintColor.off
|
|
||||||
setAccessibilityLabel()
|
setAccessibilityLabel()
|
||||||
onChange = nil
|
onChange = nil
|
||||||
}
|
}
|
||||||
@ -357,17 +352,17 @@ import Combine
|
|||||||
self.layoutIfNeeded()
|
self.layoutIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
let toggleColor = getToggleColor(for: viewModel.disabled, surface: viewModel.surface)
|
let toggleColor = getToggleColor(viewModel: viewModel)
|
||||||
let knobColor = getKnobColor(for: viewModel.disabled, surface: viewModel.surface)
|
let knobColor = getKnobColor(viewModel: viewModel)
|
||||||
|
|
||||||
if viewModel.disabled {
|
if viewModel.disabled {
|
||||||
toggleView.backgroundColor = viewModel.on ? toggleColor.on : toggleColor.off
|
toggleView.backgroundColor = toggleColor
|
||||||
knobView.backgroundColor = viewModel.on ? knobColor.on : knobColor.off
|
knobView.backgroundColor = knobColor
|
||||||
constrainKnob()
|
constrainKnob()
|
||||||
} else {
|
} else {
|
||||||
UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseIn, animations: {
|
UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseIn, animations: {
|
||||||
self.toggleView.backgroundColor = viewModel.on ? toggleColor.on : toggleColor.off
|
self.toggleView.backgroundColor = toggleColor
|
||||||
self.knobView.backgroundColor = viewModel.on ? knobColor.on : knobColor.off
|
self.knobView.backgroundColor = knobColor
|
||||||
}, completion: nil)
|
}, completion: nil)
|
||||||
|
|
||||||
UIView.animate(withDuration: 0.33, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.5, options: [], animations: {
|
UIView.animate(withDuration: 0.33, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.5, options: [], animations: {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user