From 9d8953d229304f08ee4437974dedb5f71096ceb8 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 4 Mar 2020 10:52:40 -0500 Subject: [PATCH] clean up --- MVMCoreUI.xcodeproj/project.pbxproj | 8 -- MVMCoreUI/Atoms/TextFields/EntryField.swift | 27 ----- MVMCoreUI/Atoms/Views/Toggle.swift | 110 +++++++----------- MVMCoreUI/BaseControllers/MFViewController.m | 2 +- .../FormValidationProtocol.swift | 41 ------- .../FormValidator+FormParams.swift | 10 -- MVMCoreUI/Legacy/Views/MFTextField.m | 27 +---- MVMCoreUI/Legacy/Views/MVMCoreUICheckBox.m | 19 +-- MVMCoreUI/Legacy/Views/MVMCoreUISwitch.m | 20 +--- MVMCoreUI/Legacy/Views/PrimaryButton.m | 20 +--- 10 files changed, 50 insertions(+), 234 deletions(-) delete mode 100644 MVMCoreUI/FormUIHelpers/FormValidationProtocol.swift delete mode 100644 MVMCoreUI/FormUIHelpers/FormValidator+FormParams.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index d15c400c..3dd1fad9 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -11,7 +11,6 @@ 0103B84E23D7E33A009C315C /* HeadlineBodyToggleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0103B84D23D7E33A009C315C /* HeadlineBodyToggleModel.swift */; }; 0105618D224BBE7700E1557D /* FormValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618A224BBE7700E1557D /* FormValidator.swift */; }; 0105618E224BBE7700E1557D /* FormValidator+TextFields.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */; }; - 0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */; }; 0116A4E5228B19640094F3ED /* RadioButtonSelectionHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0116A4E4228B19640094F3ED /* RadioButtonSelectionHelper.swift */; }; 011B58F023A2AA980085F53C /* ListItemModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011B58EF23A2AA980085F53C /* ListItemModelProtocol.swift */; }; 011B58F223A2AE2C0085F53C /* DropDownListItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011B58F123A2AE2C0085F53C /* DropDownListItemModel.swift */; }; @@ -64,7 +63,6 @@ 017BEB4A236235BA0024EF95 /* ModelMoleculeViewProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB49236235BA0024EF95 /* ModelMoleculeViewProtocol.swift */; }; 017BEB7B236763000024EF95 /* LineModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB7A236763000024EF95 /* LineModel.swift */; }; 017BEB7F23676E870024EF95 /* MoleculeObjectMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB7E23676E870024EF95 /* MoleculeObjectMapping.swift */; }; - 0198F79F225679880066C936 /* FormValidationProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0198F79E225679870066C936 /* FormValidationProtocol.swift */; }; 0198F7A62256A80B0066C936 /* MFRadioButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 0198F7A02256A80A0066C936 /* MFRadioButton.h */; settings = {ATTRIBUTES = (Public, ); }; }; 0198F7A82256A80B0066C936 /* MFRadioButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 0198F7A22256A80A0066C936 /* MFRadioButton.m */; }; 01C851D323CF9E740021F976 /* LabelToggleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C851D223CF9E740021F976 /* LabelToggleModel.swift */; }; @@ -381,7 +379,6 @@ 0103B84D23D7E33A009C315C /* HeadlineBodyToggleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadlineBodyToggleModel.swift; sourceTree = ""; }; 0105618A224BBE7700E1557D /* FormValidator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidator.swift; sourceTree = ""; }; 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+TextFields.swift"; sourceTree = ""; }; - 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+FormParams.swift"; sourceTree = ""; }; 0116A4E4228B19640094F3ED /* RadioButtonSelectionHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioButtonSelectionHelper.swift; sourceTree = ""; }; 011B58EF23A2AA980085F53C /* ListItemModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListItemModelProtocol.swift; sourceTree = ""; }; 011B58F123A2AE2C0085F53C /* DropDownListItemModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropDownListItemModel.swift; sourceTree = ""; }; @@ -434,7 +431,6 @@ 017BEB49236235BA0024EF95 /* ModelMoleculeViewProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelMoleculeViewProtocol.swift; sourceTree = ""; }; 017BEB7A236763000024EF95 /* LineModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineModel.swift; sourceTree = ""; }; 017BEB7E23676E870024EF95 /* MoleculeObjectMapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeObjectMapping.swift; sourceTree = ""; }; - 0198F79E225679870066C936 /* FormValidationProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidationProtocol.swift; sourceTree = ""; }; 0198F7A02256A80A0066C936 /* MFRadioButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFRadioButton.h; sourceTree = ""; }; 0198F7A22256A80A0066C936 /* MFRadioButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFRadioButton.m; sourceTree = ""; }; 01C851D223CF9E740021F976 /* LabelToggleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelToggleModel.swift; sourceTree = ""; }; @@ -827,9 +823,7 @@ isa = PBXGroup; children = ( 011D9583240422BF000E3791 /* New */, - 0198F79E225679870066C936 /* FormValidationProtocol.swift */, 0105618A224BBE7700E1557D /* FormValidator.swift */, - 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */, 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */, ); path = FormUIHelpers; @@ -1896,7 +1890,6 @@ 0A7EF85D23D8A95600B2AAD1 /* TextEntryFieldModel.swift in Sources */, D2D6CD4222E78FAB00D701B8 /* ThreeLayerTemplate.swift in Sources */, 01EB368F23609801006832FA /* LabelModel.swift in Sources */, - 0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */, 01F2A03223A4498200D954D8 /* CaretLinkModel.swift in Sources */, 0A7BAFA1232BE61800FB8E22 /* Checkbox.swift in Sources */, 011B58F023A2AA980085F53C /* ListItemModelProtocol.swift in Sources */, @@ -1966,7 +1959,6 @@ 01EB3684236097C0006832FA /* MoleculeModelProtocol.swift in Sources */, D27CD4102339057800C1DC07 /* EyebrowHeadlineBodyLink.swift in Sources */, D29DF11D21E684A9003B2FB9 /* MVMCoreUISplitViewController.m in Sources */, - 0198F79F225679880066C936 /* FormValidationProtocol.swift in Sources */, D243859923A16B1800332775 /* Container.swift in Sources */, D2C521A923EDE79E00CA2634 /* ViewController.swift in Sources */, D260105B23D0BB7100764D80 /* StackModelProtocol.swift in Sources */, diff --git a/MVMCoreUI/Atoms/TextFields/EntryField.swift b/MVMCoreUI/Atoms/TextFields/EntryField.swift index bbea1c62..43a15a3b 100644 --- a/MVMCoreUI/Atoms/TextFields/EntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/EntryField.swift @@ -48,8 +48,6 @@ import UIKit //-------------------------------------------------- public var isValid: Bool = false - public var fieldKey: String? - public var errorMessage: String? public var standardMessage: String? { didSet { @@ -259,10 +257,6 @@ import UIKit } else if let isSelected = model.isSelected{ self.isSelected = isSelected } - - if let fieldKey = model.fieldKey { - self.fieldKey = fieldKey - } } } @@ -300,11 +294,6 @@ extension EntryField { if let isSelected = dictionary["isSelected"] as? Bool { self.isSelected = isSelected } - - // Key used to send text value to server - if let fieldKey = dictionary[KeyFieldKey] as? String { - self.fieldKey = fieldKey - } } @objc open class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { @@ -312,22 +301,6 @@ extension EntryField { } } -// MARK: - Form Validation -extension EntryField: FormValidationProtocol { - - @objc public func isValidField() -> Bool { - return isValid - } - - @objc public func formFieldName() -> String? { - return fieldKey - } - - @objc public func formFieldValue() -> Any? { - return text - } -} - // MARK: - Accessibility extension EntryField { diff --git a/MVMCoreUI/Atoms/Views/Toggle.swift b/MVMCoreUI/Atoms/Views/Toggle.swift index c53b4be6..d6082292 100644 --- a/MVMCoreUI/Atoms/Views/Toggle.swift +++ b/MVMCoreUI/Atoms/Views/Toggle.swift @@ -19,7 +19,7 @@ public typealias ActionBlockConfirmation = () -> (Bool) Container: The background of the toggle control. Knob: The circular indicator that slides on the container. */ -@objcMembers open class Toggle: Control, MVMCoreUIViewConstrainingProtocol, FormValidationFormFieldProtocol { +@objcMembers open class Toggle: Control, MVMCoreUIViewConstrainingProtocol { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- @@ -339,82 +339,60 @@ public typealias ActionBlockConfirmation = () -> (Bool) return } + self.delegateObject = delegateObject let toggleModelJSON = toggleModel.toJSON() + + FormValidator.setupValidation(molecule: toggleModel, delegate: delegateObject?.formHolderDelegate) setWithJSON(toggleModelJSON, delegateObject: delegateObject, additionalData: additionalData) } + + //TODO: change to setWith Model + public override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + + guard let dictionary = json else { return } + + if let color = dictionary["onTintColor"] as? String { + containerTintColor?.on = UIColor.mfGet(forHex: color) + } + + if let color = dictionary["offTintColor"] as? String { + containerTintColor?.off = UIColor.mfGet(forHex: color) + } + + if let color = dictionary["onKnobTintColor"] as? String { + knobTintColor?.on = UIColor.mfGet(forHex: color) + } + + if let color = dictionary["offKnobTintColor"] as? String { + knobTintColor?.off = UIColor.mfGet(forHex: color) + } + + if let state = dictionary["state"] as? Bool { + changeStateNoAnimation(state) + } + + if let actionMap = dictionary.optionalDictionaryForKey("action") { + didToggleAction = { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) } + } + + if let isAnimated = dictionary["isAnimated"] as? Bool { + self.isAnimated = isAnimated + } + + if let isEnabled = dictionary["isEnabled"] as? Bool{ + self.isEnabled = isEnabled + } + } public override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { return Self.getContainerHeight() } } -// MARK: - Accessibility -extension Toggle { - - public func formFieldGroupName() -> String? { - return json?["groupName"] as? String - } -} - -// MARK: - FormValidationProtocol -extension Toggle { - - public func isValidField() -> Bool { - return isOn && json?["required"] as? Bool ?? false - } - - public func formFieldName() -> String? { - return json?[KeyFieldKey] as? String ?? "" - } - - public func formFieldValue() -> Any? { - return NSNumber(value: isOn) - } -} - // MARK: - MVMCoreUIMoleculeViewProtocol extension Toggle { - - public override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - self.delegateObject = delegateObject - -// FormValidator.setupValidation(molecule: self, delegate: delegateObject?.formValidationProtocol) - - guard let dictionary = json else { return } - - if let color = dictionary["onTintColor"] as? String { - containerTintColor?.on = UIColor.mfGet(forHex: color) - } - - if let color = dictionary["offTintColor"] as? String { - containerTintColor?.off = UIColor.mfGet(forHex: color) - } - - if let color = dictionary["onKnobTintColor"] as? String { - knobTintColor?.on = UIColor.mfGet(forHex: color) - } - - if let color = dictionary["offKnobTintColor"] as? String { - knobTintColor?.off = UIColor.mfGet(forHex: color) - } - - if let state = dictionary["state"] as? Bool { - changeStateNoAnimation(state) - } - - if let actionMap = dictionary.optionalDictionaryForKey("action") { - didToggleAction = { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) } - } - - if let isAnimated = dictionary["isAnimated"] as? Bool { - self.isAnimated = isAnimated - } - - if let isEnabled = dictionary["isEnabled"] as? Bool{ - self.isEnabled = isEnabled - } - } + public class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { return Self.getContainerHeight() diff --git a/MVMCoreUI/BaseControllers/MFViewController.m b/MVMCoreUI/BaseControllers/MFViewController.m index 1af64e34..d15a1b9e 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.m +++ b/MVMCoreUI/BaseControllers/MFViewController.m @@ -38,7 +38,7 @@ #import @import MVMAnimationFramework; -@interface MFViewController() +@interface MFViewController() // A flag for if this view controller is observing for cache updates or not. @property (nonatomic) BOOL observingForResponseJSONUpdates; diff --git a/MVMCoreUI/FormUIHelpers/FormValidationProtocol.swift b/MVMCoreUI/FormUIHelpers/FormValidationProtocol.swift deleted file mode 100644 index 49cfacc9..00000000 --- a/MVMCoreUI/FormUIHelpers/FormValidationProtocol.swift +++ /dev/null @@ -1,41 +0,0 @@ -// -// FormValidationProtocol.swift -// MVMCoreUI -// -// Created by Suresh, Kamlesh on 3/26/19. -// Copyright © 2019 Verizon Wireless. All rights reserved. -// - -import Foundation - -@objc public protocol FormValidationProtocol: NSObjectProtocol { - - // Getter method to get the FormValidator from the delegate (Mostly from the parent View Controller) - @objc optional func formValidatorModel() -> FormValidator? -} - -@objc public protocol FormValidationFormFieldProtocol: FormValidationProtocol { - // Used to check the validity of the field. For example, to enable/disable the primary button. - @objc func isValidField() -> Bool - - // The Field name key value pair for sending to server - @objc func formFieldName() -> String? - - // Returns the group name for validation. The class should always return a value. - @objc func formFieldGroupName() -> String? - - // The Field value key value pair for sending to server - @objc func formFieldValue() -> Any? -} - -@objc public protocol FormValidationEnableDisableProtocol: FormValidationProtocol { - - // Returns true if the button needs to be enabled/disabled based on the validation - @objc func isValidationRequired() -> Bool - - // Based on the isValidField(), the fields which needs to be enabled can call this method - @objc optional func enableField(_ enable: Bool) - - // Returns the list of field keys required to enable/disable - @objc optional func requiredGroups() -> [String]? -} diff --git a/MVMCoreUI/FormUIHelpers/FormValidator+FormParams.swift b/MVMCoreUI/FormUIHelpers/FormValidator+FormParams.swift deleted file mode 100644 index 97668df4..00000000 --- a/MVMCoreUI/FormUIHelpers/FormValidator+FormParams.swift +++ /dev/null @@ -1,10 +0,0 @@ -// -// MVMCoreUIFormValidator+FormParams.swift -// MVMCoreUI -// -// Created by Suresh, Kamlesh on 3/21/19. -// Copyright © 2019 Verizon Wireless. All rights reserved. -// - -import Foundation - diff --git a/MVMCoreUI/Legacy/Views/MFTextField.m b/MVMCoreUI/Legacy/Views/MFTextField.m index 691e6677..4ad018a4 100644 --- a/MVMCoreUI/Legacy/Views/MFTextField.m +++ b/MVMCoreUI/Legacy/Views/MFTextField.m @@ -18,7 +18,7 @@ @import MVMCore.NSDictionary_MFConvenience; @import MVMCore.MVMCoreJSONConstants; -@interface MFTextField() +@interface MFTextField() @property (strong, nonatomic) UIColor *customPlaceHolderColor; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *separatorHeightConstraint; @@ -560,11 +560,8 @@ - (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { [super setWithJSON:json delegateObject:delegateObject additionalData:additionalData]; if ([delegateObject isKindOfClass:[MVMCoreUIDelegateObject class]]) { -// [FormValidator setupValidationWithMolecule:self delegate:delegateObject.formValidationProtocol]; -// FormValidator *formValidator = [FormValidator getFormValidatorForDelegate:delegateObject.formValidationProtocol]; - [self setWithMap:json]; -// self.mfTextFieldDelegate = formValidator; + self.mfTextFieldDelegate = delegateObject.uiTextFieldDelegate; self.uiTextFieldDelegate = delegateObject.uiTextFieldDelegate; [MVMCoreUICommonViewsUtility addDismissToolbar:self.textField delegate:self.uiTextFieldDelegate]; } @@ -574,24 +571,4 @@ + (CGFloat)estimatedHeightForRow:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject { return 76; } - -#pragma mark - FormValidationProtocol - - -- (BOOL)isValidField { - return self.isValid; -} - -- (nullable NSString *)formFieldName { - return self.fieldKey; -} - -- (nullable id)formFieldValue { - return self.text; -} - -- (NSString * _Nullable)formFieldGroupName { - return self.groupName; -} - @end diff --git a/MVMCoreUI/Legacy/Views/MVMCoreUICheckBox.m b/MVMCoreUI/Legacy/Views/MVMCoreUICheckBox.m index cfa1d20b..ab906bd7 100644 --- a/MVMCoreUI/Legacy/Views/MVMCoreUICheckBox.m +++ b/MVMCoreUI/Legacy/Views/MVMCoreUICheckBox.m @@ -21,7 +21,7 @@ static const CGFloat FaultTolerance = 20.f; static const CGFloat CheckBoxHeightWidth = 18.0; -@interface MVMCoreUICheckBox () +@interface MVMCoreUICheckBox () @property (nonatomic, readwrite) BOOL isSelected; @property (weak, nonatomic) UIView *checkedSquare; @@ -109,23 +109,6 @@ static const CGFloat CheckBoxHeightWidth = 18.0; return checkBox; } -#pragma mark - FormValidationProtocol - -- (BOOL)isValidField { - if (self.isRequired) { - return self.isSelected; - } - return true; -} - -- (nullable NSString *)formFieldName { - return self.fieldKey; -} - -- (nullable id)formFieldValue { - return @(self.isSelected); -} - #pragma mark - inits - (instancetype)init { diff --git a/MVMCoreUI/Legacy/Views/MVMCoreUISwitch.m b/MVMCoreUI/Legacy/Views/MVMCoreUISwitch.m index c12e70a5..e4c3c38b 100644 --- a/MVMCoreUI/Legacy/Views/MVMCoreUISwitch.m +++ b/MVMCoreUI/Legacy/Views/MVMCoreUISwitch.m @@ -22,7 +22,7 @@ const CGFloat SwitchKnobWidth = 20; const CGFloat SwitchKnobHeight = 20; const CGFloat SwitchShakeIntensity = 2; -@interface MVMCoreUISwitch () +@interface MVMCoreUISwitch () @property (weak, nonatomic) UIView *baseView; @property (weak, nonatomic) UIView *knobView; @@ -426,22 +426,4 @@ const CGFloat SwitchShakeIntensity = 2; return [MVMCoreUIUtility hardcodedStringWithKey:@"AccToggleHint"]; } -#pragma mark FormValidationProtocol - -- (NSString * _Nullable)formFieldGroupName { - return [self.json string:@"groupName"]; -} - -- (BOOL)isValidField { - return self.isOn && [self.json boolForKey:@"required"]; -} - -- (NSString *)formFieldName { - return [self.json string:KeyFieldKey]; -} - -- (id)formFieldValue { - return @(self.isOn); -} - @end diff --git a/MVMCoreUI/Legacy/Views/PrimaryButton.m b/MVMCoreUI/Legacy/Views/PrimaryButton.m index f39edefc..4ced32ac 100644 --- a/MVMCoreUI/Legacy/Views/PrimaryButton.m +++ b/MVMCoreUI/Legacy/Views/PrimaryButton.m @@ -18,7 +18,7 @@ @import MVMCore.MVMCoreGetterUtility; @import MVMCore.NSDictionary_MFConvenience; -@interface PrimaryButton() +@interface PrimaryButton() @property (nonatomic) BOOL smallButton; @property (assign, nonatomic) BOOL tinyButton; @@ -781,22 +781,4 @@ } } -#pragma mark - FormValidationEnableDisableProtocol - -- (BOOL)isValidationRequired { - return self.validationRequired; -} - -- (NSArray *)requiredGroups { - return self.requiredGroupsList; -} - -- (void)enableField:(BOOL)enable { - if (!self.validationRequired) { - self.enabled = YES; - } else { - self.enabled = enable; - } -} - @end