removed default models
added accessibility Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
d33f672350
commit
482d3854a1
@ -17,30 +17,6 @@ import Combine
|
||||
Container: The background of the toggle control.
|
||||
Knob: The circular indicator that slides on the container.
|
||||
*/
|
||||
public class DefaultToggleModel: DefaultLabelModel, VDSToggleModel {
|
||||
public var id: String?
|
||||
public var inputId: String?
|
||||
public var disabled: Bool = false
|
||||
public var showText: Bool = false
|
||||
public var on: Bool = false
|
||||
public var offText: String = "Off"
|
||||
public var onText: String = "On"
|
||||
public var value: AnyHashable? = true
|
||||
public var dataAnalyticsTrack: String?
|
||||
public var dataClickStream: String?
|
||||
public var dataTrack: String?
|
||||
public var accessibilityHintEnabled: String?
|
||||
public var accessibilityHintDisabled: String?
|
||||
public var accessibilityValueEnabled: String?
|
||||
public var accessibilityValueDisabled: String?
|
||||
public var accessibilityLabelEnabled: String?
|
||||
public var accessibilityLabelDisabled: String?
|
||||
|
||||
public required init() {
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
|
||||
@objcMembers open class VDSToggle: VDSControl, Modelable, Changable {
|
||||
|
||||
public typealias ModelType = VDSToggleModel
|
||||
@ -126,6 +102,9 @@ public class DefaultToggleModel: DefaultLabelModel, VDSToggleModel {
|
||||
|
||||
@Proxy(\.model.surface)
|
||||
public var surface: Surface
|
||||
|
||||
@Proxy(\VDSToggle.model.on)
|
||||
open var isOn: Bool
|
||||
|
||||
open override var isEnabled: Bool {
|
||||
get { !model.disabled }
|
||||
@ -137,16 +116,7 @@ public class DefaultToggleModel: DefaultLabelModel, VDSToggleModel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Simple means to prevent user interaction with the toggle.
|
||||
public var isLocked: Bool = false {
|
||||
didSet { isUserInteractionEnabled = !isLocked }
|
||||
}
|
||||
|
||||
/// The state on the toggle. Default value: false.
|
||||
@Proxy(\VDSToggle.model.on)
|
||||
open var isOn: Bool
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Constraints
|
||||
//--------------------------------------------------
|
||||
@ -348,7 +318,8 @@ public class DefaultToggleModel: DefaultLabelModel, VDSToggleModel {
|
||||
/// Follow the SwiftUI View paradigm
|
||||
/// - Parameter viewModel: state
|
||||
private func onStateChange(viewModel: ModelType) {
|
||||
|
||||
let enabled = !viewModel.disabled
|
||||
|
||||
label.set(with: viewModel)
|
||||
label.text = viewModel.on ? viewModel.onText : viewModel.offText
|
||||
|
||||
@ -373,8 +344,8 @@ public class DefaultToggleModel: DefaultLabelModel, VDSToggleModel {
|
||||
}
|
||||
|
||||
if viewModel.disabled {
|
||||
toggleView.backgroundColor = isEnabled ? isOn ? containerTintColor.on : containerTintColor.off : disabledTintColor.container
|
||||
knobView.backgroundColor = isEnabled ? isOn ? knobTintColor.on : knobTintColor.off : disabledTintColor.knob
|
||||
toggleView.backgroundColor = enabled ? viewModel.on ? containerTintColor.on : containerTintColor.off : disabledTintColor.container
|
||||
knobView.backgroundColor = enabled ? viewModel.on ? knobTintColor.on : knobTintColor.off : disabledTintColor.knob
|
||||
constrainKnob()
|
||||
} else {
|
||||
UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseIn, animations: {
|
||||
@ -395,6 +366,11 @@ public class DefaultToggleModel: DefaultLabelModel, VDSToggleModel {
|
||||
|
||||
backgroundColor = viewModel.surface == .dark ? VDSColor.backgroundPrimaryDark : .clear
|
||||
isUserInteractionEnabled = !viewModel.disabled
|
||||
|
||||
accessibilityHint = enabled ? viewModel.accessibilityHintEnabled :viewModel.accessibilityHintDisabled
|
||||
accessibilityValue = viewModel.on ? viewModel.accessibilityValueEnabled : viewModel.accessibilityValueDisabled
|
||||
accessibilityLabel = viewModel.on ? viewModel.accessibilityLabelEnabled : viewModel.accessibilityLabelDisabled
|
||||
|
||||
setNeedsLayout()
|
||||
layoutIfNeeded()
|
||||
}
|
||||
|
||||
@ -28,3 +28,27 @@ extension VDSToggleModel {
|
||||
set { return }
|
||||
}
|
||||
}
|
||||
|
||||
public class DefaultToggleModel: DefaultLabelModel, VDSToggleModel {
|
||||
public var id: String?
|
||||
public var inputId: String?
|
||||
public var disabled: Bool = false
|
||||
public var showText: Bool = false
|
||||
public var on: Bool = false
|
||||
public var offText: String = "Off"
|
||||
public var onText: String = "On"
|
||||
public var value: AnyHashable? = true
|
||||
public var dataAnalyticsTrack: String?
|
||||
public var dataClickStream: String?
|
||||
public var dataTrack: String?
|
||||
public var accessibilityHintEnabled: String?
|
||||
public var accessibilityHintDisabled: String?
|
||||
public var accessibilityValueEnabled: String?
|
||||
public var accessibilityValueDisabled: String?
|
||||
public var accessibilityLabelEnabled: String?
|
||||
public var accessibilityLabelDisabled: String?
|
||||
|
||||
public required init() {
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user