From 7a1c0dd0fd9f411e063676305abdebf17e81e6ae Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 9 Apr 2020 12:49:20 -0400 Subject: [PATCH 1/3] mild changes --- .../Atomic/Atoms/Buttons/RadioButton.swift | 8 ++++---- .../Buttons/RadioButtonSelectionHelper.swift | 20 +++++++++++++++---- .../Molecules/Items/ListItemModel.swift | 1 + MVMCoreUI/FormUIHelpers/FormValidator.swift | 1 + .../Rules/RuleAnyValueChangedModel.swift | 17 ++++++++++++---- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/RadioButton.swift b/MVMCoreUI/Atomic/Atoms/Buttons/RadioButton.swift index 98532549..fa17d85c 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/RadioButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/RadioButton.swift @@ -19,8 +19,8 @@ import UIKit } } - public var enabledColor: UIColor = .black - public var disabledColor: UIColor = .mfSilver() + public var enabledColor: UIColor = .mvmBlack + public var disabledColor: UIColor = .mvmCoolGray3 public var delegateObject: MVMCoreUIDelegateObject? public var radioModel: RadioButtonModel? { @@ -108,7 +108,7 @@ import UIKit open override func setupView() { super.setupView() - backgroundColor = .white + backgroundColor = .mvmWhite clipsToBounds = true widthConstraint = widthAnchor.constraint(equalToConstant: 30) widthConstraint?.isActive = true @@ -133,6 +133,6 @@ import UIKit public override func reset() { super.reset() - backgroundColor = .white + backgroundColor = .mvmWhite } } diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonSelectionHelper.swift b/MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonSelectionHelper.swift index 3decadb5..76a58db8 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonSelectionHelper.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonSelectionHelper.swift @@ -7,24 +7,35 @@ // import Foundation -import UIKit + @objcMembers public class RadioButtonSelectionHelper: FormFieldProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public var fieldKey: String? public var groupName: String = FormValidator.defaultGroupName private var selectedRadioButton: RadioButton? private var fieldGroupName: String? public var baseValue: AnyHashable? + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + init(_ fieldKey: String?) { self.fieldKey = fieldKey } + //-------------------------------------------------- + // MARK: - FUnctions + //-------------------------------------------------- + public static func setupForRadioButtonGroup(_ radioButtonModel: RadioButtonModel, _ radioButton: RadioButton, delegateObject: MVMCoreUIDelegateObject?) { guard let groupName = radioButtonModel.fieldKey, - let formValidator = delegateObject?.formHolderDelegate?.formValidator else { - return - } + let formValidator = delegateObject?.formHolderDelegate?.formValidator + else { return } let radioButtonSelectionHelper = formValidator.radioButtonsModelByGroup[groupName] ?? RadioButtonSelectionHelper(radioButtonModel.fieldKey) radioButtonSelectionHelper.fieldGroupName = radioButtonModel.fieldKey @@ -45,6 +56,7 @@ import UIKit // MARK: - FormValidationFormFieldProtocol extension RadioButtonSelectionHelper { + public func formFieldGroupName() -> String? { return selectedRadioButton?.formFieldGroupName() ?? self.fieldGroupName } diff --git a/MVMCoreUI/Atomic/Molecules/Items/ListItemModel.swift b/MVMCoreUI/Atomic/Molecules/Items/ListItemModel.swift index 9365125a..9a00a94d 100644 --- a/MVMCoreUI/Atomic/Molecules/Items/ListItemModel.swift +++ b/MVMCoreUI/Atomic/Molecules/Items/ListItemModel.swift @@ -9,6 +9,7 @@ import Foundation + @objcMembers open class ListItemModel: ContainerModel, ListItemModelProtocol { //-------------------------------------------------- // MARK: - Properties diff --git a/MVMCoreUI/FormUIHelpers/FormValidator.swift b/MVMCoreUI/FormUIHelpers/FormValidator.swift index 592132f5..f1d0855e 100644 --- a/MVMCoreUI/FormUIHelpers/FormValidator.swift +++ b/MVMCoreUI/FormUIHelpers/FormValidator.swift @@ -9,6 +9,7 @@ import UIKit import MVMCore + @objcMembers public class FormValidator: NSObject { static var defaultGroupName: String = "default" diff --git a/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleAnyValueChangedModel.swift b/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleAnyValueChangedModel.swift index 042243db..7cf24cd5 100644 --- a/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleAnyValueChangedModel.swift +++ b/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleAnyValueChangedModel.swift @@ -8,25 +8,34 @@ import Foundation -public class RuleAnyValueChangedModel: RulesProtocol { +public class RuleAnyValueChangedModel: RulesProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public static var identifier: String = "anyValueChanged" public var type: String = RuleAnyValueChangedModel.identifier public var fields: [String] + //-------------------------------------------------- + // MARK: - Validation + //-------------------------------------------------- + public func isValid(_ formField: FormFieldProtocol) -> Bool { return formField.baseValue != formField.formFieldValue() } public func isValid(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool { + for formKey in fields { - guard let formField = fieldMolecules[formKey] else { - continue - } + guard let formField = fieldMolecules[formKey] else { continue } + if isValid(formField) { return true } } + return false } } From 020030e669b9bc0caec7576bd830431065934655 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 9 Apr 2020 12:53:37 -0400 Subject: [PATCH 2/3] comments --- MVMCoreUI/FormUIHelpers/FormValidator.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/FormUIHelpers/FormValidator.swift b/MVMCoreUI/FormUIHelpers/FormValidator.swift index f1d0855e..06c8cdf1 100644 --- a/MVMCoreUI/FormUIHelpers/FormValidator.swift +++ b/MVMCoreUI/FormUIHelpers/FormValidator.swift @@ -11,7 +11,10 @@ import MVMCore @objcMembers public class FormValidator: NSObject { - + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + static var defaultGroupName: String = "default" var formRules: [FormGroupRule]? weak var delegate: FormHolderProtocol? @@ -19,10 +22,18 @@ import MVMCore var groupWatchers: [FormGroupWatcherFieldProtocol] = [] var radioButtonsModelByGroup: [String: RadioButtonSelectionHelper] = [:] + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + public init(_ formRules: [FormGroupRule]?) { self.formRules = formRules } + //-------------------------------------------------- + // MARK: - Methods + //-------------------------------------------------- + /// Adds the form field to the validator. public func add(_ field: FormFieldProtocol) { if let fieldKey = field.fieldKey { From 97b1ac48ddfbc5a342f99389a39db37adf2d8ab0 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 9 Apr 2020 15:46:01 -0400 Subject: [PATCH 3/3] latest --- MVMCoreUI/Atomic/Atoms/Buttons/RadioButton.swift | 14 +++++++++++--- .../Atomic/Atoms/Buttons/RadioButtonModel.swift | 2 +- ...stLeftVariableRadioButtonAndPaymentMethod.swift | 12 ++++++++---- MVMCoreUI/BaseClasses/Control.swift | 1 + 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/RadioButton.swift b/MVMCoreUI/Atomic/Atoms/Buttons/RadioButton.swift index fa17d85c..6eb00959 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/RadioButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/RadioButton.swift @@ -40,6 +40,13 @@ import UIKit } }() + public override var isEnabled: Bool { + didSet { + isUserInteractionEnabled = isEnabled + setNeedsDisplay() + } + } + //-------------------------------------------------- // MARK: - Constraints //-------------------------------------------------- @@ -71,7 +78,7 @@ import UIKit } //-------------------------------------------------- - // MARK: - Methods + // MARK: - Validation //-------------------------------------------------- /// The action performed when tapped. @@ -128,11 +135,12 @@ import UIKit self.delegateObject = delegateObject isSelected = model.state + isEnabled = model.enabled RadioButtonSelectionHelper.setupForRadioButtonGroup(model, self, delegateObject: delegateObject) } public override func reset() { - super.reset() - backgroundColor = .mvmWhite + super.reset() + backgroundColor = .mvmWhite } } diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonModel.swift b/MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonModel.swift index 579c0ed9..ee408bb4 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonModel.swift @@ -51,7 +51,7 @@ open class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol { } //-------------------------------------------------- - // MARK: - Method + // MARK: - Validation //-------------------------------------------------- public func formFieldValue() -> AnyHashable? { diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAndPaymentMethod.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAndPaymentMethod.swift index 9517acf0..4597a0b9 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAndPaymentMethod.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAndPaymentMethod.swift @@ -8,12 +8,13 @@ import UIKit + @objcMembers open class ListLeftVariableRadioButtonAndPaymentMethod: TableViewCell { //----------------------------------------------------- // MARK: - Outlets //----------------------------------------------------- - let radioButton = RadioButton(frame: .zero) + let radioButton = RadioButton() let leftImage = MFLoadImageView(pinnedEdges: .all) let eyebrowHeadlineBodyLink = EyebrowHeadlineBodyLink() var stack: Stack @@ -57,7 +58,7 @@ import UIKit // MARK: - Molecule //---------------------------------------------------- - open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) guard let model = model as? ListLeftVariableRadioButtonAndPaymentMethodModel else { return} radioButton.set(with: model.radioButton, delegateObject, additionalData) @@ -69,7 +70,10 @@ import UIKit return 90 } - public override func didSelectCell(at index: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { - radioButton.tapAction() + public override func didSelectCell(at index: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + + if radioButton.isEnabled { + radioButton.tapAction() + } } } diff --git a/MVMCoreUI/BaseClasses/Control.swift b/MVMCoreUI/BaseClasses/Control.swift index ebb88977..d8acb6f6 100644 --- a/MVMCoreUI/BaseClasses/Control.swift +++ b/MVMCoreUI/BaseClasses/Control.swift @@ -8,6 +8,7 @@ import UIKit + @objcMembers open class Control: UIControl, MoleculeViewProtocol { //-------------------------------------------------- // MARK: - Properties