diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 5409c5a9..ddf5c036 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -8,7 +8,6 @@ /* Begin PBXBuildFile section */ 01004F3022721C3800991ECC /* RadioButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01004F2F22721C3800991ECC /* RadioButton.swift */; }; - 01004F322273972F00991ECC /* MFView+FormValidation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01004F312273972F00991ECC /* MFView+FormValidation.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 */; }; @@ -171,7 +170,6 @@ /* Begin PBXFileReference section */ 01004F2F22721C3800991ECC /* RadioButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioButton.swift; sourceTree = ""; }; - 01004F312273972F00991ECC /* MFView+FormValidation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFView+FormValidation.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 = ""; }; @@ -325,10 +323,10 @@ D2C5001621F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIViewControllerMappingObject.h; sourceTree = ""; }; D2C5001721F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUIViewControllerMappingObject.m; sourceTree = ""; }; D2E1FADA2260D3D200AEFD8C /* MVMCoreUIDelegateObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVMCoreUIDelegateObject.swift; sourceTree = ""; }; - DB891E822253FA8500022516 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = ""; }; D2E1FADC2268B25E00AEFD8C /* MoleculeTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeTableViewCell.swift; sourceTree = ""; }; D2E1FADE2268B8E700AEFD8C /* ThreeLayerTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreeLayerTableViewController.swift; sourceTree = ""; }; D2E1FAE02268E81D00AEFD8C /* MoleculeListTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeListTemplate.swift; sourceTree = ""; }; + DB891E822253FA8500022516 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = ""; }; DBC4391622442196001AB423 /* CaretView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaretView.swift; sourceTree = ""; }; DBC4391722442197001AB423 /* DashLine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DashLine.swift; sourceTree = ""; }; DBC4391A224421A0001AB423 /* CaretButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaretButton.swift; sourceTree = ""; }; @@ -578,7 +576,6 @@ DBC4391622442196001AB423 /* CaretView.swift */, DBC4391722442197001AB423 /* DashLine.swift */, D29DF17E21E69E2E003B2FB9 /* MFView.h */, - 01004F312273972F00991ECC /* MFView+FormValidation.swift */, D29DF17F21E69E2E003B2FB9 /* MFView.m */, D29DF31E21ED0CBA003B2FB9 /* LabelView.h */, D29DF31F21ED0CBA003B2FB9 /* LabelView.m */, @@ -899,7 +896,6 @@ D22D1F572204CE5D0077CEC0 /* MVMCoreUIStackableViewController.m in Sources */, 01DF567021FA5AB300CC099B /* TextFieldListFormViewController.swift in Sources */, D2A5145F2211DDC100345BFB /* MoleculeStackView.swift in Sources */, - 01004F322273972F00991ECC /* MFView+FormValidation.swift in Sources */, D29DF27621E79E81003B2FB9 /* MVMCoreUILoggingHandler.m in Sources */, D29DF24D21E6A177003B2FB9 /* MFTextField.m in Sources */, D29DF2A221E7AF4E003B2FB9 /* MVMCoreUIUtility.m in Sources */, diff --git a/MVMCoreUI/Atoms/TextFields/MFTextField.m b/MVMCoreUI/Atoms/TextFields/MFTextField.m index 33224f8a..52580f46 100644 --- a/MVMCoreUI/Atoms/TextFields/MFTextField.m +++ b/MVMCoreUI/Atoms/TextFields/MFTextField.m @@ -298,14 +298,11 @@ self.uiTextFieldDelegate = delegate; } -- (void)setWithMap:(nullable NSDictionary *)map bothDelegates:(nullable id)delegate { +- (void)setWithMap:(nullable NSDictionary *)map { if (map.count == 0) { return; } - [MVMCoreUICommonViewsUtility addDismissToolbar:self.textField delegate:delegate]; - [self setBothTextFieldDelegates:delegate]; - NSString *string = [map string:KeyLabel]; if (string.length > 0) { self.formText = string; @@ -351,6 +348,12 @@ } } +- (void)setWithMap:(nullable NSDictionary *)map bothDelegates:(nullable id)delegate { + [MVMCoreUICommonViewsUtility addDismissToolbar:self.textField delegate:delegate]; + [self setBothTextFieldDelegates:delegate]; + [self setWithMap:map]; +} + - (void)setValidationBlock:(BOOL (^)(NSString * _Nullable))validationBlock { _validationBlock = validationBlock; [self valueChanged]; @@ -560,7 +563,11 @@ if ([delegateObject isKindOfClass:[MVMCoreUIDelegateObject class]]) { [FormValidator setupValidationWithMolecule:self delegate:((MVMCoreUIDelegateObject *)delegateObject).formValidationProtocol]; FormValidator *formValidator = [FormValidator getFormValidatorForDelegate:((MVMCoreUIDelegateObject *)delegateObject).formValidationProtocol]; - [self setWithMap:json bothDelegates:formValidator]; + + [self setWithMap:json]; + self.mfTextFieldDelegate = formValidator; + self.uiTextFieldDelegate = ((MVMCoreUIDelegateObject *)delegateObject).uiTextFieldDelegate; + [MVMCoreUICommonViewsUtility addDismissToolbar:self.textField delegate:self.uiTextFieldDelegate]; } } diff --git a/MVMCoreUI/Atoms/Views/MFView+FormValidation.swift b/MVMCoreUI/Atoms/Views/MFView+FormValidation.swift deleted file mode 100644 index 66d3d27a..00000000 --- a/MVMCoreUI/Atoms/Views/MFView+FormValidation.swift +++ /dev/null @@ -1,34 +0,0 @@ -// -// MFView+FormValidation.swift -// MVMCoreUI -// -// Created by Suresh, Kamlesh on 4/26/19. -// Copyright © 2019 Verizon Wireless. All rights reserved. -// - -import Foundation - - -fileprivate struct FormValidatorHolder { - static var formValidator: FormValidator? -} - -extension FormValidationProtocol where Self: MFView { - - var formValidator: FormValidator? { - get { - return FormValidatorHolder.formValidator - } - set(newValue) { - FormValidatorHolder.formValidator = newValue - } - } - - func setupFormValidation(delegateObject: DelegateObject?) { - if let delegateObject = delegateObject as? MVMCoreUIDelegateObject, - let formValidationProtocol = delegateObject.formValidationProtocol { - FormValidator.setupValidation(molecule: self, delegate:formValidationProtocol) - formValidator = FormValidator.getFormValidatorFor(delegate:formValidationProtocol) - } - } -} diff --git a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m index 76f2d0f6..48a46ef6 100644 --- a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m +++ b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m @@ -42,7 +42,7 @@ static const CGFloat CheckBoxHeightWidth = 18.0; @property (nonatomic) BOOL isRequired; @property (nullable, strong, nonatomic) NSString *fieldKey; -@property (nullable, strong, nonatomic) DelegateObject *delegate; +@property (nullable, strong, nonatomic) MVMCoreUIDelegateObject *delegateObject; @end @@ -60,12 +60,17 @@ static const CGFloat CheckBoxHeightWidth = 18.0; - (void)setWithJSON:(NSDictionary *)json delegateObject:(DelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { +<<<<<<< HEAD if ([delegateObject isKindOfClass:[MVMCoreUIDelegateObject class]]) { [FormValidator setupValidationWithMolecule:self delegate:((MVMCoreUIDelegateObject *)delegateObject).formValidationProtocol]; } self.delegate = delegateObject; +======= + [FormValidator setupValidationWithMolecule:self delegate:((MVMCoreUIDelegateObject *)delegateObject).formValidationProtocol]; + self.delegateObject = (MVMCoreUIDelegateObject *) delegateObject; +>>>>>>> e90b4c299e84ce13a69fc77d4e69ad027b55fa09 self.fieldKey = [json stringForKey:KeyFieldKey]; self.isRequired = [json boolForKey:KeyRequired]; @@ -346,8 +351,7 @@ static const CGFloat CheckBoxHeightWidth = 18.0; [self.checkMark updateCheckSelected:NO animated:animated]; } - FormValidator *formValidator = ((MVMCoreUIDelegateObject *)self.delegate).formValidationProtocol.formValidatorModel; - [formValidator enableByValidation]; + [FormValidator enableByValidationWithDelegate:((MVMCoreUIDelegateObject *)self.delegateObject).formValidationProtocol]; } - (void)setColor:(nullable UIColor *)color forState:(UIControlState)state { diff --git a/MVMCoreUI/BaseControllers/MFViewController.m b/MVMCoreUI/BaseControllers/MFViewController.m index 1bd5e866..b6f71412 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.m +++ b/MVMCoreUI/BaseControllers/MFViewController.m @@ -343,15 +343,24 @@ - (BOOL)isOverridingRightButton { NSDictionary *rightPanelLinkDict = [self.loadObject.pageJSON dict:@"rightPanelButtonLink"]; if (rightPanelLinkDict) { - [[MVMCoreActionHandler sharedActionHandler] handleActionWithDictionary:rightPanelLinkDict - additionalData:nil - delegateObject:[self delegateObject]]; + [[MVMCoreActionHandler sharedActionHandler] handleActionWithDictionary:rightPanelLinkDict additionalData:nil delegateObject:[self delegateObject]]; return YES; } else { return NO; } } +- (BOOL)isOverridingLeftButton { + NSDictionary *leftPanelLinkDict = [self.loadObject.pageJSON dict:@"leftPanelButtonLink"]; + if (leftPanelLinkDict) { + [[MVMCoreActionHandler sharedActionHandler] handleActionWithDictionary:leftPanelLinkDict additionalData:nil delegateObject:[self delegateObject]]; + return YES; + } else { + return NO; + } +} + + - (void)setSupportShouldBeAccessible:(BOOL)supportShouldBeAccessible { MVMCoreUISplitViewController *splitViewController = [MVMCoreUISession sharedGlobal].splitViewController; diff --git a/MVMCoreUI/Containers/TabBarController/MVMCoreUITabBarPageControlViewController.m b/MVMCoreUI/Containers/TabBarController/MVMCoreUITabBarPageControlViewController.m index d06ca5f4..1d8481d6 100644 --- a/MVMCoreUI/Containers/TabBarController/MVMCoreUITabBarPageControlViewController.m +++ b/MVMCoreUI/Containers/TabBarController/MVMCoreUITabBarPageControlViewController.m @@ -139,6 +139,22 @@ } } +- (BOOL)isOverridingLeftButton { + if ([self.viewController respondsToSelector:@selector(isOverridingLeftButton)]) { + return [self.viewController performSelector:@selector(isOverridingLeftButton)]; + } else { + return [super isOverridingLeftButton]; + } +} + +- (BOOL)isOverridingRightButton { + if ([self.viewController respondsToSelector:@selector(isOverridingRightButton)]) { + return [self.viewController performSelector:@selector(isOverridingRightButton)]; + } else { + return [super isOverridingRightButton]; + } +} + #pragma mark - View Cycle - (void)loadView { diff --git a/MVMCoreUI/FormUIHelpers/FormValidator+FormParams.swift b/MVMCoreUI/FormUIHelpers/FormValidator+FormParams.swift index 17da0e72..bb9885ab 100644 --- a/MVMCoreUI/FormUIHelpers/FormValidator+FormParams.swift +++ b/MVMCoreUI/FormUIHelpers/FormValidator+FormParams.swift @@ -17,12 +17,9 @@ import Foundation var extraParam: [String: Any] = [:] MVMCoreDispatchUtility.performSyncBlock(onMainThread: { for molecule in self.molecules { - if let formFieldName = molecule.formFieldName, - let formFieldValue = molecule.formFieldValue, - let fieldName = formFieldName(), - let fieldValue = formFieldValue() { - - extraParam[fieldName] = fieldValue + if let formFieldName = molecule.formFieldName?(), + let formFieldValue = molecule.formFieldValue?() { + extraParam[formFieldName] = formFieldValue } } }) diff --git a/MVMCoreUI/FormUIHelpers/FormValidator+TextFields.swift b/MVMCoreUI/FormUIHelpers/FormValidator+TextFields.swift index 2532910d..b2b18ebe 100644 --- a/MVMCoreUI/FormUIHelpers/FormValidator+TextFields.swift +++ b/MVMCoreUI/FormUIHelpers/FormValidator+TextFields.swift @@ -8,63 +8,6 @@ import Foundation -@objc extension FormValidator: UITextFieldDelegate { - public func textFieldDidEndEditing(_ textField: UITextField) { - enableByValidation() - if let delegate = delegate as? UITextFieldDelegate { - delegate.textFieldDidEndEditing?(textField) - } - } - - public func textFieldShouldReturn(_ textField: UITextField) -> Bool { - textField.resignFirstResponder() - if let delegate = delegate as? UITextFieldDelegate { - return delegate.textFieldShouldReturn?(textField) ?? true - } - return true - } - - public func textFieldDidBeginEditing(_ textField: UITextField) { - if let delegate = delegate as? UITextFieldDelegate { - delegate.textFieldDidBeginEditing?(textField) - } - } - - public func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool { - if let delegate = delegate as? UITextFieldDelegate { - return delegate.textFieldShouldBeginEditing?(textField) ?? true - } - return true - } - - public func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { - if let delegate = delegate as? UITextFieldDelegate { - return delegate.textFieldShouldEndEditing?(textField) ?? true - } - return true - } - - public func textFieldDidEndEditing(_ textField: UITextField, reason: UITextField.DidEndEditingReason) { - if let delegate = delegate as? UITextFieldDelegate { - delegate.textFieldDidEndEditing?(textField, reason: reason) - } - } - - public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { - if let delegate = delegate as? UITextFieldDelegate { - return delegate.textField?(textField, shouldChangeCharactersIn: range, replacementString: string) ?? true - } - return true - } - - public func textFieldShouldClear(_ textField: UITextField) -> Bool { - if let delegate = delegate as? UITextFieldDelegate { - return delegate.textFieldShouldClear?(textField) ?? true - } - return true - } -} - @objc extension FormValidator: MFTextFieldDelegate { public func dismissFieldInput(_ sender: Any?) { if let delegate = delegate as? MFTextFieldDelegate { diff --git a/MVMCoreUI/FormUIHelpers/FormValidator.swift b/MVMCoreUI/FormUIHelpers/FormValidator.swift index 5eb28904..07f4a583 100644 --- a/MVMCoreUI/FormUIHelpers/FormValidator.swift +++ b/MVMCoreUI/FormUIHelpers/FormValidator.swift @@ -19,19 +19,19 @@ import UIKit molecules.append(molecule) } - public static func getFormValidatorFor(delegate: FormValidationProtocol) -> FormValidator? { - if let delegateFormValidatorModel = delegate.formValidatorModel, - let validator = delegateFormValidatorModel() { - return validator - } else { - return nil + public static func enableByValidationWith(delegate: FormValidationProtocol?) { + if let delegate = delegate { + let formValidator = FormValidator.getFormValidatorFor(delegate: delegate) + formValidator?.enableByValidation() } } + public static func getFormValidatorFor(delegate: FormValidationProtocol) -> FormValidator? { + return delegate.formValidatorModel?() + } + public static func setupValidation(molecule: UIView & FormValidationProtocol, delegate: FormValidationProtocol?) { - if let delegateFormValidatorModel = delegate?.formValidatorModel, - let validator = delegateFormValidatorModel() { - + if let validator = delegate?.formValidatorModel?() { validator.delegate = delegate validator.insertMolecule(molecule) } diff --git a/MVMCoreUI/Molecules/RadioButton.swift b/MVMCoreUI/Molecules/RadioButton.swift index d5cc4d87..f55ef302 100644 --- a/MVMCoreUI/Molecules/RadioButton.swift +++ b/MVMCoreUI/Molecules/RadioButton.swift @@ -81,7 +81,6 @@ import UIKit } else { radioButton.isSelected = !radioButton.isSelected } - formValidator?.enableByValidation() } func getColor( _ json: [AnyHashable: Any], _ key: String) -> UIColor? { diff --git a/MVMCoreUI/Molecules/RadioButtonList.swift b/MVMCoreUI/Molecules/RadioButtonList.swift index 6a1083fd..1b597214 100644 --- a/MVMCoreUI/Molecules/RadioButtonList.swift +++ b/MVMCoreUI/Molecules/RadioButtonList.swift @@ -17,6 +17,8 @@ import UIKit var selectedRadioButton: RadioButton? var selectedValue: String? + var delegateObject:MVMCoreUIDelegateObject? + // MARK: - Inits public init() { @@ -35,7 +37,8 @@ import UIKit selectedRadioButton?.radioButton.isSelected = false selectedRadioButton = radioButton selectedRadioButton?.radioButton.isSelected = true - formValidator?.enableByValidation() + + FormValidator.enableByValidationWith(delegate: self.delegateObject?.formValidationProtocol) } open override func setupView() { @@ -56,7 +59,7 @@ extension RadioButtonList: FormValidationProtocol { // The Field name key value pair for sending to server @objc public func formFieldName() -> String? { - return selectedRadioButton?.formFieldName() + return json?.optionalStringForKey("fieldKey") } // The Feild value key value paid for sending to server @@ -78,7 +81,8 @@ extension RadioButtonList { return } - setupFormValidation(delegateObject: delegateObject) + self.delegateObject = delegateObject + FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol) StackableViewController.remove(self.subviews) diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift b/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift index eaf892fb..92744a8c 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift @@ -11,10 +11,12 @@ import UIKit open class MVMCoreUIDelegateObject: DelegateObject { public weak var formValidationProtocol: FormValidationProtocol? public weak var buttonDelegate: ButtonDelegateProtocol? - + public weak var uiTextFieldDelegate: UITextFieldDelegate? + open override func setAll(withDelegate delegate: Any) { super.setAll(withDelegate: delegate) formValidationProtocol = delegate as? FormValidationProtocol buttonDelegate = delegate as? ButtonDelegateProtocol + uiTextFieldDelegate = delegate as? UITextFieldDelegate } } diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index f8d97233..0a37d62e 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -33,8 +33,7 @@ @"caretView": CaretView.class, @"caretButton": CaretButton.class, @"textField" : MFTextField.class, - @"radioButtonList": RadioButtonList.class, - @"radioButton": RadioButton.class, + @"radioButton": RadioButtonList.class, @"checkbox" : MVMCoreUICheckBox.class } mutableCopy]; });