From fa52fa8c12948798ece5c995e42881842b25e501 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 3 Jul 2024 15:58:01 -0500 Subject: [PATCH] added protocol/refactored to deal with RadiobuttonLabel Signed-off-by: Matt Bruce --- .../Selectors/RadioButtonSelectionHelper.swift | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButtonSelectionHelper.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButtonSelectionHelper.swift index 2b6fa01d..4ca37dce 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButtonSelectionHelper.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButtonSelectionHelper.swift @@ -6,6 +6,10 @@ // Copyright © 2019 Verizon Wireless. All rights reserved. // +public protocol RadioButtonSelectionHelperProtocol: AnyObject { + var isSelected: Bool { get set } + var radioButtonModel: RadioButtonModel { get } +} @objcMembers public class RadioButtonSelectionHelper: FormFieldProtocol { //-------------------------------------------------- @@ -14,7 +18,7 @@ public var fieldKey: String? public var groupName: String = FormValidator.defaultGroupName - private var selectedRadioButton: RadioButton? + private var selectedRadioButton: RadioButtonSelectionHelperProtocol? private var selectedRadioButtonModel: RadioButtonModel? public var baseValue: AnyHashable? public var enabled: Bool = true @@ -24,7 +28,7 @@ // MARK: - Initializer //-------------------------------------------------- - public func set(_ radioButtonModel: RadioButtonModel, _ radioButton: RadioButton) { + public func set(_ radioButtonModel: RadioButtonModel, _ radioButton: RadioButtonSelectionHelperProtocol) { self.fieldKey = radioButtonModel.fieldKey self.groupName = radioButtonModel.groupName @@ -49,7 +53,7 @@ // MARK: - Functions //-------------------------------------------------- - public static func setupForRadioButtonGroup(_ radioButtonModel: RadioButtonModel, _ radioButton: RadioButton, delegateObject: MVMCoreUIDelegateObject?) { + public static func setupForRadioButtonGroup(_ radioButtonModel: RadioButtonModel, _ radioButton: RadioButtonSelectionHelperProtocol, delegateObject: MVMCoreUIDelegateObject?) { guard let groupName = radioButtonModel.fieldKey, let formValidator = delegateObject?.formHolderDelegate?.formValidator @@ -61,10 +65,10 @@ FormValidator.setupValidation(for: radioButtonSelectionHelper, delegate: delegateObject?.formHolderDelegate) } - public func selected(_ radioButton: RadioButton) { + public func selected(_ radioButton: RadioButtonSelectionHelperProtocol) { // Checks because the view could be reused - if selectedRadioButton?.radioModel === selectedRadioButtonModel { + if selectedRadioButton?.radioButtonModel === selectedRadioButtonModel { selectedRadioButton?.isSelected = false } else { selectedRadioButtonModel?.state = false @@ -72,7 +76,7 @@ selectedRadioButton = radioButton selectedRadioButton?.isSelected = true - selectedRadioButtonModel = selectedRadioButton?.radioModel + selectedRadioButtonModel = selectedRadioButton?.radioButtonModel } }