a few updates
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
66255d9dc5
commit
04e11ee1fb
@ -27,6 +27,9 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
||||
open var viewModel: ToggleModel!
|
||||
open var delegateObject: MVMCoreUIDelegateObject?
|
||||
open var additionalData: [AnyHashable : Any]?
|
||||
|
||||
/// Disables all selection logic when setting the value of isOn, reducing it to a stored property.
|
||||
public var updateSelectionOnly: Bool = false
|
||||
|
||||
public var didToggleAction: ActionBlock? {
|
||||
get { nil }
|
||||
@ -58,14 +61,13 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
||||
/// The state on the toggle. Default value: false.
|
||||
open override var isOn: Bool {
|
||||
didSet {
|
||||
toggleModel?.selected = isOn
|
||||
_ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
|
||||
if !updateSelectionOnly {
|
||||
viewModel.selected = isOn
|
||||
_ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public var toggleModel: ToggleModel? {
|
||||
viewModel
|
||||
}
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
//--------------------------------------------------
|
||||
@ -141,7 +143,6 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
||||
open override func toggle() {
|
||||
if let result = shouldToggleAction?(), result {
|
||||
super.toggle()
|
||||
didToggleAction?()
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,7 +150,13 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
||||
public func viewModelDidUpdate() {
|
||||
FormValidator.setupValidation(for: viewModel, delegate: delegateObject?.formHolderDelegate)
|
||||
|
||||
isOn = viewModel.selected
|
||||
if viewModel.selected {
|
||||
updateSelectionOnly = false
|
||||
isOn = viewModel.selected
|
||||
updateSelectionOnly = true
|
||||
}
|
||||
|
||||
surface = viewModel.surface
|
||||
isAnimated = viewModel.animated
|
||||
isEnabled = viewModel.enabled && !viewModel.readOnly
|
||||
showText = viewModel.showText
|
||||
|
||||
@ -25,6 +25,8 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol {
|
||||
public var alternateAction: ActionModelProtocol?
|
||||
public var accessibilityText: String?
|
||||
|
||||
public var surface: Surface { inverted ? .dark : .light }
|
||||
public var inverted: Bool = false
|
||||
public var showText: Bool = false
|
||||
public var onText: String = "On"
|
||||
public var offText: String = "Off"
|
||||
@ -53,6 +55,7 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol {
|
||||
case alternateAction
|
||||
case accessibilityText
|
||||
|
||||
case inverted
|
||||
case showText
|
||||
case onText
|
||||
case offText
|
||||
@ -121,6 +124,7 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol {
|
||||
enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) ?? true
|
||||
readOnly = try typeContainer.decodeIfPresent(Bool.self, forKey: .readOnly) ?? false
|
||||
|
||||
inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) ?? false
|
||||
showText = try typeContainer.decodeIfPresent(Bool.self, forKey: .showText) ?? false
|
||||
onText = try typeContainer.decodeIfPresent(String.self, forKey: .onText) ?? "On"
|
||||
offText = try typeContainer.decodeIfPresent(String.self, forKey: .offText) ?? "Off"
|
||||
@ -145,6 +149,7 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol {
|
||||
try container.encodeIfPresent(groupName, forKey: .groupName)
|
||||
try container.encode(readOnly, forKey: .readOnly)
|
||||
|
||||
try container.encode(inverted, forKey: .inverted)
|
||||
try container.encode(showText, forKey: .showText)
|
||||
try container.encode(onText, forKey: .onText)
|
||||
try container.encode(offText, forKey: .offText)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user