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 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 }
|
didSet {
|
||||||
set {
|
if let didToggleAction {
|
||||||
if let action = newValue {
|
|
||||||
onChange = { _ in
|
onChange = { _ in
|
||||||
action()
|
didToggleAction()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
onChange = nil
|
onChange = nil
|
||||||
@ -58,16 +54,6 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
didSet { isUserInteractionEnabled = !isLocked }
|
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
|
// MARK: - Initializers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -119,18 +105,17 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
public func viewModelDidUpdate() {
|
public func viewModelDidUpdate() {
|
||||||
FormValidator.setupValidation(for: viewModel, delegate: delegateObject?.formHolderDelegate)
|
FormValidator.setupValidation(for: viewModel, delegate: delegateObject?.formHolderDelegate)
|
||||||
|
|
||||||
if viewModel.selected {
|
isOn = viewModel.selected
|
||||||
updateSelectionOnly = false
|
|
||||||
isOn = viewModel.selected
|
|
||||||
updateSelectionOnly = true
|
|
||||||
}
|
|
||||||
|
|
||||||
surface = viewModel.surface
|
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
|
||||||
onText = viewModel.onText
|
if let onText = viewModel.onText {
|
||||||
offText = viewModel.offText
|
self.onText = onText
|
||||||
|
}
|
||||||
|
if let offText = viewModel.offText {
|
||||||
|
self.offText = offText
|
||||||
|
}
|
||||||
textSize = viewModel.textSize
|
textSize = viewModel.textSize
|
||||||
textWeight = viewModel.textWeight
|
textWeight = viewModel.textWeight
|
||||||
textPosition = viewModel.textPosition
|
textPosition = viewModel.textPosition
|
||||||
@ -166,6 +151,8 @@ 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()
|
||||||
|
viewModel?.selected = isOn
|
||||||
|
_ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user