From 5e116e3c9153c83a96acdebfd518a03db51b6706 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 1 Aug 2024 17:14:04 -0500 Subject: [PATCH] reverted code in case the isSelected is set directly Signed-off-by: Matt Bruce --- .../Atomic/Atoms/Selectors/Checkbox.swift | 36 ++++++++++++------- .../Atomic/Atoms/Views/CheckboxLabel.swift | 33 ++++++++++------- 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift index 60d88693..82aad9ee 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift @@ -38,6 +38,23 @@ import VDS } } + /// Disables all selection logic when setting the value of isSelected, reducing it to a stored property. + open var updateSelectionOnly: Bool = false + + /** + The represented state of the Checkbox. + + Setting updateSelectionOnly to true bypasses the animation logic inherent with setting this property. + */ + override open var isSelected: Bool { + didSet { + if !updateSelectionOnly { + viewModel.selected = isSelected + _ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate) + } + } + } + //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- @@ -66,16 +83,6 @@ import VDS isSelected = isChecked } - open override func setup() { - super.setup() - publisher(for: .valueChanged) - .sink { [weak self] control in - guard let self, isEnabled else { return } - viewModel?.selected = isSelected - _ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate) - }.store(in: &subscribers) - } - //-------------------------------------------------- // MARK: - Actions //-------------------------------------------------- @@ -136,8 +143,13 @@ import VDS //properties isEnabled = viewModel.enabled && !viewModel.readOnly isAnimated = viewModel.animated - isSelected = viewModel.selected - + + if viewModel.selected { + updateSelectionOnly = true + isSelected = viewModel.selected + updateSelectionOnly = false + } + //events viewModel.updateUI = { MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in diff --git a/MVMCoreUI/Atomic/Atoms/Views/CheckboxLabel.swift b/MVMCoreUI/Atomic/Atoms/Views/CheckboxLabel.swift index c75ead98..19966009 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CheckboxLabel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CheckboxLabel.swift @@ -20,21 +20,23 @@ import VDS var fieldValue: JSONValue? var groupName: String? - //-------------------------------------------------- - // MARK: - Life Cycle - //-------------------------------------------------- + /// Disables all selection logic when setting the value of isSelected, reducing it to a stored property. + open var updateSelectionOnly: Bool = false - open override func setup() { - super.setup() - - publisher(for: .valueChanged) - .sink { [weak self] control in - guard let self, isEnabled else { return } - viewModel?.checkbox.selected = isSelected + /** + The represented state of the Checkbox. + + Setting updateSelectionOnly to true bypasses the animation logic inherent with setting this property. + */ + override open var isSelected: Bool { + didSet { + if !updateSelectionOnly { + viewModel.checkbox.selected = isSelected _ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate) - }.store(in: &subscribers) + } + } } - + //-------------------------------------------------- // MARK: - Atomic //-------------------------------------------------- @@ -73,8 +75,13 @@ import VDS //properties isAnimated = viewModel.checkbox.animated isEnabled = viewModel.checkbox.enabled && !viewModel.checkbox.readOnly - isSelected = viewModel.checkbox.selected + if viewModel.checkbox.selected { + updateSelectionOnly = false + isSelected = viewModel.checkbox.selected + updateSelectionOnly = true + } + //events viewModel.checkbox.updateUI = { MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in