code review

This commit is contained in:
Suresh, Kamlesh 2019-05-31 17:29:32 -04:00
parent 714b153b6a
commit 6828f833e7
5 changed files with 21 additions and 33 deletions

View File

@ -60,11 +60,9 @@ static const CGFloat CheckBoxHeightWidth = 18.0;
- (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { - (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData {
if ([delegateObject isKindOfClass:[MVMCoreUIDelegateObject class]]) { [FormValidator setupValidationWithMolecule:self delegate:delegateObject.formValidationProtocol];
[FormValidator setupValidationWithMolecule:self delegate:((MVMCoreUIDelegateObject *)delegateObject).formValidationProtocol];
}
self.delegateObject = (MVMCoreUIDelegateObject *) delegateObject; self.delegateObject = delegateObject;
self.fieldKey = [json stringForKey:KeyFieldKey]; self.fieldKey = [json stringForKey:KeyFieldKey];
self.isRequired = [json boolForKey:KeyRequired]; self.isRequired = [json boolForKey:KeyRequired];
@ -345,7 +343,7 @@ static const CGFloat CheckBoxHeightWidth = 18.0;
[self.checkMark updateCheckSelected:NO animated:animated]; [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 { - (void)setColor:(nullable UIColor *)color forState:(UIControlState)state {

View File

@ -12,7 +12,7 @@ import UIKit
@objcMembers open class RadioButton: ViewConstrainingView { @objcMembers open class RadioButton: ViewConstrainingView {
let radioButton = MFRadioButton() let radioButton = MFRadioButton()
var delegateObject:MVMCoreUIDelegateObject? var delegateObject: MVMCoreUIDelegateObject?
var dummyButton: MFCustomButton? var dummyButton: MFCustomButton?
let label = Label() let label = Label()
@ -52,13 +52,14 @@ import UIKit
if let rightView = createRightView() { if let rightView = createRightView() {
addSubview(rightView) 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.rightAnchor.constraint(equalTo: rightAnchor, constant: 0).isActive = true
rightView.topAnchor.constraint(greaterThanOrEqualTo: topAnchor, constant: PaddingOne).isActive = true rightView.topAnchor.constraint(greaterThanOrEqualTo: topAnchor, constant: PaddingOne).isActive = true
rightView.bottomAnchor.constraint(greaterThanOrEqualTo: bottomAnchor, constant: PaddingOne).isActive = true rightView.bottomAnchor.constraint(greaterThanOrEqualTo: bottomAnchor, constant: PaddingOne).isActive = true
rightView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true rightView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
} }
addActionHandler() addActionHandler()
addActionHandler()
} }
func createRightView() -> ViewConstrainingView? { func createRightView() -> ViewConstrainingView? {
@ -68,7 +69,7 @@ import UIKit
func addActionHandler() { func addActionHandler() {
if dummyButton != nil { guard dummyButton == nil else {
return return
} }
@ -97,7 +98,8 @@ import UIKit
// MARK: - MVMCoreUIMoleculeViewProtocol // MARK: - MVMCoreUIMoleculeViewProtocol
extension RadioButton { 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) super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
// Configure class properties with JSON values // Configure class properties with JSON values
@ -106,9 +108,8 @@ extension RadioButton {
} }
groupName = jsonDictionary.optionalStringForKey("groupName") groupName = jsonDictionary.optionalStringForKey("groupName")
fieldKey = jsonDictionary.optionalStringForKey("fieldKey") fieldKey = jsonDictionary.optionalStringForKey("fieldKey")
isRequired = jsonDictionary.boolForKey("required") isRequired = jsonDictionary.boolForKey("required")
self.delegateObject = delegateObject
self.delegateObject = delegateObject as? MVMCoreUIDelegateObject
radioButtonModel = RadioButtonModel.setupForRadioButtonGroup(radioButton: self, radioButtonModel = RadioButtonModel.setupForRadioButtonGroup(radioButton: self,
formValidator: self.delegateObject?.formValidationProtocol?.formValidatorModel?()) formValidator: self.delegateObject?.formValidationProtocol?.formValidatorModel?())
@ -130,7 +131,7 @@ extension RadioButton {
open override func needsToBeConstrained() -> Bool { open override func needsToBeConstrained() -> Bool {
return true return true
} }
open override func moleculeAlignment() -> UIStackView.Alignment { open override func moleculeAlignment() -> UIStackView.Alignment {
return UIStackView.Alignment.leading; return UIStackView.Alignment.leading;
} }
@ -141,7 +142,7 @@ extension RadioButton {
extension RadioButton: FormValidationProtocol { extension RadioButton: FormValidationProtocol {
// Used to check the validity of the field, to enable/disable the primary button. // Used to check the validity of the field, to enable/disable the primary button.
@objc public func isValidField() -> Bool { @objc public func isValidField() -> Bool {
if isRequired == false { guard isRequired else {
return true return true
} }
return radioButtonModel?.isValidField() ?? false return radioButtonModel?.isValidField() ?? false
@ -149,17 +150,11 @@ extension RadioButton: FormValidationProtocol {
// The Field name key value pair for sending to server // The Field name key value pair for sending to server
@objc public func formFieldName() -> String? { @objc public func formFieldName() -> String? {
if let radioButtonModel = radioButtonModel { return radioButtonModel?.formFieldName() ?? json?.optionalStringForKey("fieldKey")
return radioButtonModel.formFieldName()
}
return json?.optionalStringForKey("fieldKey")
} }
// The Feild value key value paid for sending to server // The Feild value key value paid for sending to server
@objc public func formFieldValue() -> Any? { @objc public func formFieldValue() -> Any? {
if let radioButtonModel = radioButtonModel { return radioButtonModel?.formFieldValue() ?? radioButton.isSelected
return radioButtonModel.formFieldValue()
}
return radioButton.isSelected
} }
} }

View File

@ -12,10 +12,8 @@ import UIKit
@objcMembers public class RadioButtonModel: NSObject { @objcMembers public class RadioButtonModel: NSObject {
private var selectedRadioButton: RadioButton? private var selectedRadioButton: RadioButton?
private var radioButtons: [RadioButton] = []
public static func setupForRadioButtonGroup(radioButton: RadioButton, formValidator: FormValidator?) -> RadioButtonModel? { public static func setupForRadioButtonGroup(radioButton: RadioButton, formValidator: FormValidator?) -> RadioButtonModel? {
guard let groupName = radioButton.groupName, guard let groupName = radioButton.groupName,
let formValidator = formValidator else { let formValidator = formValidator else {
return nil return nil
@ -23,8 +21,6 @@ import UIKit
let radioButtonModel = formValidator.radioButtonsModelByGroup[groupName] ?? RadioButtonModel() let radioButtonModel = formValidator.radioButtonsModelByGroup[groupName] ?? RadioButtonModel()
formValidator.radioButtonsModelByGroup[groupName] = radioButtonModel formValidator.radioButtonsModelByGroup[groupName] = radioButtonModel
radioButtonModel.radioButtons.append(radioButton)
return radioButtonModel return radioButtonModel
} }
@ -39,17 +35,12 @@ import UIKit
extension RadioButtonModel: FormValidationProtocol { extension RadioButtonModel: FormValidationProtocol {
// Used to check the validity of the field, to enable/disable the primary button. // Used to check the validity of the field, to enable/disable the primary button.
@objc public func isValidField() -> Bool { @objc public func isValidField() -> Bool {
if selectedRadioButton != nil { return selectedRadioButton != nil ? true : false
return true
}
return false
} }
// Name of the field to send to server
// The Field name key value pair for sending to server
@objc public func formFieldName() -> String? { @objc public func formFieldName() -> String? {
return selectedRadioButton?.fieldKey return selectedRadioButton?.fieldKey
} }
// The Feild value key value paid for sending to server // The Feild value key value paid for sending to server
@objc public func formFieldValue() -> Any? { @objc public func formFieldValue() -> Any? {
return selectedRadioButton != nil ? true : false return selectedRadioButton != nil ? true : false

View File

@ -36,6 +36,9 @@ extern CGFloat const PaddingVerticalWhiteGrayView;
extern CGFloat const PaddingVerticalHeadlineAlternate; extern CGFloat const PaddingVerticalHeadlineAlternate;
extern CGFloat const PaddingPrimaryButtonTop; extern CGFloat const PaddingPrimaryButtonTop;
//
extern CGFloat const PaddingHorizontalBetweenRelatedItems;
// These are based on the multiple of 6 rule // These are based on the multiple of 6 rule
extern CGFloat const PaddingOne; extern CGFloat const PaddingOne;
extern CGFloat const PaddingTwo; extern CGFloat const PaddingTwo;

View File

@ -25,6 +25,7 @@ CGFloat const PaddingVerticalWhiteGrayView = 72;
CGFloat const PaddingVerticalHeadlineAlternate = 48; CGFloat const PaddingVerticalHeadlineAlternate = 48;
CGFloat const PaddingPrimaryButtonTop = 36; CGFloat const PaddingPrimaryButtonTop = 36;
CGFloat const PaddingHorizontalBetweenRelatedItems = 16;
CGFloat const PaddingOne = 6; CGFloat const PaddingOne = 6;
CGFloat const PaddingTwo = 12; CGFloat const PaddingTwo = 12;
CGFloat const PaddingThree = 18; CGFloat const PaddingThree = 18;