diff --git a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m index cf608538..9bd8eaee 100644 --- a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m +++ b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m @@ -60,11 +60,9 @@ static const CGFloat CheckBoxHeightWidth = 18.0; - (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { - if ([delegateObject isKindOfClass:[MVMCoreUIDelegateObject class]]) { - [FormValidator setupValidationWithMolecule:self delegate:((MVMCoreUIDelegateObject *)delegateObject).formValidationProtocol]; - } + [FormValidator setupValidationWithMolecule:self delegate:delegateObject.formValidationProtocol]; - self.delegateObject = (MVMCoreUIDelegateObject *) delegateObject; + self.delegateObject = delegateObject; self.fieldKey = [json stringForKey:KeyFieldKey]; self.isRequired = [json boolForKey:KeyRequired]; @@ -345,7 +343,7 @@ static const CGFloat CheckBoxHeightWidth = 18.0; [self.checkMark updateCheckSelected:NO animated:animated]; } - [FormValidator enableByValidationWithDelegate:((MVMCoreUIDelegateObject *)self.delegateObject).formValidationProtocol]; + [FormValidator enableByValidationWithDelegate:self.delegateObject.formValidationProtocol]; } - (void)setColor:(nullable UIColor *)color forState:(UIControlState)state { diff --git a/MVMCoreUI/Molecules/RadioButton.swift b/MVMCoreUI/Molecules/RadioButton.swift index c814de13..ae2f7d52 100644 --- a/MVMCoreUI/Molecules/RadioButton.swift +++ b/MVMCoreUI/Molecules/RadioButton.swift @@ -12,7 +12,7 @@ import UIKit @objcMembers open class RadioButton: ViewConstrainingView { let radioButton = MFRadioButton() - var delegateObject:MVMCoreUIDelegateObject? + var delegateObject: MVMCoreUIDelegateObject? var dummyButton: MFCustomButton? let label = Label() @@ -52,13 +52,14 @@ import UIKit if let rightView = createRightView() { addSubview(rightView) - rightView.leftAnchor.constraint(equalTo: radioButton.rightAnchor, constant: PaddingTwo).isActive = true + rightView.leftAnchor.constraint(equalTo: radioButton.rightAnchor, constant: PaddingHorizontalBetweenRelatedItems).isActive = true rightView.rightAnchor.constraint(equalTo: rightAnchor, constant: 0).isActive = true rightView.topAnchor.constraint(greaterThanOrEqualTo: topAnchor, constant: PaddingOne).isActive = true rightView.bottomAnchor.constraint(greaterThanOrEqualTo: bottomAnchor, constant: PaddingOne).isActive = true rightView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true } addActionHandler() + addActionHandler() } func createRightView() -> ViewConstrainingView? { @@ -68,7 +69,7 @@ import UIKit func addActionHandler() { - if dummyButton != nil { + guard dummyButton == nil else { return } @@ -97,7 +98,8 @@ import UIKit // MARK: - MVMCoreUIMoleculeViewProtocol extension RadioButton { - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + @objc open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) // Configure class properties with JSON values @@ -106,9 +108,8 @@ extension RadioButton { } groupName = jsonDictionary.optionalStringForKey("groupName") fieldKey = jsonDictionary.optionalStringForKey("fieldKey") - isRequired = jsonDictionary.boolForKey("required") - - self.delegateObject = delegateObject as? MVMCoreUIDelegateObject + isRequired = jsonDictionary.boolForKey("required") + self.delegateObject = delegateObject radioButtonModel = RadioButtonModel.setupForRadioButtonGroup(radioButton: self, formValidator: self.delegateObject?.formValidationProtocol?.formValidatorModel?()) @@ -130,7 +131,7 @@ extension RadioButton { open override func needsToBeConstrained() -> Bool { return true } - + open override func moleculeAlignment() -> UIStackView.Alignment { return UIStackView.Alignment.leading; } @@ -141,7 +142,7 @@ extension RadioButton { extension RadioButton: FormValidationProtocol { // Used to check the validity of the field, to enable/disable the primary button. @objc public func isValidField() -> Bool { - if isRequired == false { + guard isRequired else { return true } return radioButtonModel?.isValidField() ?? false @@ -149,17 +150,11 @@ extension RadioButton: FormValidationProtocol { // The Field name key value pair for sending to server @objc public func formFieldName() -> String? { - if let radioButtonModel = radioButtonModel { - return radioButtonModel.formFieldName() - } - return json?.optionalStringForKey("fieldKey") + return radioButtonModel?.formFieldName() ?? json?.optionalStringForKey("fieldKey") } // The Feild value key value paid for sending to server @objc public func formFieldValue() -> Any? { - if let radioButtonModel = radioButtonModel { - return radioButtonModel.formFieldValue() - } - return radioButton.isSelected + return radioButtonModel?.formFieldValue() ?? radioButton.isSelected } } diff --git a/MVMCoreUI/Molecules/RadioButtonModel.swift b/MVMCoreUI/Molecules/RadioButtonModel.swift index fbbb1a60..096cb80a 100644 --- a/MVMCoreUI/Molecules/RadioButtonModel.swift +++ b/MVMCoreUI/Molecules/RadioButtonModel.swift @@ -12,10 +12,8 @@ import UIKit @objcMembers public class RadioButtonModel: NSObject { private var selectedRadioButton: RadioButton? - private var radioButtons: [RadioButton] = [] public static func setupForRadioButtonGroup(radioButton: RadioButton, formValidator: FormValidator?) -> RadioButtonModel? { - guard let groupName = radioButton.groupName, let formValidator = formValidator else { return nil @@ -23,8 +21,6 @@ import UIKit let radioButtonModel = formValidator.radioButtonsModelByGroup[groupName] ?? RadioButtonModel() formValidator.radioButtonsModelByGroup[groupName] = radioButtonModel - radioButtonModel.radioButtons.append(radioButton) - return radioButtonModel } @@ -39,17 +35,12 @@ import UIKit extension RadioButtonModel: FormValidationProtocol { // Used to check the validity of the field, to enable/disable the primary button. @objc public func isValidField() -> Bool { - if selectedRadioButton != nil { - return true - } - return false + return selectedRadioButton != nil ? true : false } - - // The Field name key value pair for sending to server + // Name of the field to send to server @objc public func formFieldName() -> String? { return selectedRadioButton?.fieldKey } - // The Feild value key value paid for sending to server @objc public func formFieldValue() -> Any? { return selectedRadioButton != nil ? true : false diff --git a/MVMCoreUI/Styles/MFStyler.h b/MVMCoreUI/Styles/MFStyler.h index 0a52c468..83fd0271 100644 --- a/MVMCoreUI/Styles/MFStyler.h +++ b/MVMCoreUI/Styles/MFStyler.h @@ -36,6 +36,9 @@ extern CGFloat const PaddingVerticalWhiteGrayView; extern CGFloat const PaddingVerticalHeadlineAlternate; extern CGFloat const PaddingPrimaryButtonTop; +// +extern CGFloat const PaddingHorizontalBetweenRelatedItems; + // These are based on the multiple of 6 rule extern CGFloat const PaddingOne; extern CGFloat const PaddingTwo; diff --git a/MVMCoreUI/Styles/MFStyler.m b/MVMCoreUI/Styles/MFStyler.m index 261181b1..d0d436a2 100644 --- a/MVMCoreUI/Styles/MFStyler.m +++ b/MVMCoreUI/Styles/MFStyler.m @@ -25,6 +25,7 @@ CGFloat const PaddingVerticalWhiteGrayView = 72; CGFloat const PaddingVerticalHeadlineAlternate = 48; CGFloat const PaddingPrimaryButtonTop = 36; +CGFloat const PaddingHorizontalBetweenRelatedItems = 16; CGFloat const PaddingOne = 6; CGFloat const PaddingTwo = 12; CGFloat const PaddingThree = 18;