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 viewModel: ToggleModel!
|
||||||
open var delegateObject: MVMCoreUIDelegateObject?
|
open var delegateObject: MVMCoreUIDelegateObject?
|
||||||
open var additionalData: [AnyHashable : Any]?
|
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? {
|
public var didToggleAction: ActionBlock? {
|
||||||
get { nil }
|
get { nil }
|
||||||
@ -58,14 +61,13 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
/// The state on the toggle. Default value: false.
|
/// The state on the toggle. Default value: false.
|
||||||
open override var isOn: Bool {
|
open override var isOn: Bool {
|
||||||
didSet {
|
didSet {
|
||||||
toggleModel?.selected = isOn
|
if !updateSelectionOnly {
|
||||||
_ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
|
viewModel.selected = isOn
|
||||||
|
_ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public var toggleModel: ToggleModel? {
|
|
||||||
viewModel
|
|
||||||
}
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -141,7 +143,6 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
open override func toggle() {
|
open override func toggle() {
|
||||||
if let result = shouldToggleAction?(), result {
|
if let result = shouldToggleAction?(), result {
|
||||||
super.toggle()
|
super.toggle()
|
||||||
didToggleAction?()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +150,13 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
public func viewModelDidUpdate() {
|
public func viewModelDidUpdate() {
|
||||||
FormValidator.setupValidation(for: viewModel, delegate: delegateObject?.formHolderDelegate)
|
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
|
isAnimated = viewModel.animated
|
||||||
isEnabled = viewModel.enabled && !viewModel.readOnly
|
isEnabled = viewModel.enabled && !viewModel.readOnly
|
||||||
showText = viewModel.showText
|
showText = viewModel.showText
|
||||||
|
|||||||
@ -25,6 +25,8 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol {
|
|||||||
public var alternateAction: ActionModelProtocol?
|
public var alternateAction: ActionModelProtocol?
|
||||||
public var accessibilityText: String?
|
public var accessibilityText: String?
|
||||||
|
|
||||||
|
public var surface: Surface { inverted ? .dark : .light }
|
||||||
|
public var inverted: Bool = false
|
||||||
public var showText: Bool = false
|
public var showText: Bool = false
|
||||||
public var onText: String = "On"
|
public var onText: String = "On"
|
||||||
public var offText: String = "Off"
|
public var offText: String = "Off"
|
||||||
@ -53,6 +55,7 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol {
|
|||||||
case alternateAction
|
case alternateAction
|
||||||
case accessibilityText
|
case accessibilityText
|
||||||
|
|
||||||
|
case inverted
|
||||||
case showText
|
case showText
|
||||||
case onText
|
case onText
|
||||||
case offText
|
case offText
|
||||||
@ -121,6 +124,7 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol {
|
|||||||
enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) ?? true
|
enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) ?? true
|
||||||
readOnly = try typeContainer.decodeIfPresent(Bool.self, forKey: .readOnly) ?? false
|
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
|
showText = try typeContainer.decodeIfPresent(Bool.self, forKey: .showText) ?? false
|
||||||
onText = try typeContainer.decodeIfPresent(String.self, forKey: .onText) ?? "On"
|
onText = try typeContainer.decodeIfPresent(String.self, forKey: .onText) ?? "On"
|
||||||
offText = try typeContainer.decodeIfPresent(String.self, forKey: .offText) ?? "Off"
|
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.encodeIfPresent(groupName, forKey: .groupName)
|
||||||
try container.encode(readOnly, forKey: .readOnly)
|
try container.encode(readOnly, forKey: .readOnly)
|
||||||
|
|
||||||
|
try container.encode(inverted, forKey: .inverted)
|
||||||
try container.encode(showText, forKey: .showText)
|
try container.encode(showText, forKey: .showText)
|
||||||
try container.encode(onText, forKey: .onText)
|
try container.encode(onText, forKey: .onText)
|
||||||
try container.encode(offText, forKey: .offText)
|
try container.encode(offText, forKey: .offText)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user