refactored setting of isON on viewModelDidUpdate
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
eab6fb5f3b
commit
fe66380d72
@ -28,15 +28,11 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
||||
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 }
|
||||
set {
|
||||
if let action = newValue {
|
||||
didSet {
|
||||
if let didToggleAction {
|
||||
onChange = { _ in
|
||||
action()
|
||||
didToggleAction()
|
||||
}
|
||||
} else {
|
||||
onChange = nil
|
||||
@ -58,16 +54,6 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
||||
didSet { isUserInteractionEnabled = !isLocked }
|
||||
}
|
||||
|
||||
/// The state on the toggle. Default value: false.
|
||||
open override var isOn: Bool {
|
||||
didSet {
|
||||
if !updateSelectionOnly {
|
||||
viewModel.selected = isOn
|
||||
_ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
//--------------------------------------------------
|
||||
@ -119,18 +105,17 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
||||
public func viewModelDidUpdate() {
|
||||
FormValidator.setupValidation(for: viewModel, delegate: delegateObject?.formHolderDelegate)
|
||||
|
||||
if viewModel.selected {
|
||||
updateSelectionOnly = false
|
||||
isOn = viewModel.selected
|
||||
updateSelectionOnly = true
|
||||
}
|
||||
|
||||
isOn = viewModel.selected
|
||||
surface = viewModel.surface
|
||||
isAnimated = viewModel.animated
|
||||
isEnabled = viewModel.enabled && !viewModel.readOnly
|
||||
showText = viewModel.showText
|
||||
onText = viewModel.onText
|
||||
offText = viewModel.offText
|
||||
if let onText = viewModel.onText {
|
||||
self.onText = onText
|
||||
}
|
||||
if let offText = viewModel.offText {
|
||||
self.offText = offText
|
||||
}
|
||||
textSize = viewModel.textSize
|
||||
textWeight = viewModel.textWeight
|
||||
textPosition = viewModel.textPosition
|
||||
@ -166,6 +151,8 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
||||
open override func toggle() {
|
||||
if let result = shouldToggleAction?(), result {
|
||||
super.toggle()
|
||||
viewModel?.selected = isOn
|
||||
_ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user