From a9734be4df338fd472a474023db53385d37ee81a Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 18 Apr 2019 12:32:59 -0400 Subject: [PATCH 01/47] detail view controller --- .../SplitViewController/MVMCoreUISplitViewController.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m index bdfd6ecd..ff2e2964 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m @@ -142,7 +142,7 @@ CGFloat const PanelAnimationDuration = 0.2; - (IBAction)leftPanelButtonPressed:(id)sender { [MVMCoreDispatchUtility performBlockOnMainThread:^{ - UIViewController *viewController = self.navigationController.topViewController; + UIViewController *viewController = [self getCurrentDetailViewController]; // If Viewcontroller confirms to protocol and implements the the method leftPanelButtonPressed if ([viewController conformsToProtocol:@protocol(MVMCoreUIDetailViewProtocol)] @@ -176,7 +176,7 @@ CGFloat const PanelAnimationDuration = 0.2; - (IBAction)rightPanelButtonPressed:(id)sender { [MVMCoreDispatchUtility performBlockOnMainThread:^{ - UIViewController *viewController = self.navigationController.topViewController; + UIViewController *viewController = [self getCurrentDetailViewController]; // If Viewcontroller confirms to protocol and implements the the method rightPanelButtonPressed if ([viewController conformsToProtocol:@protocol(MVMCoreUIDetailViewProtocol)] From 3ec1364aed221f8ec3b4b20413720a1bd617cc36 Mon Sep 17 00:00:00 2001 From: panxi Date: Fri, 3 May 2019 15:25:41 -0400 Subject: [PATCH 02/47] let tabbar manager handle child viewcontroller's behavior --- MVMCoreUI/BaseControllers/MFViewController.m | 13 +++++++++++++ .../MVMCoreUISplitViewController.m | 4 ++-- .../MVMCoreUITabBarPageControlViewController.m | 16 ++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/BaseControllers/MFViewController.m b/MVMCoreUI/BaseControllers/MFViewController.m index 0c3b3f3d..5c599ca3 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.m +++ b/MVMCoreUI/BaseControllers/MFViewController.m @@ -352,6 +352,19 @@ } } +- (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/SplitViewController/MVMCoreUISplitViewController.m b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m index ff2e2964..bdfd6ecd 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m @@ -142,7 +142,7 @@ CGFloat const PanelAnimationDuration = 0.2; - (IBAction)leftPanelButtonPressed:(id)sender { [MVMCoreDispatchUtility performBlockOnMainThread:^{ - UIViewController *viewController = [self getCurrentDetailViewController]; + UIViewController *viewController = self.navigationController.topViewController; // If Viewcontroller confirms to protocol and implements the the method leftPanelButtonPressed if ([viewController conformsToProtocol:@protocol(MVMCoreUIDetailViewProtocol)] @@ -176,7 +176,7 @@ CGFloat const PanelAnimationDuration = 0.2; - (IBAction)rightPanelButtonPressed:(id)sender { [MVMCoreDispatchUtility performBlockOnMainThread:^{ - UIViewController *viewController = [self getCurrentDetailViewController]; + UIViewController *viewController = self.navigationController.topViewController; // If Viewcontroller confirms to protocol and implements the the method rightPanelButtonPressed if ([viewController conformsToProtocol:@protocol(MVMCoreUIDetailViewProtocol)] diff --git a/MVMCoreUI/Containers/TabBarController/MVMCoreUITabBarPageControlViewController.m b/MVMCoreUI/Containers/TabBarController/MVMCoreUITabBarPageControlViewController.m index d06ca5f4..5845a06a 100644 --- a/MVMCoreUI/Containers/TabBarController/MVMCoreUITabBarPageControlViewController.m +++ b/MVMCoreUI/Containers/TabBarController/MVMCoreUITabBarPageControlViewController.m @@ -139,6 +139,22 @@ } } +- (BOOL)isOverridingLeftButton { + if ([self.viewController isKindOfClass:MFViewController.class]) { + return [(MFViewController *)self.viewController isOverridingLeftButton]; + } else { + return [super isOverridingLeftButton]; + } +} + +- (BOOL)isOverridingRightButton { + if ([self.viewController isKindOfClass:MFViewController.class]) { + return [(MFViewController *)self.viewController isOverridingRightButton]; + } else { + return [super isOverridingRightButton]; + } +} + #pragma mark - View Cycle - (void)loadView { From 14b01d0ae0aeccf8054d1415e892a33fc6fce623 Mon Sep 17 00:00:00 2001 From: Priya Date: Tue, 7 May 2019 12:55:46 -0400 Subject: [PATCH 03/47] switch changes --- MVMCoreUI.xcodeproj/project.pbxproj | 6 +- MVMCoreUI/Molecules/Switch.swift | 78 +++++++++++++++++++ .../MVMCoreUIMoleculeMappingObject.m | 3 +- 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 MVMCoreUI/Molecules/Switch.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 83b51092..45a09419 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ 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 */; }; + 016A1071228122180009D605 /* Switch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016A1070228122180009D605 /* Switch.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 */; }; @@ -170,6 +171,7 @@ 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 = ""; }; + 016A1070228122180009D605 /* Switch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Switch.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 = ""; }; @@ -319,10 +321,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 = ""; }; @@ -442,6 +444,7 @@ D29770C721F7C4AE00B2F0D0 /* TopLabelsView.h */, D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */, D282AACA2243C61700C46919 /* ButtonView.swift */, + 016A1070228122180009D605 /* Switch.swift */, D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */, D2A514662213885800345BFB /* StandardHeaderView.swift */, D2A5145C2211D22A00345BFB /* MVMCoreUIMoleculeViewProtocol.h */, @@ -917,6 +920,7 @@ D2A5146B2214905000345BFB /* ThreeLayerViewController.swift in Sources */, D29DF2C921E7BFC6003B2FB9 /* MFSizeObject.m in Sources */, D29DF2C721E7BF57003B2FB9 /* MFTabBarInteractor.m in Sources */, + 016A1071228122180009D605 /* Switch.swift in Sources */, D29DF29521E7ADB8003B2FB9 /* ProgrammaticScrollViewController.m in Sources */, D29DF16121E69996003B2FB9 /* MFViewController.m in Sources */, D2E1FAE12268E81D00AEFD8C /* MoleculeListTemplate.swift in Sources */, diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift new file mode 100644 index 00000000..dec7f46b --- /dev/null +++ b/MVMCoreUI/Molecules/Switch.swift @@ -0,0 +1,78 @@ +// +// Switch.swift +// MVMCoreUI +// +// Created by Priya on 5/6/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +public class Switch: ViewConstrainingView { + var isRequired: Bool? = false + var state: Bool? = false + var onTintColor: UIColor? = .clear + var offTintColor: UIColor? = .clear + var isOnState: Bool? = false + var fieldKey: String? = "" + // MARK: - Inits + public init() { + super.init(frame: .zero) + } + + public override init(frame: CGRect) { + super.init(frame: frame) + } + + required public init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + } + + // MARK: - MVMCoreUIMoleculeViewProtocol + open override func setAsMolecule() { + super.setAsMolecule() + } + + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + self.isRequired = json?[KeyRequired] as? Bool + self.state = json?["state"] as? Bool + if let onColorString = json?.optionalStringForKey("onTintColor") { + self.onTintColor = .mfGet(forHex: onColorString) + } + if let offColorString = json?.optionalStringForKey("offTintColor") { + self.offTintColor = .mfGet(forHex: offColorString) + } + self.fieldKey = json?[KeyFieldKey] as? String + + } + + func setupConstraints(forView view: UIView) { + leftPin = view.leftAnchor.constraint(equalTo: leftAnchor) + topPin = view.topAnchor.constraint(equalTo: topAnchor) + rightPin = rightAnchor.constraint(equalTo: view.rightAnchor) + bottomPin = bottomAnchor.constraint(equalTo: view.bottomAnchor) + leftPin?.isActive = true + topPin?.isActive = true + rightPin?.isActive = true + bottomPin?.isActive = true + } + + // MARK: - FormValidationProtocol + + func isValidField() -> Bool { + if self.isRequired ?? false { + return self.isOnState ?? false + } + return true + } + + func formFieldName() -> String { + return self.fieldKey ?? "" + } + + func formFieldValue() -> Bool { + return self.isOnState ?? false + } + +} diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index e1101191..391dd561 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -33,7 +33,8 @@ @"caretView": CaretView.class, @"caretButton": CaretButton.class, @"textField" : MFTextField.class, - @"checkbox" : MVMCoreUICheckBox.class + @"checkbox" : MVMCoreUICheckBox.class, + @"switch" : Switch.class } mutableCopy]; }); return mapping; From f4bf4c0b5a8cf5157e4199b12f12e95a2e36c968 Mon Sep 17 00:00:00 2001 From: panxi Date: Wed, 8 May 2019 11:03:14 -0400 Subject: [PATCH 04/47] update code based on Scott's comment --- MVMCoreUI/BaseControllers/MFViewController.m | 8 ++------ .../MVMCoreUITabBarPageControlViewController.m | 8 ++++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/MVMCoreUI/BaseControllers/MFViewController.m b/MVMCoreUI/BaseControllers/MFViewController.m index 5c599ca3..a9206b52 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.m +++ b/MVMCoreUI/BaseControllers/MFViewController.m @@ -343,9 +343,7 @@ - (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; @@ -355,9 +353,7 @@ - (BOOL)isOverridingLeftButton { NSDictionary *leftPanelLinkDict = [self.loadObject.pageJSON dict:@"leftPanelButtonLink"]; if (leftPanelLinkDict) { - [[MVMCoreActionHandler sharedActionHandler] handleActionWithDictionary:leftPanelLinkDict - additionalData:nil - delegateObject:[self delegateObject]]; + [[MVMCoreActionHandler sharedActionHandler] handleActionWithDictionary:leftPanelLinkDict additionalData:nil delegateObject:[self delegateObject]]; return YES; } else { return NO; diff --git a/MVMCoreUI/Containers/TabBarController/MVMCoreUITabBarPageControlViewController.m b/MVMCoreUI/Containers/TabBarController/MVMCoreUITabBarPageControlViewController.m index 5845a06a..1d8481d6 100644 --- a/MVMCoreUI/Containers/TabBarController/MVMCoreUITabBarPageControlViewController.m +++ b/MVMCoreUI/Containers/TabBarController/MVMCoreUITabBarPageControlViewController.m @@ -140,16 +140,16 @@ } - (BOOL)isOverridingLeftButton { - if ([self.viewController isKindOfClass:MFViewController.class]) { - return [(MFViewController *)self.viewController isOverridingLeftButton]; + if ([self.viewController respondsToSelector:@selector(isOverridingLeftButton)]) { + return [self.viewController performSelector:@selector(isOverridingLeftButton)]; } else { return [super isOverridingLeftButton]; } } - (BOOL)isOverridingRightButton { - if ([self.viewController isKindOfClass:MFViewController.class]) { - return [(MFViewController *)self.viewController isOverridingRightButton]; + if ([self.viewController respondsToSelector:@selector(isOverridingRightButton)]) { + return [self.viewController performSelector:@selector(isOverridingRightButton)]; } else { return [super isOverridingRightButton]; } From b5f65b6fdfcb82256cd5d185b83d1169f831096b Mon Sep 17 00:00:00 2001 From: panxi Date: Thu, 9 May 2019 10:50:36 -0400 Subject: [PATCH 05/47] update checkbox for crash --- MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m index ff46aa6a..0158beb1 100644 --- a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m +++ b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m @@ -342,8 +342,10 @@ static const CGFloat CheckBoxHeightWidth = 18.0; [self.checkMark updateCheckSelected:NO animated:animated]; } - FormValidator *formValidator = ((MVMCoreUIDelegateObject *)self.delegate).formValidationProtocol.formValidatorModel; - [formValidator enableByValidation]; + if (self.delegate && [self.delegate respondsToSelector:@selector(formValidationProtocol)] && [[self.delegate performSelector:@selector(formValidationProtocol)] respondsToSelector:@selector(formValidatorModel)]) { + FormValidator *formValidator = [[self.delegate performSelector:@selector(formValidationProtocol)] performSelector:@selector(formValidatorModel)]; + [formValidator enableByValidation]; + } } - (void)setColor:(nullable UIColor *)color forState:(UIControlState)state { From af81b62f9353631abcd1cf335a8ed29ed14ad555 Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 9 May 2019 10:58:05 -0400 Subject: [PATCH 06/47] switch --- MVMCoreUI/Molecules/Switch.swift | 111 ++++++++++++++++++++++++++----- 1 file changed, 93 insertions(+), 18 deletions(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index dec7f46b..f3fc775c 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -8,13 +8,16 @@ import UIKit -public class Switch: ViewConstrainingView { +public class Switch: ViewConstrainingView, FormValidationProtocol { + var aSwitch = UISwitch() + var label = Label() var isRequired: Bool? = false var state: Bool? = false var onTintColor: UIColor? = .clear var offTintColor: UIColor? = .clear var isOnState: Bool? = false var fieldKey: String? = "" + // MARK: - Inits public init() { super.init(frame: .zero) @@ -33,10 +36,47 @@ public class Switch: ViewConstrainingView { super.setAsMolecule() } + @objc func switchChanged(mySwitch: UISwitch) { + let value = mySwitch.isOn + let str = value ? "Switch is On" : "Switch is Off" + print("\(str)") + // Do something + } + + + open override func setupView() { + super.setupView() + aSwitch.onTintColor = self.onTintColor + aSwitch.addTarget(self, action: #selector(switchChanged), for: UIControl.Event.valueChanged) + self.addSubview(aSwitch) + self.addSubview(label) + label.translatesAutoresizingMaskIntoConstraints = false + aSwitch.translatesAutoresizingMaskIntoConstraints = false + } + + + public override func updateView(_ size: CGFloat) { + super.updateView(size) + self.setupConstraints(forView: self) + } + + + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) self.isRequired = json?[KeyRequired] as? Bool self.state = json?["state"] as? Bool + if let dict = json?.optionalDictionaryForKey("label") { + label.text = dict["text"] as? String + if let textColor = json?.optionalStringForKey("textColor") { + label.textColor = .mfGet(forHex: textColor) + } + } + + if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { + FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol) + } + if let onColorString = json?.optionalStringForKey("onTintColor") { self.onTintColor = .mfGet(forHex: onColorString) } @@ -44,35 +84,70 @@ public class Switch: ViewConstrainingView { self.offTintColor = .mfGet(forHex: offColorString) } self.fieldKey = json?[KeyFieldKey] as? String - + aSwitch.onTintColor = self.onTintColor } func setupConstraints(forView view: UIView) { - leftPin = view.leftAnchor.constraint(equalTo: leftAnchor) - topPin = view.topAnchor.constraint(equalTo: topAnchor) - rightPin = rightAnchor.constraint(equalTo: view.rightAnchor) - bottomPin = bottomAnchor.constraint(equalTo: view.bottomAnchor) - leftPin?.isActive = true - topPin?.isActive = true - rightPin?.isActive = true - bottomPin?.isActive = true + label.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 0).isActive = true + label.trailingAnchor.constraint(equalTo: aSwitch.leadingAnchor, constant: 20).isActive = true + label.topAnchor.constraint(equalTo: view.topAnchor).isActive = true + label.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true + + aSwitch.leadingAnchor.constraint(equalTo: label.trailingAnchor, constant: PaddingOne).isActive = true + //aSwitch.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -50).isActive = true + + + view.trailingAnchor.constraint(equalTo: aSwitch.trailingAnchor, constant: 0).isActive = true + + + aSwitch.topAnchor.constraint(equalTo: view.topAnchor).isActive = true + aSwitch.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true + // aSwitch.widthAnchor.constraint(equalToConstant: 60.0).isActive = true + } + // MARK: - FormValidationProtocol - func isValidField() -> Bool { - if self.isRequired ?? false { - return self.isOnState ?? false - } - return true + +// { +// "moleculeName":"switch", +// "fieldName": "switchOption", +// "fieldKey": "switchImei1", +// "onTintColor": "#ffff00", +// "offTintColor": "#ffffff", +// "state": true, +// "label": { +// "moleculeName": "label", +// "text": "This is a switch", +// "textColor": "#000000", +// "backgroundColor": "#FFFFFF" +// }, +// "required": false, +// +// } + public func isValidField() -> Bool { +// if self.isRequired ?? false { +// return aSwitch.isOn +// } + return aSwitch.isOn } - func formFieldName() -> String { + public func formFieldName() -> String? { return self.fieldKey ?? "" } - func formFieldValue() -> Bool { - return self.isOnState ?? false + public func formFieldValue() -> Any? { + return aSwitch.isOn + } + + public override func needsToBeConstrained() -> Bool { + return true + } + + public override func moleculeAlignment() -> UIStackView.Alignment { + return UIStackView.Alignment.leading } } + From 315ea87c10d71e30647b52a2edf7dc90c0c6b56c Mon Sep 17 00:00:00 2001 From: "Chowdhury, Shohrab" Date: Mon, 13 May 2019 15:51:21 -0400 Subject: [PATCH 07/47] add new font method for 5g --- MVMCoreUI/Styles/MFStyler.h | 3 +++ MVMCoreUI/Styles/MFStyler.m | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/MVMCoreUI/Styles/MFStyler.h b/MVMCoreUI/Styles/MFStyler.h index 49f02db0..ddafe4c9 100644 --- a/MVMCoreUI/Styles/MFStyler.h +++ b/MVMCoreUI/Styles/MFStyler.h @@ -157,6 +157,9 @@ B3 -> Legal //75Bd 10pt only for support + (nullable UIFont *)fontForUnreadMessageOnSupport; +//55Rg 16pt ++(nullable UIFont *)fontFiveGMessage:(BOOL)genericScaling; + // Returns the fonts for these styles allowing to apply a generic scale by device or not. + (nullable UIFont *)fontForBiggerHeadLine:(BOOL)genericScaling; + (nullable UIFont *)fontForPlan:(BOOL)genericScaling; diff --git a/MVMCoreUI/Styles/MFStyler.m b/MVMCoreUI/Styles/MFStyler.m index ca0fcd2e..45a881a0 100644 --- a/MVMCoreUI/Styles/MFStyler.m +++ b/MVMCoreUI/Styles/MFStyler.m @@ -347,6 +347,15 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; return [MFFonts mfFont75Bd:size]; } ++(nullable UIFont *)fontFiveGMessage:(BOOL)genericScaling { + CGFloat size = 16; + if (genericScaling) { + size = [self sizeFontGenericForCurrentDevice:size]; + } + return [MFFonts mfFont55Rg:size]; +} + + + (nullable UIFont *)fontForHeadlineAlternative:(BOOL)genericScaling { CGFloat size = 24; if (genericScaling) { From bad190a3aba01748be52076b1f1ac9e5fe07e416 Mon Sep 17 00:00:00 2001 From: "Chowdhury, Shohrab" Date: Mon, 13 May 2019 15:59:10 -0400 Subject: [PATCH 08/47] update font name --- MVMCoreUI/Styles/MFStyler.h | 4 ++-- MVMCoreUI/Styles/MFStyler.m | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Styles/MFStyler.h b/MVMCoreUI/Styles/MFStyler.h index ddafe4c9..09299a82 100644 --- a/MVMCoreUI/Styles/MFStyler.h +++ b/MVMCoreUI/Styles/MFStyler.h @@ -157,8 +157,8 @@ B3 -> Legal //75Bd 10pt only for support + (nullable UIFont *)fontForUnreadMessageOnSupport; -//55Rg 16pt -+(nullable UIFont *)fontFiveGMessage:(BOOL)genericScaling; +//55Rg 16pt for 5G flow ++ (nullable UIFont *)font5GMessage:(BOOL)genericScaling; // Returns the fonts for these styles allowing to apply a generic scale by device or not. + (nullable UIFont *)fontForBiggerHeadLine:(BOOL)genericScaling; diff --git a/MVMCoreUI/Styles/MFStyler.m b/MVMCoreUI/Styles/MFStyler.m index 45a881a0..f31cb88c 100644 --- a/MVMCoreUI/Styles/MFStyler.m +++ b/MVMCoreUI/Styles/MFStyler.m @@ -356,7 +356,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } -+ (nullable UIFont *)fontForHeadlineAlternative:(BOOL)genericScaling { ++ (nullable UIFont *)font5GMessage:(BOOL)genericScaling; { CGFloat size = 24; if (genericScaling) { size = [self sizeFontGenericForCurrentDevice:size]; From e4d8e3695ba2fc5eebb6964bd9ccf4d147cb6083 Mon Sep 17 00:00:00 2001 From: "Chowdhury, Shohrab" Date: Mon, 13 May 2019 16:02:04 -0400 Subject: [PATCH 09/47] update name method --- MVMCoreUI/Styles/MFStyler.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Styles/MFStyler.m b/MVMCoreUI/Styles/MFStyler.m index f31cb88c..e0fc8217 100644 --- a/MVMCoreUI/Styles/MFStyler.m +++ b/MVMCoreUI/Styles/MFStyler.m @@ -347,7 +347,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; return [MFFonts mfFont75Bd:size]; } -+(nullable UIFont *)fontFiveGMessage:(BOOL)genericScaling { ++(nullable UIFont *)font5GMessage:(BOOL)genericScaling { CGFloat size = 16; if (genericScaling) { size = [self sizeFontGenericForCurrentDevice:size]; From 629c531d21dc3bc3b9f57cc329fdec36f8f0f962 Mon Sep 17 00:00:00 2001 From: "Chowdhury, Shohrab" Date: Mon, 13 May 2019 16:03:59 -0400 Subject: [PATCH 10/47] update name --- MVMCoreUI/Styles/MFStyler.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Styles/MFStyler.m b/MVMCoreUI/Styles/MFStyler.m index e0fc8217..d8eab822 100644 --- a/MVMCoreUI/Styles/MFStyler.m +++ b/MVMCoreUI/Styles/MFStyler.m @@ -356,7 +356,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } -+ (nullable UIFont *)font5GMessage:(BOOL)genericScaling; { ++ (nullable UIFont *)fontForHeadlineAlternative:(BOOL)genericScaling { CGFloat size = 24; if (genericScaling) { size = [self sizeFontGenericForCurrentDevice:size]; From e949f6ec2fe72e9c74e7ba58cdc283855f528f23 Mon Sep 17 00:00:00 2001 From: "Chowdhury, Shohrab" Date: Mon, 13 May 2019 16:07:17 -0400 Subject: [PATCH 11/47] add space in method name --- MVMCoreUI/Styles/MFStyler.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Styles/MFStyler.m b/MVMCoreUI/Styles/MFStyler.m index d8eab822..a1e60db6 100644 --- a/MVMCoreUI/Styles/MFStyler.m +++ b/MVMCoreUI/Styles/MFStyler.m @@ -347,7 +347,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; return [MFFonts mfFont75Bd:size]; } -+(nullable UIFont *)font5GMessage:(BOOL)genericScaling { ++ (nullable UIFont *)font5GMessage:(BOOL)genericScaling { CGFloat size = 16; if (genericScaling) { size = [self sizeFontGenericForCurrentDevice:size]; From b77ec675e012dbd5d87851d1b751f32b698814ab Mon Sep 17 00:00:00 2001 From: Priya Date: Tue, 14 May 2019 14:34:54 -0400 Subject: [PATCH 12/47] Switch molecule --- MVMCoreUI/Molecules/Switch.swift | 109 ++++++++++++------------------- 1 file changed, 43 insertions(+), 66 deletions(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index f3fc775c..162ddebc 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -11,14 +11,15 @@ import UIKit public class Switch: ViewConstrainingView, FormValidationProtocol { var aSwitch = UISwitch() var label = Label() + var mfTextButton = MFTextButton() var isRequired: Bool? = false var state: Bool? = false var onTintColor: UIColor? = .clear var offTintColor: UIColor? = .clear var isOnState: Bool? = false var fieldKey: String? = "" + var delegate: DelegateObject? - // MARK: - Inits public init() { super.init(frame: .zero) } @@ -30,47 +31,50 @@ public class Switch: ViewConstrainingView, FormValidationProtocol { required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } - - // MARK: - MVMCoreUIMoleculeViewProtocol open override func setAsMolecule() { super.setAsMolecule() } - + @objc func switchChanged(mySwitch: UISwitch) { - let value = mySwitch.isOn - let str = value ? "Switch is On" : "Switch is Off" - print("\(str)") - // Do something + let formValidator = (self.delegate as? MVMCoreUIDelegateObject)?.formValidationProtocol?.formValidatorModel?() + formValidator?.enableByValidation() } - - + open override func setupView() { super.setupView() - aSwitch.onTintColor = self.onTintColor - aSwitch.addTarget(self, action: #selector(switchChanged), for: UIControl.Event.valueChanged) - self.addSubview(aSwitch) - self.addSubview(label) + aSwitch.onTintColor = onTintColor + + aSwitch.addTarget(self, action: #selector(Switch.switchChanged(mySwitch:)), for: .valueChanged) + mfTextButton = MFTextButton(nil, constrainHeight: true, forWidth: CGFloat.leastNormalMagnitude) + + addSubview(aSwitch) + addSubview(label) + addSubview(mfTextButton) + label.translatesAutoresizingMaskIntoConstraints = false aSwitch.translatesAutoresizingMaskIntoConstraints = false + mfTextButton.translatesAutoresizingMaskIntoConstraints = false; + setupConstraints(forView: self) } - public override func updateView(_ size: CGFloat) { super.updateView(size) - self.setupConstraints(forView: self) + label.updateView(size) + mfTextButton.updateView(size) } - - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - self.isRequired = json?[KeyRequired] as? Bool - self.state = json?["state"] as? Bool + isRequired = json?[KeyRequired] as? Bool + state = json?["state"] as? Bool + + self.delegate = delegateObject if let dict = json?.optionalDictionaryForKey("label") { - label.text = dict["text"] as? String - if let textColor = json?.optionalStringForKey("textColor") { - label.textColor = .mfGet(forHex: textColor) - } + label.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData) + } + + if let dict = json?.optionalDictionaryForKey("textButton") { + mfTextButton.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData) } if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { @@ -78,63 +82,36 @@ public class Switch: ViewConstrainingView, FormValidationProtocol { } if let onColorString = json?.optionalStringForKey("onTintColor") { - self.onTintColor = .mfGet(forHex: onColorString) + onTintColor = .mfGet(forHex: onColorString) } if let offColorString = json?.optionalStringForKey("offTintColor") { - self.offTintColor = .mfGet(forHex: offColorString) + offTintColor = .mfGet(forHex: offColorString) } - self.fieldKey = json?[KeyFieldKey] as? String - aSwitch.onTintColor = self.onTintColor + + aSwitch.onTintColor = onTintColor + aSwitch.isOn = state ?? false } func setupConstraints(forView view: UIView) { - label.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 0).isActive = true - label.trailingAnchor.constraint(equalTo: aSwitch.leadingAnchor, constant: 20).isActive = true - label.topAnchor.constraint(equalTo: view.topAnchor).isActive = true - label.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true + NSLayoutConstraint.constraintPinRightSubview(aSwitch, rightConstant: 0) + NSLayoutConstraint.constraintPinLeftSubview(label, leftConstant: 0) - aSwitch.leadingAnchor.constraint(equalTo: label.trailingAnchor, constant: PaddingOne).isActive = true - //aSwitch.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -50).isActive = true - + NSLayoutConstraint.constraintPinSubview(aSwitch, pinTop: true, topConstant: 0, topRelation: .equal, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: false, rightConstant: 0, rightRelation: .equal) - view.trailingAnchor.constraint(equalTo: aSwitch.trailingAnchor, constant: 0).isActive = true - - - aSwitch.topAnchor.constraint(equalTo: view.topAnchor).isActive = true - aSwitch.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true - // aSwitch.widthAnchor.constraint(equalToConstant: 60.0).isActive = true + NSLayoutConstraint.constraintPinTopSubview(label, topConstant: 0) + NSLayoutConstraint(pinFirstView: label, toSecondView: aSwitch, withConstant: PaddingOne, directionVertical: false)?.isActive = true + NSLayoutConstraint(pinFirstView: label, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true)?.isActive = true + NSLayoutConstraint.constraintPinLeftSubview(mfTextButton, leftConstant: 0) + NSLayoutConstraint.constraintPinBottomSubview(mfTextButton, bottomConstant: 0) } - - // MARK: - FormValidationProtocol - - -// { -// "moleculeName":"switch", -// "fieldName": "switchOption", -// "fieldKey": "switchImei1", -// "onTintColor": "#ffff00", -// "offTintColor": "#ffffff", -// "state": true, -// "label": { -// "moleculeName": "label", -// "text": "This is a switch", -// "textColor": "#000000", -// "backgroundColor": "#FFFFFF" -// }, -// "required": false, -// -// } public func isValidField() -> Bool { -// if self.isRequired ?? false { -// return aSwitch.isOn -// } - return aSwitch.isOn + return (isRequired == false) ? true : aSwitch.isOn } public func formFieldName() -> String? { - return self.fieldKey ?? "" + return json?.optionalStringForKey(KeyFieldKey) } public func formFieldValue() -> Any? { From 150c218ea7328e8637be7a2709ed9d25fee2f1b4 Mon Sep 17 00:00:00 2001 From: "Chowdhury, Shohrab" Date: Tue, 14 May 2019 14:37:41 -0400 Subject: [PATCH 13/47] update ble pair --- MVMCoreUI/Styles/MFStyler.h | 4 ++++ MVMCoreUI/Styles/MFStyler.m | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/MVMCoreUI/Styles/MFStyler.h b/MVMCoreUI/Styles/MFStyler.h index 09299a82..0a52c468 100644 --- a/MVMCoreUI/Styles/MFStyler.h +++ b/MVMCoreUI/Styles/MFStyler.h @@ -160,6 +160,10 @@ B3 -> Legal //55Rg 16pt for 5G flow + (nullable UIFont *)font5GMessage:(BOOL)genericScaling; +//55Rg 16pt for 5G flow scale YES ++ (nullable UIFont *)font5GMessage; + + // Returns the fonts for these styles allowing to apply a generic scale by device or not. + (nullable UIFont *)fontForBiggerHeadLine:(BOOL)genericScaling; + (nullable UIFont *)fontForPlan:(BOOL)genericScaling; diff --git a/MVMCoreUI/Styles/MFStyler.m b/MVMCoreUI/Styles/MFStyler.m index a1e60db6..f7353f72 100644 --- a/MVMCoreUI/Styles/MFStyler.m +++ b/MVMCoreUI/Styles/MFStyler.m @@ -355,6 +355,12 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; return [MFFonts mfFont55Rg:size]; } ++ (nullable UIFont *)font5GMessage { + CGFloat size = 16; + size = [self sizeFontGenericForCurrentDevice:size]; + return [MFFonts mfFont55Rg:size]; +} + + (nullable UIFont *)fontForHeadlineAlternative:(BOOL)genericScaling { CGFloat size = 24; From 5da427d469e9ad91752d3d3e45bf11987b7db3a1 Mon Sep 17 00:00:00 2001 From: "Chowdhury, Shohrab" Date: Tue, 14 May 2019 14:43:22 -0400 Subject: [PATCH 14/47] add font --- MVMCoreUI/Styles/MFStyler.m | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/MVMCoreUI/Styles/MFStyler.m b/MVMCoreUI/Styles/MFStyler.m index f7353f72..261181b1 100644 --- a/MVMCoreUI/Styles/MFStyler.m +++ b/MVMCoreUI/Styles/MFStyler.m @@ -356,9 +356,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nullable UIFont *)font5GMessage { - CGFloat size = 16; - size = [self sizeFontGenericForCurrentDevice:size]; - return [MFFonts mfFont55Rg:size]; + return [self font5GMessage:YES]; } From 0f458d21a3733efb3c62fd44c72b9e2309068323 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 15 May 2019 11:16:08 -0400 Subject: [PATCH 15/47] module molecule --- .../MVMCoreUIMoleculeMappingObject.h | 19 ++++++-- .../MVMCoreUIMoleculeMappingObject.m | 42 +++++++++++++++++ .../Templates/MoleculeStackTemplate.swift | 47 +++++++++++++++++++ MVMCoreUI/Utility/MVMCoreUIConstants.h | 7 +++ 4 files changed, 111 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h index 43a113c9..79534f20 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h @@ -9,20 +9,31 @@ #import #import @class DelegateObject; +@class MVMCoreLoadObject; +@class MVMCoreErrorObject; @interface MVMCoreUIMoleculeMappingObject : NSObject -// Maps molecule name to class. +/// Maps molecule name to class. @property (nullable, strong, nonatomic) NSMutableDictionary *moleculeMapping; -// Returns the shared instance +/// Returns the shared instance + (nullable instancetype)sharedMappingObject; -// Returns the molecule for the given name. +/// Returns the molecule for the given name. - (nullable UIView *)getMoleculeForName:(nonnull NSString *)name; - (nullable UIView *)getMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable DelegateObject *)delegateObject; -// Similar to above but also checks if the molecule needs to be constrained for a stack. +/// Returns the molecule for the json. Also checks if the molecule needs to be constrained for a stack. - (nullable UIView *)getMoleculeForStackWithJSON:(nonnull NSDictionary *)json delegateObject:(nullable DelegateObject *)delegateObject; +/// Returns the molecule for the json. Checks if the molecule needs to be constrained for a stack. Load object may be used if the molecule needs to be loaded from the page or module map. +- (nullable UIView *)getMoleculeForStackWithJSON:(nonnull NSDictionary *)json delegateObject:(nullable DelegateObject *)delegateObject loadObject:(nullable MVMCoreLoadObject *)loadObject; + +#pragma mark - Helpers + +/// Gets the molecule from the passed in module map. ++ (nullable NSDictionary *)getMoleculeMapForModuleMolecule:(nullable NSDictionary *)moduleMolecule moduleMap:(nullable NSDictionary *)moduleMap error:(MVMCoreErrorObject *_Nullable *_Nullable)error; ++ (nullable NSString *)getMoleculeNameForModuleMolecule:(nullable NSDictionary *)moduleMolecule moduleMap:(nullable NSDictionary *)moduleMap error:(MVMCoreErrorObject *_Nullable *_Nullable)error; + @end diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index e1101191..58586bb5 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -9,6 +9,7 @@ #import "MVMCoreUIMoleculeMappingObject.h" @import MVMCore.MVMCoreActionUtility; @import MVMCore.NSDictionary_MFConvenience; +@import MVMCore.MVMCoreLoadObject; #import "MVMCoreUIObject.h" #import #import "MFTextField.h" @@ -80,4 +81,45 @@ return molecule; } +- (nullable UIView *)getMoleculeForStackWithJSON:(nonnull NSDictionary *)json delegateObject:(nullable DelegateObject *)delegateObject loadObject:(nullable MVMCoreLoadObject *)loadObject { + NSString *moleculeName = [json string:KeyMoleculeName]; + if (!moleculeName) { + return nil; + } else if ([moleculeName isEqualToString:@"moduleMolecule"]) { + NSString *moduleName = [json string:@"moduleName"]; + if (moduleName) { + NSDictionary *newJSON = [loadObject.modulesJSON dict:moduleName]; + if (newJSON) { + json = newJSON; + } + } + } + UIView *molecule = [self getMoleculeForName:moleculeName]; + if ([molecule respondsToSelector:@selector(needsToBeConstrained)] && [molecule needsToBeConstrained]) { + molecule = [[ViewConstrainingView alloc] initWithMolecule:molecule alignment:[molecule respondsToSelector:@selector(moleculeAlignment)] ? [molecule moleculeAlignment] : UIStackViewAlignmentFill]; + } + [molecule setWithJSON:json delegateObject:delegateObject additionalData:nil]; + return molecule; +} + +#pragma mark - Helpers + ++ (nullable NSDictionary *)getMoleculeMapForModuleMolecule:(nullable NSDictionary *)moduleMolecule moduleMap:(nullable NSDictionary *)moduleMap error:(MVMCoreErrorObject *_Nullable *_Nullable)error { + NSString *moleculeName = [moduleMolecule string:KeyMoleculeName]; + if ([moleculeName isEqualToString:@"moduleMolecule"]) { + NSString *moduleName = [moduleMolecule string:@"moduleName"]; + NSDictionary *module = moduleName ? [moduleMap dict:moduleName] : nil; + if (!module && error) { + *error = [[MVMCoreErrorObject alloc] initWithTitle:nil message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeModuleMolecule domain:ErrorDomainNative location:NSStringFromClass(self)]; + } + return module; + } else { + return nil; + } +} + ++ (nullable NSString *)getMoleculeNameForModuleMolecule:(nullable NSDictionary *)moduleMolecule moduleMap:(nullable NSDictionary *)moduleMap error:(MVMCoreErrorObject *_Nullable *_Nullable)error { + return [[self getMoleculeMapForModuleMolecule:moduleMolecule moduleMap:moduleMap error:error] string:KeyMoleculeName]; +} + @end diff --git a/MVMCoreUI/Templates/MoleculeStackTemplate.swift b/MVMCoreUI/Templates/MoleculeStackTemplate.swift index 51b3ed7f..10a291d7 100644 --- a/MVMCoreUI/Templates/MoleculeStackTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeStackTemplate.swift @@ -10,6 +10,15 @@ import UIKit public class MoleculeStackTemplate: ThreeLayerViewController { + public override func shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject, error: AutoreleasingUnsafeMutablePointer) -> Bool { + var shouldFinish = super.shouldFinishProcessingLoad(loadObject, error: error) + if shouldFinish, let firstError = modulesNeeded().errors?.first { + // Don't continue if there was an error loading needed modules. + error.pointee = firstError + shouldFinish = false + } + return shouldFinish + } public override func spaceBetweenTopAndMiddle() -> CGFloat? { return 0 @@ -35,4 +44,42 @@ public class MoleculeStackTemplate: ThreeLayerViewController { } return molecule } + + // MARK: - cache handling + public override func pageTypesToListenFor() -> [Any]? { + guard let pageType = self.pageType else { + return super.pageTypesToListenFor() + } + return [pageType] + } + + public override func modulesToListenFor() -> [Any]? { + // Get all of the molecules that need modules. + return modulesNeeded().modules + } + + // MARK: - Module Molecule Handling + func addModule(for moduleMolecule: [AnyHashable: Any]?, modules: inout [String], errors: inout [MVMCoreErrorObject]) { + var error: MVMCoreErrorObject? + if let moleculeName = MVMCoreUIMoleculeMappingObject.getMoleculeName(forModuleMolecule: moduleMolecule, moduleMap: loadObject?.modulesJSON, error: &error) { + modules.append(moleculeName) + if let errorObject = error { + MVMCoreLoggingHandler.shared()?.addError(toLog: errorObject) + errors.append(errorObject) + } + } + } + + func modulesNeeded() -> (modules: [String]?, errors: [MVMCoreErrorObject]?) { + var modules: [String] = [] + var errors: [MVMCoreErrorObject] = [] + addModule(for: loadObject?.pageJSON?.optionalDictionaryForKey("header"), modules: &modules, errors: &errors) + addModule(for: loadObject?.pageJSON?.optionalDictionaryForKey("footer"), modules: &modules, errors: &errors) + if let molecules = loadObject?.pageJSON?.optionalArrayForChainOfKeysOrIndexes(["moleculeStack","molecules"]) as? [[AnyHashable: Any]] { + for molecule in molecules { + addModule(for: molecule, modules: &modules, errors: &errors) + } + } + return (modules.count > 0 ? modules : nil, errors.count > 0 ? errors : nil) + } } diff --git a/MVMCoreUI/Utility/MVMCoreUIConstants.h b/MVMCoreUI/Utility/MVMCoreUIConstants.h index 189c2c49..6a3f930c 100644 --- a/MVMCoreUI/Utility/MVMCoreUIConstants.h +++ b/MVMCoreUI/Utility/MVMCoreUIConstants.h @@ -68,3 +68,10 @@ extern BOOL DisableAnimations; // Hand Scroll Key extern NSString * const KeyHandScrollAnimation; extern NSString * const KeyHandScroll; + +#pragma mark - Error Codes + +// Native Error Codes (Add new ones to bottom, don't change order!) +typedef NS_ENUM(NSInteger, CoreUIErrorCode) { + ErrorCodeModuleMolecule = 100 +}; From 8ef420e3a4500c65c90c0eb3573f587c6c4ab60a Mon Sep 17 00:00:00 2001 From: Priya Date: Wed, 15 May 2019 12:01:30 -0400 Subject: [PATCH 16/47] switch modification --- MVMCoreUI/Molecules/Switch.swift | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index 162ddebc..50f9aae0 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -13,11 +13,8 @@ public class Switch: ViewConstrainingView, FormValidationProtocol { var label = Label() var mfTextButton = MFTextButton() var isRequired: Bool? = false - var state: Bool? = false var onTintColor: UIColor? = .clear var offTintColor: UIColor? = .clear - var isOnState: Bool? = false - var fieldKey: String? = "" var delegate: DelegateObject? public init() { @@ -66,8 +63,6 @@ public class Switch: ViewConstrainingView, FormValidationProtocol { open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) isRequired = json?[KeyRequired] as? Bool - state = json?["state"] as? Bool - self.delegate = delegateObject if let dict = json?.optionalDictionaryForKey("label") { label.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData) @@ -87,21 +82,17 @@ public class Switch: ViewConstrainingView, FormValidationProtocol { if let offColorString = json?.optionalStringForKey("offTintColor") { offTintColor = .mfGet(forHex: offColorString) } - aSwitch.onTintColor = onTintColor - aSwitch.isOn = state ?? false + aSwitch.isOn = json?.optionalBoolForKey("state") ?? false } func setupConstraints(forView view: UIView) { NSLayoutConstraint.constraintPinRightSubview(aSwitch, rightConstant: 0) NSLayoutConstraint.constraintPinLeftSubview(label, leftConstant: 0) - NSLayoutConstraint.constraintPinSubview(aSwitch, pinTop: true, topConstant: 0, topRelation: .equal, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: false, rightConstant: 0, rightRelation: .equal) - NSLayoutConstraint.constraintPinTopSubview(label, topConstant: 0) NSLayoutConstraint(pinFirstView: label, toSecondView: aSwitch, withConstant: PaddingOne, directionVertical: false)?.isActive = true NSLayoutConstraint(pinFirstView: label, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true)?.isActive = true - NSLayoutConstraint.constraintPinLeftSubview(mfTextButton, leftConstant: 0) NSLayoutConstraint.constraintPinBottomSubview(mfTextButton, bottomConstant: 0) } From 97b7fbebad7e06198b442663ba7b18f7c04656e9 Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 16 May 2019 10:20:13 -0400 Subject: [PATCH 17/47] switch modification --- MVMCoreUI/Molecules/Switch.swift | 75 ++++++++++++-------------------- 1 file changed, 29 insertions(+), 46 deletions(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index 50f9aae0..b01ef73e 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -8,48 +8,31 @@ import UIKit -public class Switch: ViewConstrainingView, FormValidationProtocol { - var aSwitch = UISwitch() +@objcMembers public class Switch: ViewConstrainingView, FormValidationProtocol{ + public var mvmSwitch = UISwitch() var label = Label() var mfTextButton = MFTextButton() - var isRequired: Bool? = false - var onTintColor: UIColor? = .clear - var offTintColor: UIColor? = .clear - var delegate: DelegateObject? - - public init() { - super.init(frame: .zero) - } - - public override init(frame: CGRect) { - super.init(frame: frame) - } - - required public init?(coder aDecoder: NSCoder) { - super.init(coder: aDecoder) - } - open override func setAsMolecule() { - super.setAsMolecule() - } + var isRequired: Bool! = false - @objc func switchChanged(mySwitch: UISwitch) { - let formValidator = (self.delegate as? MVMCoreUIDelegateObject)?.formValidationProtocol?.formValidatorModel?() - formValidator?.enableByValidation() + var delegateObject: DelegateObject? + + + @objc func switchChanged() { + let delegate = delegateObject as? MVMCoreUIDelegateObject + if let delegate = delegate { + let formValidator = delegate.formValidationProtocol?.formValidatorModel?() + formValidator?.enableByValidation() + } } open override func setupView() { super.setupView() - aSwitch.onTintColor = onTintColor - - aSwitch.addTarget(self, action: #selector(Switch.switchChanged(mySwitch:)), for: .valueChanged) - mfTextButton = MFTextButton(nil, constrainHeight: true, forWidth: CGFloat.leastNormalMagnitude) - - addSubview(aSwitch) + mvmSwitch.addTarget(self, action: #selector(Switch.switchChanged), for: .valueChanged) + addSubview(mvmSwitch) addSubview(label) addSubview(mfTextButton) - - label.translatesAutoresizingMaskIntoConstraints = false - aSwitch.translatesAutoresizingMaskIntoConstraints = false + // label.translatesAutoresizingMaskIntoConstraints = false + mvmSwitch.translatesAutoresizingMaskIntoConstraints = false mfTextButton.translatesAutoresizingMaskIntoConstraints = false; setupConstraints(forView: self) } @@ -63,7 +46,7 @@ public class Switch: ViewConstrainingView, FormValidationProtocol { open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) isRequired = json?[KeyRequired] as? Bool - self.delegate = delegateObject + self.delegateObject = delegateObject if let dict = json?.optionalDictionaryForKey("label") { label.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData) } @@ -77,28 +60,28 @@ public class Switch: ViewConstrainingView, FormValidationProtocol { } if let onColorString = json?.optionalStringForKey("onTintColor") { - onTintColor = .mfGet(forHex: onColorString) + mvmSwitch.onTintColor = .mfGet(forHex: onColorString) } - if let offColorString = json?.optionalStringForKey("offTintColor") { - offTintColor = .mfGet(forHex: offColorString) - } - aSwitch.onTintColor = onTintColor - aSwitch.isOn = json?.optionalBoolForKey("state") ?? false + mvmSwitch.isOn = json?.optionalBoolForKey("state") ?? false } func setupConstraints(forView view: UIView) { - NSLayoutConstraint.constraintPinRightSubview(aSwitch, rightConstant: 0) NSLayoutConstraint.constraintPinLeftSubview(label, leftConstant: 0) - NSLayoutConstraint.constraintPinSubview(aSwitch, pinTop: true, topConstant: 0, topRelation: .equal, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: false, rightConstant: 0, rightRelation: .equal) + NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinTop: true, topConstant: 0, topRelation: .equal, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: true, rightConstant: 0, rightRelation: .equal) NSLayoutConstraint.constraintPinTopSubview(label, topConstant: 0) - NSLayoutConstraint(pinFirstView: label, toSecondView: aSwitch, withConstant: PaddingOne, directionVertical: false)?.isActive = true - NSLayoutConstraint(pinFirstView: label, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true)?.isActive = true + _ = NSLayoutConstraint(pinFirstView: label, toSecondView: mvmSwitch, withConstant: PaddingOne, directionVertical: false) + _ = NSLayoutConstraint(pinFirstView: label, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true) NSLayoutConstraint.constraintPinLeftSubview(mfTextButton, leftConstant: 0) NSLayoutConstraint.constraintPinBottomSubview(mfTextButton, bottomConstant: 0) + NSLayoutConstraint.constraintPinRightSubview(mfTextButton, rightConstant: 0) + if label.text?.isEmpty ?? false == false { + _ = NSLayoutConstraint(pinFirstView: mvmSwitch, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true) + } + } public func isValidField() -> Bool { - return (isRequired == false) ? true : aSwitch.isOn + return (isRequired == false) ? true : mvmSwitch.isOn } public func formFieldName() -> String? { @@ -106,7 +89,7 @@ public class Switch: ViewConstrainingView, FormValidationProtocol { } public func formFieldValue() -> Any? { - return aSwitch.isOn + return mvmSwitch.isOn } public override func needsToBeConstrained() -> Bool { From 9ecc7f21a6f10a25a250f9f65beb4bb9e8cb09ae Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 16 May 2019 11:54:57 -0400 Subject: [PATCH 18/47] switch modification --- MVMCoreUI/Molecules/Switch.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index b01ef73e..4f87c8a3 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -13,11 +13,9 @@ import UIKit var label = Label() var mfTextButton = MFTextButton() var isRequired: Bool! = false - var delegateObject: DelegateObject? - - @objc func switchChanged() { +@objc func switchChanged() { let delegate = delegateObject as? MVMCoreUIDelegateObject if let delegate = delegate { let formValidator = delegate.formValidationProtocol?.formValidatorModel?() From 85e9c56dcf6a442863ff020a7b8bcbc4c8eec3c8 Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 16 May 2019 15:05:05 -0400 Subject: [PATCH 19/47] switch modification --- MVMCoreUI/Molecules/Switch.swift | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index 4f87c8a3..658a375c 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -9,7 +9,7 @@ import UIKit @objcMembers public class Switch: ViewConstrainingView, FormValidationProtocol{ - public var mvmSwitch = UISwitch() + public var mvmSwitch = MVMCoreUISwitch() var label = Label() var mfTextButton = MFTextButton() var isRequired: Bool! = false @@ -38,6 +38,7 @@ import UIKit public override func updateView(_ size: CGFloat) { super.updateView(size) label.updateView(size) + mvmSwitch.updateView(size) mfTextButton.updateView(size) } @@ -48,19 +49,26 @@ import UIKit if let dict = json?.optionalDictionaryForKey("label") { label.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData) } - if let dict = json?.optionalDictionaryForKey("textButton") { mfTextButton.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData) } - if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol) } - if let onColorString = json?.optionalStringForKey("onTintColor") { mvmSwitch.onTintColor = .mfGet(forHex: onColorString) } - mvmSwitch.isOn = json?.optionalBoolForKey("state") ?? false + if let offColorString = json?.optionalStringForKey("offTintColor") { + mvmSwitch.offTintColor = .mfGet(forHex: offColorString) + } + if let onKnobColorString = json?.optionalStringForKey("onKnobTintColor") { + mvmSwitch.onKnobTintColor = .mfGet(forHex: onKnobColorString) + } + if let offKnobColorString = json?.optionalStringForKey("offKnobTintColor") { + mvmSwitch.offKnobTintColor = .mfGet(forHex: offKnobColorString) + } +// mvmSwitch.isOn = json?.optionalBoolForKey("state") ?? false + mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true) } func setupConstraints(forView view: UIView) { From 91890011d873756b8a1342a2c321fb0112a71ed0 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 16 May 2019 16:44:52 -0400 Subject: [PATCH 20/47] Panel protocol for override panel --- MVMCoreUI/BaseControllers/MFViewController.m | 1 + .../MVMCoreUIDetailViewProtocol.h | 6 + .../MVMCoreUIPanelProtocol.h | 8 +- .../MVMCoreUISplitViewController.h | 5 +- .../MVMCoreUISplitViewController.m | 178 ++++++++++++------ 5 files changed, 136 insertions(+), 62 deletions(-) diff --git a/MVMCoreUI/BaseControllers/MFViewController.m b/MVMCoreUI/BaseControllers/MFViewController.m index b6f71412..b9ce00de 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.m +++ b/MVMCoreUI/BaseControllers/MFViewController.m @@ -297,6 +297,7 @@ if (navigationController == [MVMCoreUISplitViewController mainSplitViewController].navigationController) { // Update icons if main navigation controller. + [[MVMCoreUISession sharedGlobal].splitViewController setupPanels]; [self setMasterShouldBeAccessible:self.masterShouldBeAccessible]; [self setSupportShouldBeAccessible:self.supportShouldBeAccessible]; [self showBottomProgressBar]; diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUIDetailViewProtocol.h b/MVMCoreUI/Containers/SplitViewController/MVMCoreUIDetailViewProtocol.h index acb56ad1..038769fb 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUIDetailViewProtocol.h +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUIDetailViewProtocol.h @@ -21,6 +21,12 @@ NS_ASSUME_NONNULL_BEGIN - (void)panelWillDisappear:(nonnull NSObject *)panel; - (void)panelDidDisappear:(nonnull NSObject *)panel; +/// Can override the left panel. +- (nullable UIViewController *)overrideLeftPanel; + +/// Can override the right panel. +- (nullable UIViewController *)overrideRightPanel; + // Called when the back button is pressed. Overwrite for special functionality. - (void)backButtonPressed; diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUIPanelProtocol.h b/MVMCoreUI/Containers/SplitViewController/MVMCoreUIPanelProtocol.h index f90391d3..4537e791 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUIPanelProtocol.h +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUIPanelProtocol.h @@ -6,7 +6,7 @@ // Copyright © 2017 Verizon Wireless. All rights reserved. // -#import +#import @protocol MVMCoreUIPanelProtocol #pragma mark - life cycle @@ -33,6 +33,12 @@ - (void)showArrow; - (void)hideArrow; +/// The width to use if the panel is automatically extended when the screen is big enough. +- (CGFloat)panelExtendedWidth; + +/// The maximum width of the panel. +- (CGFloat)panelMaxWidth; + // Gets called when we are restarting or clearing a session. - (void)clearData; diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h index 0d4c9ea4..cf27dc78 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h @@ -80,6 +80,9 @@ typedef NS_ENUM(NSInteger, MFNumberOfDrawers) { // contains speicaly logic to set the icon color - (void)setNavigationIconColor:(nullable UIColor *)color; +/// Updates the panels that are used. +- (void)setupPanels; + #pragma mark - Bottom Progress Bar - (void)setBottomProgressBarProgress:(float)progress; @@ -114,7 +117,7 @@ typedef NS_ENUM(NSInteger, MFNumberOfDrawers) { // Can subclass to set threshold for when the drawers are permanently extended. Default is 1000 for the left panel and 2000 for both. - (MFNumberOfDrawers)numberOfDrawersShouldShow:(nullable NSNumber *)forWidth; -// subclass to return panels +// subclass to return default global panels. kept alive after creation. - (nullable UIViewController *)createLeftPanelViewController; - (nullable UIViewController *)createRightPanelViewController; diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m index bdfd6ecd..73382510 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m @@ -27,6 +27,12 @@ @interface MVMCoreUISplitViewController () +typedef NS_OPTIONS(NSInteger, MFExtendedDrawer) { + MFExtendedDrawerNone = 0, + MFExtendedDrawerRight, + MFExtendedDrawerLeft +}; + @property (weak, nonatomic) UIView *leftView; @property (weak, nonatomic) UIView *mainView; @property (weak, nonatomic) UIView *rightView; @@ -38,6 +44,10 @@ @property (weak, nonatomic) UIView *leftPanelSeparator; @property (weak, nonatomic) UIView *rightPanelSeparator; +// For keeping +@property (strong, nonatomic, readwrite) UIViewController *globalLeftPanel; +@property (strong, nonatomic, readwrite) UIViewController *globalRightPanel; + @property (weak, nonatomic, readwrite) UIViewController *leftPanel; @property (weak, nonatomic, readwrite) UIViewController *rightPanel; @property (weak, nonatomic, readwrite) MVMCoreUINavigationController *navigationController; @@ -51,13 +61,7 @@ @property (nonatomic, strong) UIGestureRecognizer *tapToDismissGesture; @property (nullable, readwrite, weak, nonatomic) NSObject *explictlyShowingPanel; -@property (nullable, weak, nonatomic) NSObject *prioritizedExtendedPanel; - -typedef NS_OPTIONS(NSInteger, MFExtendedDrawer) { - MFExtendedDrawerNone = 0, - MFExtendedDrawerRight, - MFExtendedDrawerLeft -}; +@property (nonatomic) MFExtendedDrawer prioritizedExtendedPanel; @property (nonatomic) MFExtendedDrawer extendedDrawers; @property (nonatomic, readwrite) BOOL leftPanelIsAccessible; @@ -119,18 +123,30 @@ CGFloat const PanelAnimationDuration = 0.2; } - (CGFloat)leftPanelExtendedWidth { + if ([self.leftPanel respondsToSelector:@selector(panelExtendedWidth)]) { + return [self.leftPanel panelExtendedWidth]; + } return 320; } - (CGFloat)leftPanelMaxWidth { + if ([self.leftPanel respondsToSelector:@selector(panelMaxWidth)]) { + return [self.leftPanel panelMaxWidth]; + } return 415; } - (CGFloat)rightPanelExtendedWidth { + if ([self.rightPanel respondsToSelector:@selector(panelExtendedWidth)]) { + return [self.rightPanel panelExtendedWidth]; + } return 320; } - (CGFloat)rightPanelMaxWidth { + if ([self.rightPanel respondsToSelector:@selector(panelMaxWidth)]) { + return [self.rightPanel panelMaxWidth]; + } return 500; } @@ -217,7 +233,7 @@ CGFloat const PanelAnimationDuration = 0.2; return NO; } else { // left is extended if the right panel isn't prioritized. - return self.prioritizedExtendedPanel != self.rightPanel; + return self.prioritizedExtendedPanel != MFExtendedDrawerRight; } } } @@ -420,7 +436,7 @@ CGFloat const PanelAnimationDuration = 0.2; return NO; } else { // Extend right if the left panel isn't prioritized. - return self.prioritizedExtendedPanel != self.leftPanel; + return self.prioritizedExtendedPanel != MFExtendedDrawerLeft; } } } @@ -656,6 +672,94 @@ CGFloat const PanelAnimationDuration = 0.2; } } +- (void)addPanel:(nonnull UIViewController *)panel { + UIView *view = panel.view; + [self addChildViewController:panel]; + [self.view addSubview:view]; + [panel didMoveToParentViewController:self]; +} + +- (void)removePanel:(nullable UIViewController *)panel { + [panel willMoveToParentViewController:nil]; + [panel.view removeFromSuperview]; + [panel removeFromParentViewController]; +} + +- (void)setupLeftPanel { + UIViewController *panel = nil; + UIViewController *currentViewController = [self getCurrentDetailViewController]; + if ([currentViewController respondsToSelector:@selector(overrideLeftPanel)]) { + panel = [((UIViewController *)currentViewController) overrideLeftPanel]; + } else { + panel = self.globalLeftPanel; + self.leftPanelButton = nil; + } + + if (!panel) { + [self removePanel:self.leftPanel]; + } else if (panel && panel != self.leftPanel) { + [self removePanel:self.leftPanel]; + [self addPanel:panel]; + self.leftView = panel.view; + self.leftPanel = panel; + NSLayoutConstraint *leftPanelWidth = [NSLayoutConstraint constraintWithItem:self.leftView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:270]; + leftPanelWidth.active = YES; + self.leftPanelWidth = leftPanelWidth; + [NSLayoutConstraint constraintWithItem:self.mainView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.leftView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0].active = YES; + [NSLayoutConstraint constraintWithItem:self.leftView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.mainView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0].active = YES; + [NSLayoutConstraint constraintWithItem:self.leftView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.mainView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0].active = YES; + + if ([panel respondsToSelector:@selector(buttonForPanel)]) { + self.leftPanelButton = [panel buttonForPanel]; + } else if ([panel respondsToSelector:@selector(imageForButtonForPanel)]) { + self.leftPanelButton = [[UIBarButtonItem alloc] initWithImage:[panel imageForButtonForPanel] style:UIBarButtonItemStylePlain target:self action:@selector(leftPanelButtonPressed:)]; + } else { + self.leftPanelButton = nil; + } + } +} + +- (void)setupRightPanel { + UIViewController *panel = nil; + UIViewController *currentViewController = [self getCurrentDetailViewController]; + if ([currentViewController respondsToSelector:@selector(overrideRightPanel)]) { + panel = [((UIViewController *)currentViewController) overrideRightPanel]; + } else { + panel = self.globalRightPanel; + } + + if (!panel) { + [self removePanel:self.rightPanel]; + self.rightPanelButton = nil; + } else if (panel && panel != self.rightPanel) { + [self removePanel:self.rightPanel]; + [self addPanel:panel]; + self.rightView = panel.view; + self.rightPanel = panel; + NSLayoutConstraint *rightPanelWidth = [NSLayoutConstraint constraintWithItem:self.rightView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:270]; + rightPanelWidth.active = YES; + self.rightPanelWidth = rightPanelWidth; + [NSLayoutConstraint constraintWithItem:self.rightView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.mainView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0].active = YES; + [NSLayoutConstraint constraintWithItem:self.rightView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.mainView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0].active = YES; + [NSLayoutConstraint constraintWithItem:self.rightView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.mainView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0].active = YES; + + if ([panel respondsToSelector:@selector(buttonForPanel)]) { + self.rightPanelButton = [panel buttonForPanel]; + } else if ([panel respondsToSelector:@selector(imageForButtonForPanel)]) { + self.rightPanelButton = [[UIBarButtonItem alloc] initWithImage:[panel imageForButtonForPanel] style:UIBarButtonItemStylePlain target:self action:@selector(rightPanelButtonPressed:)]; + } else { + self.rightPanelButton = nil; + } + } +} + +- (void)setupPanels { + [self setupLeftPanel]; + [self setupRightPanel]; + self.explictlyShowingPanel = nil; + [self.view layoutIfNeeded]; +} + #pragma mark - Bottom Progress Bar - (void)setBottomProgressBarProgress:(float)progress { @@ -744,62 +848,16 @@ CGFloat const PanelAnimationDuration = 0.2; [NSLayoutConstraint constraintWithItem:coverView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0].active = YES; [NSLayoutConstraint constraintWithItem:coverView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0].active = YES; - // Left Panel - UIViewController *leftPanel = [self createLeftPanelViewController]; - if (leftPanel) { - UIView *leftView = leftPanel.view; - [self addChildViewController:leftPanel]; - [self.view addSubview:leftView]; - [leftPanel didMoveToParentViewController:self]; - self.leftView = leftView; - self.leftPanel = leftPanel; - NSLayoutConstraint *leftPanelWidth = [NSLayoutConstraint constraintWithItem:leftView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:270]; - leftPanelWidth.active = YES; - self.leftPanelWidth = leftPanelWidth; - [NSLayoutConstraint constraintWithItem:mainView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:leftView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0].active = YES; - [NSLayoutConstraint constraintWithItem:leftView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0].active = YES; - [NSLayoutConstraint constraintWithItem:leftView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0].active = YES; - } - - // Right Panel - UIViewController *rightPanel = [self createRightPanelViewController]; - if (rightPanel) { - UIView *rightView = rightPanel.view; - [self addChildViewController:rightPanel]; - [self.view addSubview:rightView]; - [rightPanel didMoveToParentViewController:self]; - self.rightView = rightView; - self.rightPanel = rightPanel; - NSLayoutConstraint *rightPanelWidth = [NSLayoutConstraint constraintWithItem:rightView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:270]; - rightPanelWidth.active = YES; - self.rightPanelWidth = rightPanelWidth; - [NSLayoutConstraint constraintWithItem:rightView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0].active = YES; - [NSLayoutConstraint constraintWithItem:rightView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0].active = YES; - [NSLayoutConstraint constraintWithItem:rightView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0].active = YES; - } + // Create panels + self.globalLeftPanel = [self createLeftPanelViewController]; + self.globalRightPanel = [self createRightPanelViewController]; + [self setupPanels]; } - (void)viewDidLoad { [super viewDidLoad]; [self.topAlertView pinATopViewController:self]; - // Do any additional setup after loading the view. - if (self.leftPanel) { - if ([self.leftPanel respondsToSelector:@selector(buttonForPanel)]) { - self.leftPanelButton = [self.leftPanel buttonForPanel]; - } else { - self.leftPanelButton = [[UIBarButtonItem alloc] initWithImage:[self.leftPanel imageForButtonForPanel] style:UIBarButtonItemStylePlain target:self action:@selector(leftPanelButtonPressed:)]; - } - } - - if (self.rightPanel) { - if ([self.rightPanel respondsToSelector:@selector(buttonForPanel)]) { - self.rightPanelButton = [self.rightPanel buttonForPanel]; - } else { - self.rightPanelButton = [[UIBarButtonItem alloc] initWithImage:[self.rightPanel imageForButtonForPanel] style:UIBarButtonItemStylePlain target:self action:@selector(rightPanelButtonPressed:)]; - } - } - // Creates the back button self.backButton = [[UIBarButtonItem alloc] initWithImage:[self imageForBackButton] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonPressed:)]; self.backButton.imageInsets = UIEdgeInsetsMake(0, 4, 0, -8); @@ -811,7 +869,7 @@ CGFloat const PanelAnimationDuration = 0.2; } self.extendedDrawers = MFExtendedDrawerLeft | MFExtendedDrawerRight; - self.prioritizedExtendedPanel = self.leftPanel; + self.prioritizedExtendedPanel = MFExtendedDrawerLeft; self.view.backgroundColor = [UIColor blackColor]; } From d0a0957bb1585a7b08f835e7753421352ba2e021 Mon Sep 17 00:00:00 2001 From: "Chowdhury, Shohrab" Date: Fri, 17 May 2019 10:35:54 -0400 Subject: [PATCH 21/47] show left pannel --- .../SplitViewController/MVMCoreUISplitViewController.m | 1 + 1 file changed, 1 insertion(+) diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m index 73382510..d993a797 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m @@ -703,6 +703,7 @@ CGFloat const PanelAnimationDuration = 0.2; self.leftView = panel.view; self.leftPanel = panel; NSLayoutConstraint *leftPanelWidth = [NSLayoutConstraint constraintWithItem:self.leftView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:270]; + self.leftView.translatesAutoresizingMaskIntoConstraints = NO; leftPanelWidth.active = YES; self.leftPanelWidth = leftPanelWidth; [NSLayoutConstraint constraintWithItem:self.mainView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.leftView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0].active = YES; From c59be1b9a8ef912f3792dbd4dad723b467d28106 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 17 May 2019 10:37:32 -0400 Subject: [PATCH 22/47] menu fixing --- .../SplitViewController/MVMCoreUISplitViewController.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m index 73382510..2c6318e4 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m @@ -702,6 +702,7 @@ CGFloat const PanelAnimationDuration = 0.2; [self addPanel:panel]; self.leftView = panel.view; self.leftPanel = panel; + self.leftView.translatesAutoresizingMaskIntoConstraints = NO; NSLayoutConstraint *leftPanelWidth = [NSLayoutConstraint constraintWithItem:self.leftView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:270]; leftPanelWidth.active = YES; self.leftPanelWidth = leftPanelWidth; @@ -736,6 +737,7 @@ CGFloat const PanelAnimationDuration = 0.2; [self addPanel:panel]; self.rightView = panel.view; self.rightPanel = panel; + self.rightView.translatesAutoresizingMaskIntoConstraints = NO; NSLayoutConstraint *rightPanelWidth = [NSLayoutConstraint constraintWithItem:self.rightView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:270]; rightPanelWidth.active = YES; self.rightPanelWidth = rightPanelWidth; From 5e49d5c55d78a14b45a856b58e090fe406154875 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 17 May 2019 11:26:14 -0400 Subject: [PATCH 23/47] update for error to be called --- .../SplitViewController/MVMCoreUISplitViewController.m | 1 + 1 file changed, 1 insertion(+) diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m index 3e8cc6c3..af1e5c53 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m @@ -757,6 +757,7 @@ CGFloat const PanelAnimationDuration = 0.2; } - (void)setupPanels { + [self forceHideBothDrawers]; [self setupLeftPanel]; [self setupRightPanel]; self.explictlyShowingPanel = nil; From 281a10f7e1478f3b249da973c079f4d25e8140fd Mon Sep 17 00:00:00 2001 From: Priya Date: Fri, 17 May 2019 14:36:18 -0400 Subject: [PATCH 24/47] Switch molecule --- MVMCoreUI/Molecules/Switch.swift | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index 658a375c..f756e9d9 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -10,9 +10,11 @@ import UIKit @objcMembers public class Switch: ViewConstrainingView, FormValidationProtocol{ public var mvmSwitch = MVMCoreUISwitch() - var label = Label() - var mfTextButton = MFTextButton() - var isRequired: Bool! = false + public var label = Label() + public var mfTextButton = MFTextButton() + var topConstraint_Switch: NSLayoutConstraint? + var bottomConstraint_textBtn: NSLayoutConstraint? + var isRequired = false var delegateObject: DelegateObject? @objc func switchChanged() { @@ -44,7 +46,7 @@ import UIKit open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - isRequired = json?[KeyRequired] as? Bool + isRequired = json?[KeyRequired] as? Bool ?? false self.delegateObject = delegateObject if let dict = json?.optionalDictionaryForKey("label") { label.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData) @@ -67,19 +69,30 @@ import UIKit if let offKnobColorString = json?.optionalStringForKey("offKnobTintColor") { mvmSwitch.offKnobTintColor = .mfGet(forHex: offKnobColorString) } -// mvmSwitch.isOn = json?.optionalBoolForKey("state") ?? false + // mvmSwitch.isOn = json?.optionalBoolForKey("state") ?? false mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true) + //updateContraints() + } + + func updateContraints() { + if let isEmptyText = label.text?.isEmpty,isEmptyText == false{ + topConstraint_Switch?.priority = UILayoutPriority(rawValue:249) + NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinCenterX: false, pinCenterY: true) + } + layoutIfNeeded() } func setupConstraints(forView view: UIView) { NSLayoutConstraint.constraintPinLeftSubview(label, leftConstant: 0) - NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinTop: true, topConstant: 0, topRelation: .equal, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: true, rightConstant: 0, rightRelation: .equal) + let dict = NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinTop: true, topConstant: 0, topRelation: .greaterThanOrEqual, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: true, rightConstant: 0, rightRelation: .equal) + topConstraint_Switch = dict?[ConstraintTop] as? NSLayoutConstraint NSLayoutConstraint.constraintPinTopSubview(label, topConstant: 0) _ = NSLayoutConstraint(pinFirstView: label, toSecondView: mvmSwitch, withConstant: PaddingOne, directionVertical: false) _ = NSLayoutConstraint(pinFirstView: label, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true) NSLayoutConstraint.constraintPinLeftSubview(mfTextButton, leftConstant: 0) NSLayoutConstraint.constraintPinBottomSubview(mfTextButton, bottomConstant: 0) - NSLayoutConstraint.constraintPinRightSubview(mfTextButton, rightConstant: 0) + // NSLayoutConstraint.constraintPinRightSubview(mfTextButton, rightConstant: 0) + if label.text?.isEmpty ?? false == false { _ = NSLayoutConstraint(pinFirstView: mvmSwitch, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true) } @@ -108,3 +121,4 @@ import UIKit } + From aac9db9ca5894efacb8018dd88d0564c29a252e2 Mon Sep 17 00:00:00 2001 From: Priya Date: Fri, 17 May 2019 15:22:12 -0400 Subject: [PATCH 25/47] Switch molecule --- MVMCoreUI/Molecules/Switch.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index f756e9d9..fee44c09 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -17,7 +17,7 @@ import UIKit var isRequired = false var delegateObject: DelegateObject? -@objc func switchChanged() { + @objc func switchChanged() { let delegate = delegateObject as? MVMCoreUIDelegateObject if let delegate = delegate { let formValidator = delegate.formValidationProtocol?.formValidatorModel?() From e92bc6abf9c5487afb10af60186d7f0fad67cdee Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 20 May 2019 09:30:31 -0400 Subject: [PATCH 26/47] Smooths out animation into 5g --- MVMCoreUI/BaseControllers/MFViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/BaseControllers/MFViewController.m b/MVMCoreUI/BaseControllers/MFViewController.m index b9ce00de..444dcf8f 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.m +++ b/MVMCoreUI/BaseControllers/MFViewController.m @@ -279,7 +279,7 @@ - (void)updateNavigationBarUI:(nonnull UINavigationController *)navigationController { if (navigationController) { - [navigationController setNavigationBarHidden:[self navigationBarHidden] animated:NO]; + [navigationController setNavigationBarHidden:[self navigationBarHidden] animated:YES]; [UIColor mfSetBackgroundColorForNavigationBar:[self navigationBarColor] navigationBar:navigationController.navigationBar transparent:[self navigationBarTransparent]]; From ddd8eb9d453a5eb8d443835a91687c1a02d58f3e Mon Sep 17 00:00:00 2001 From: Priya Date: Mon, 20 May 2019 09:35:35 -0400 Subject: [PATCH 27/47] Switch molecule --- MVMCoreUI/Molecules/Switch.swift | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index fee44c09..1c58d5e5 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -17,14 +17,14 @@ import UIKit var isRequired = false var delegateObject: DelegateObject? - @objc func switchChanged() { + @objc func switchChanged() { let delegate = delegateObject as? MVMCoreUIDelegateObject if let delegate = delegate { let formValidator = delegate.formValidationProtocol?.formValidatorModel?() formValidator?.enableByValidation() } } - + open override func setupView() { super.setupView() mvmSwitch.addTarget(self, action: #selector(Switch.switchChanged), for: .valueChanged) @@ -34,7 +34,7 @@ import UIKit // label.translatesAutoresizingMaskIntoConstraints = false mvmSwitch.translatesAutoresizingMaskIntoConstraints = false mfTextButton.translatesAutoresizingMaskIntoConstraints = false; - setupConstraints(forView: self) + setupConstraints() } public override func updateView(_ size: CGFloat) { @@ -54,7 +54,7 @@ import UIKit if let dict = json?.optionalDictionaryForKey("textButton") { mfTextButton.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData) } - if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { + if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol) } if let onColorString = json?.optionalStringForKey("onTintColor") { @@ -71,32 +71,27 @@ import UIKit } // mvmSwitch.isOn = json?.optionalBoolForKey("state") ?? false mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true) - //updateContraints() + updateContraints() } func updateContraints() { - if let isEmptyText = label.text?.isEmpty,isEmptyText == false{ + if let isEmptyText = label.text?.isEmpty,isEmptyText == false { topConstraint_Switch?.priority = UILayoutPriority(rawValue:249) NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinCenterX: false, pinCenterY: true) + _ = NSLayoutConstraint(pinFirstView: mvmSwitch, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true) } layoutIfNeeded() } - func setupConstraints(forView view: UIView) { + func setupConstraints() { NSLayoutConstraint.constraintPinLeftSubview(label, leftConstant: 0) - let dict = NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinTop: true, topConstant: 0, topRelation: .greaterThanOrEqual, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: true, rightConstant: 0, rightRelation: .equal) + let dict = NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinTop: true, topConstant: 0, topRelation: .greaterThanOrEqual, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: true, rightConstant: 0, rightRelation: .greaterThanOrEqual) topConstraint_Switch = dict?[ConstraintTop] as? NSLayoutConstraint NSLayoutConstraint.constraintPinTopSubview(label, topConstant: 0) _ = NSLayoutConstraint(pinFirstView: label, toSecondView: mvmSwitch, withConstant: PaddingOne, directionVertical: false) _ = NSLayoutConstraint(pinFirstView: label, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true) NSLayoutConstraint.constraintPinLeftSubview(mfTextButton, leftConstant: 0) NSLayoutConstraint.constraintPinBottomSubview(mfTextButton, bottomConstant: 0) - // NSLayoutConstraint.constraintPinRightSubview(mfTextButton, rightConstant: 0) - - if label.text?.isEmpty ?? false == false { - _ = NSLayoutConstraint(pinFirstView: mvmSwitch, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true) - } - } public func isValidField() -> Bool { From 9f5600a0f30cd47834351afdc371ae2b5e516205 Mon Sep 17 00:00:00 2001 From: Priya Date: Mon, 20 May 2019 15:51:07 -0400 Subject: [PATCH 28/47] switch modification --- MVMCoreUI/Molecules/Switch.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index 1c58d5e5..4f410366 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -84,7 +84,8 @@ import UIKit } func setupConstraints() { - NSLayoutConstraint.constraintPinLeftSubview(label, leftConstant: 0) + NSLayoutConstraint.constraintPinLeftSubview(label, leftConstant: 0) + NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinCenterX: false, pinCenterY: true) let dict = NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinTop: true, topConstant: 0, topRelation: .greaterThanOrEqual, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: true, rightConstant: 0, rightRelation: .greaterThanOrEqual) topConstraint_Switch = dict?[ConstraintTop] as? NSLayoutConstraint NSLayoutConstraint.constraintPinTopSubview(label, topConstant: 0) From 9fd2d2cbda0ab1928e4ae4efee3ba9077fd0a774 Mon Sep 17 00:00:00 2001 From: Priya Date: Tue, 21 May 2019 14:04:46 -0400 Subject: [PATCH 29/47] Switch molecule --- MVMCoreUI/Molecules/Switch.swift | 55 ++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index 4f410366..2c4fe19a 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -11,6 +11,7 @@ import UIKit @objcMembers public class Switch: ViewConstrainingView, FormValidationProtocol{ public var mvmSwitch = MVMCoreUISwitch() public var label = Label() + public var leftContainerView = UIView() public var mfTextButton = MFTextButton() var topConstraint_Switch: NSLayoutConstraint? var bottomConstraint_textBtn: NSLayoutConstraint? @@ -28,9 +29,11 @@ import UIKit open override func setupView() { super.setupView() mvmSwitch.addTarget(self, action: #selector(Switch.switchChanged), for: .valueChanged) + //leftContainerView.addSubview(mvmSwitch) + leftContainerView.addSubview(label) + leftContainerView.addSubview(mfTextButton) + addSubview(leftContainerView) addSubview(mvmSwitch) - addSubview(label) - addSubview(mfTextButton) // label.translatesAutoresizingMaskIntoConstraints = false mvmSwitch.translatesAutoresizingMaskIntoConstraints = false mfTextButton.translatesAutoresizingMaskIntoConstraints = false; @@ -71,28 +74,40 @@ import UIKit } // mvmSwitch.isOn = json?.optionalBoolForKey("state") ?? false mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true) - updateContraints() - } - - func updateContraints() { - if let isEmptyText = label.text?.isEmpty,isEmptyText == false { - topConstraint_Switch?.priority = UILayoutPriority(rawValue:249) - NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinCenterX: false, pinCenterY: true) - _ = NSLayoutConstraint(pinFirstView: mvmSwitch, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true) - } - layoutIfNeeded() +// updateContraints(json?.optionalDictionaryForKey("textButton")) + leftContainerView.backgroundColor = .red } func setupConstraints() { - NSLayoutConstraint.constraintPinLeftSubview(label, leftConstant: 0) - NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinCenterX: false, pinCenterY: true) - let dict = NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinTop: true, topConstant: 0, topRelation: .greaterThanOrEqual, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: true, rightConstant: 0, rightRelation: .greaterThanOrEqual) - topConstraint_Switch = dict?[ConstraintTop] as? NSLayoutConstraint + var constraint = label.topAnchor.constraint(equalTo: topAnchor) + constraint.priority = UILayoutPriority(rawValue: 249) + constraint.isActive = true + label.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true + label.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true + NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinCenterX: false, pinCenterY: true) + let _ = NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinTop: true, topConstant: 0, topRelation: .greaterThanOrEqual, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: true, rightConstant: 0, rightRelation: .equal) + // NSLayoutConstraint.constraintPinRightSubview(mvmSwitch, rightConstant: 0) + constraint = mvmSwitch.topAnchor.constraint(equalTo: topAnchor) + constraint.priority = UILayoutPriority(rawValue: 249) + constraint.isActive = true + constraint = bottomAnchor.constraint(equalTo: mvmSwitch.bottomAnchor) + constraint.priority = UILayoutPriority(rawValue: 249) + constraint.isActive = true + //topConstraint_Switch = dict?[ConstraintTop] as? NSLayoutConstraint NSLayoutConstraint.constraintPinTopSubview(label, topConstant: 0) - _ = NSLayoutConstraint(pinFirstView: label, toSecondView: mvmSwitch, withConstant: PaddingOne, directionVertical: false) - _ = NSLayoutConstraint(pinFirstView: label, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true) - NSLayoutConstraint.constraintPinLeftSubview(mfTextButton, leftConstant: 0) - NSLayoutConstraint.constraintPinBottomSubview(mfTextButton, bottomConstant: 0) + +// mvmSwitch.setContentHuggingPriority(UILayoutPriority(rawValue: 800), for: NSLayoutConstraint.Axis.horizontal) + + mvmSwitch.leadingAnchor.constraint(greaterThanOrEqualTo: label.trailingAnchor).isActive = true + mvmSwitch.leadingAnchor.constraint(greaterThanOrEqualTo: mfTextButton.trailingAnchor).isActive = true + NSLayoutConstraint.constraintPinLeftSubview(mfTextButton, leftConstant: 0) + constraint = bottomAnchor.constraint(equalTo: mfTextButton.bottomAnchor) + constraint.priority = UILayoutPriority(249) + constraint.isActive = true + bottomAnchor.constraint(greaterThanOrEqualTo: mfTextButton.bottomAnchor).isActive = true + label.bottomAnchor.constraint(equalTo: mfTextButton.topAnchor, constant: 0).isActive = true + leftContainerView.setContentHuggingPriority(UILayoutPriority(rawValue: 900), for: NSLayoutConstraint.Axis.horizontal) + } public func isValidField() -> Bool { From 89b1c9a21b26cc194978ed0ada5c45020720eece Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 23 May 2019 11:40:21 -0400 Subject: [PATCH 30/47] Switch molecule --- MVMCoreUI.xcodeproj/project.pbxproj | 18 +-- MVMCoreUI/Atoms/Buttons/MFTextButton.m | 6 + .../{Switch.swift => SwitchLineItem.swift} | 107 +++++++++++------- 3 files changed, 79 insertions(+), 52 deletions(-) rename MVMCoreUI/Molecules/{Switch.swift => SwitchLineItem.swift} (52%) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 45a09419..ec95f4d8 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -10,7 +10,7 @@ 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 */; }; - 016A1071228122180009D605 /* Switch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016A1070228122180009D605 /* Switch.swift */; }; + 016A1071228122180009D605 /* SwitchLineItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016A1070228122180009D605 /* SwitchLineItem.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 */; }; @@ -171,7 +171,7 @@ 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 = ""; }; - 016A1070228122180009D605 /* Switch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Switch.swift; sourceTree = ""; }; + 016A1070228122180009D605 /* SwitchLineItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwitchLineItem.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 = ""; }; @@ -444,7 +444,7 @@ D29770C721F7C4AE00B2F0D0 /* TopLabelsView.h */, D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */, D282AACA2243C61700C46919 /* ButtonView.swift */, - 016A1070228122180009D605 /* Switch.swift */, + 016A1070228122180009D605 /* SwitchLineItem.swift */, D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */, D2A514662213885800345BFB /* StandardHeaderView.swift */, D2A5145C2211D22A00345BFB /* MVMCoreUIMoleculeViewProtocol.h */, @@ -920,7 +920,7 @@ D2A5146B2214905000345BFB /* ThreeLayerViewController.swift in Sources */, D29DF2C921E7BFC6003B2FB9 /* MFSizeObject.m in Sources */, D29DF2C721E7BF57003B2FB9 /* MFTabBarInteractor.m in Sources */, - 016A1071228122180009D605 /* Switch.swift in Sources */, + 016A1071228122180009D605 /* SwitchLineItem.swift in Sources */, D29DF29521E7ADB8003B2FB9 /* ProgrammaticScrollViewController.m in Sources */, D29DF16121E69996003B2FB9 /* MFViewController.m in Sources */, D2E1FAE12268E81D00AEFD8C /* MoleculeListTemplate.swift in Sources */, @@ -1102,9 +1102,9 @@ BITCODE_GENERATION_MODE = bitcode; CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = ""; - CODE_SIGN_STYLE = Automatic; + CODE_SIGN_STYLE = Manual; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = FCMA4QKS77; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -1119,6 +1119,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.vzw.MVMCoreUI; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; @@ -1132,9 +1133,9 @@ BITCODE_GENERATION_MODE = bitcode; CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = ""; - CODE_SIGN_STYLE = Automatic; + CODE_SIGN_STYLE = Manual; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = FCMA4QKS77; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -1149,6 +1150,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.vzw.MVMCoreUI; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; diff --git a/MVMCoreUI/Atoms/Buttons/MFTextButton.m b/MVMCoreUI/Atoms/Buttons/MFTextButton.m index d78df33d..aa176923 100644 --- a/MVMCoreUI/Atoms/Buttons/MFTextButton.m +++ b/MVMCoreUI/Atoms/Buttons/MFTextButton.m @@ -18,6 +18,9 @@ @interface MFTextButton () + +@property (nullable, nonatomic, strong) NSLayoutConstraint *widthConstraint; + @end @implementation MFTextButton @@ -122,6 +125,7 @@ } else { [theButton setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical]; } + theButton.widthConstraint = [theButton.widthAnchor constraintEqualToConstant:0]; [theButton updateView:width]; return theButton; } @@ -136,8 +140,10 @@ [self setWithActionMap:json delegateObject:delegateObject additionalData:additionalData]; if ([self titleForState:UIControlStateNormal].length == 0) { self.heightConstraint.constant = 0; + self.widthConstraint.active = YES; } else { self.heightConstraint.constant = self.sizeObject.standardSize; + self.widthConstraint.active = NO; } } diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/SwitchLineItem.swift similarity index 52% rename from MVMCoreUI/Molecules/Switch.swift rename to MVMCoreUI/Molecules/SwitchLineItem.swift index 2c4fe19a..cc4d076f 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/SwitchLineItem.swift @@ -1,5 +1,5 @@ // -// Switch.swift +// SwitchLineItem.swift // MVMCoreUI // // Created by Priya on 5/6/19. @@ -12,9 +12,7 @@ import UIKit public var mvmSwitch = MVMCoreUISwitch() public var label = Label() public var leftContainerView = UIView() - public var mfTextButton = MFTextButton() - var topConstraint_Switch: NSLayoutConstraint? - var bottomConstraint_textBtn: NSLayoutConstraint? + public var mfTextButton = MFTextButton(nil, constrainHeight: true, forWidth: 0) var isRequired = false var delegateObject: DelegateObject? @@ -29,15 +27,16 @@ import UIKit open override func setupView() { super.setupView() mvmSwitch.addTarget(self, action: #selector(Switch.switchChanged), for: .valueChanged) - //leftContainerView.addSubview(mvmSwitch) leftContainerView.addSubview(label) leftContainerView.addSubview(mfTextButton) addSubview(leftContainerView) addSubview(mvmSwitch) - // label.translatesAutoresizingMaskIntoConstraints = false + + leftContainerView.translatesAutoresizingMaskIntoConstraints = false mvmSwitch.translatesAutoresizingMaskIntoConstraints = false - mfTextButton.translatesAutoresizingMaskIntoConstraints = false; - setupConstraints() + mfTextButton.translatesAutoresizingMaskIntoConstraints = false + label.translatesAutoresizingMaskIntoConstraints = false + setupContainerConstraints() } public override func updateView(_ size: CGFloat) { @@ -51,12 +50,8 @@ import UIKit super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) isRequired = json?[KeyRequired] as? Bool ?? false self.delegateObject = delegateObject - if let dict = json?.optionalDictionaryForKey("label") { - label.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData) - } - if let dict = json?.optionalDictionaryForKey("textButton") { - mfTextButton.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData) - } + label.setWithJSON(json?.optionalDictionaryForKey("label"), delegateObject: delegateObject, additionalData: additionalData) + mfTextButton.setWithJSON(json?.optionalDictionaryForKey("textButton"), delegateObject: delegateObject, additionalData: additionalData) if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol) } @@ -72,42 +67,66 @@ import UIKit if let offKnobColorString = json?.optionalStringForKey("offKnobTintColor") { mvmSwitch.offKnobTintColor = .mfGet(forHex: offKnobColorString) } - // mvmSwitch.isOn = json?.optionalBoolForKey("state") ?? false mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true) -// updateContraints(json?.optionalDictionaryForKey("textButton")) - leftContainerView.backgroundColor = .red + // if left container no width + if (label.text?.count ?? 0) <= 0 && (mfTextButton.titleLabel?.text?.count ?? 0) <= 0 { + mvmSwitch.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 0).isActive = true + } } - - func setupConstraints() { - var constraint = label.topAnchor.constraint(equalTo: topAnchor) - constraint.priority = UILayoutPriority(rawValue: 249) - constraint.isActive = true - label.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true - label.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true - NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinCenterX: false, pinCenterY: true) - let _ = NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinTop: true, topConstant: 0, topRelation: .greaterThanOrEqual, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: true, rightConstant: 0, rightRelation: .equal) - // NSLayoutConstraint.constraintPinRightSubview(mvmSwitch, rightConstant: 0) - constraint = mvmSwitch.topAnchor.constraint(equalTo: topAnchor) - constraint.priority = UILayoutPriority(rawValue: 249) - constraint.isActive = true - constraint = bottomAnchor.constraint(equalTo: mvmSwitch.bottomAnchor) - constraint.priority = UILayoutPriority(rawValue: 249) - constraint.isActive = true - //topConstraint_Switch = dict?[ConstraintTop] as? NSLayoutConstraint - NSLayoutConstraint.constraintPinTopSubview(label, topConstant: 0) + + func setupContainerConstraints() { + leftContainerView.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true -// mvmSwitch.setContentHuggingPriority(UILayoutPriority(rawValue: 800), for: NSLayoutConstraint.Axis.horizontal) - - mvmSwitch.leadingAnchor.constraint(greaterThanOrEqualTo: label.trailingAnchor).isActive = true - mvmSwitch.leadingAnchor.constraint(greaterThanOrEqualTo: mfTextButton.trailingAnchor).isActive = true - NSLayoutConstraint.constraintPinLeftSubview(mfTextButton, leftConstant: 0) - constraint = bottomAnchor.constraint(equalTo: mfTextButton.bottomAnchor) + var constraint = leftContainerView.topAnchor.constraint(equalTo: topAnchor) constraint.priority = UILayoutPriority(249) constraint.isActive = true - bottomAnchor.constraint(greaterThanOrEqualTo: mfTextButton.bottomAnchor).isActive = true - label.bottomAnchor.constraint(equalTo: mfTextButton.topAnchor, constant: 0).isActive = true - leftContainerView.setContentHuggingPriority(UILayoutPriority(rawValue: 900), for: NSLayoutConstraint.Axis.horizontal) + + mvmSwitch.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true + + constraint = mvmSwitch.topAnchor.constraint(equalTo: topAnchor) + constraint.priority = UILayoutPriority(249) + constraint.isActive = true + + trailingAnchor.constraint(equalTo: mvmSwitch.trailingAnchor).isActive = true + + constraint = bottomAnchor.constraint(equalTo: mvmSwitch.bottomAnchor) + constraint.priority = UILayoutPriority(249) + constraint.isActive = true + + bottomAnchor.constraint(greaterThanOrEqualTo: mvmSwitch.bottomAnchor).isActive = true + constraint = bottomAnchor.constraint(equalTo: leftContainerView.bottomAnchor) + constraint.isActive = true + + bottomAnchor.constraint(greaterThanOrEqualTo: leftContainerView.bottomAnchor).isActive = true + leftContainerView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true + + NSLayoutConstraint.constraintPinSubview(leftContainerView, pinCenterX: false, pinCenterY: true) + constraint = mvmSwitch.leadingAnchor.constraint(greaterThanOrEqualTo: leftContainerView.trailingAnchor) + constraint.priority = UILayoutPriority(999) + constraint.isActive = true + NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinCenterX: false, pinCenterY: true) + + leftContainerView.topAnchor.constraint(equalTo: label.topAnchor).isActive = true + leftContainerView.trailingAnchor.constraint(greaterThanOrEqualTo: label.trailingAnchor).isActive = true + + constraint = leftContainerView.trailingAnchor.constraint(equalTo: label.trailingAnchor) + constraint.priority = UILayoutPriority(249) + constraint.isActive = true + + leftContainerView.trailingAnchor.constraint(greaterThanOrEqualTo: mfTextButton.trailingAnchor).isActive = true + + constraint = leftContainerView.trailingAnchor.constraint(equalTo: mfTextButton.trailingAnchor) + constraint.priority = UILayoutPriority(249) + constraint.isActive = true + + leftContainerView.bottomAnchor.constraint(equalTo: mfTextButton.bottomAnchor).isActive = true + mfTextButton.leadingAnchor.constraint(equalTo: leftContainerView.leadingAnchor).isActive = true + label.leadingAnchor.constraint(equalTo: leftContainerView.leadingAnchor).isActive = true + mfTextButton.topAnchor.constraint(equalTo: label.bottomAnchor).isActive = true + leftContainerView.setContentHuggingPriority(.defaultHigh, for: .horizontal) + mvmSwitch.setContentHuggingPriority(.defaultLow, for: .horizontal) + } public func isValidField() -> Bool { From 2e99c7baff9fd43f15cda3ef09f93f1bd402adb6 Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 23 May 2019 12:31:36 -0400 Subject: [PATCH 31/47] Switch molecule --- MVMCoreUI.xcodeproj/project.pbxproj | 8 ++++---- MVMCoreUI/Atoms/Buttons/MFTextButton.m | 6 ------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index ec95f4d8..3d7bdc49 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -1101,8 +1101,8 @@ buildSettings = { BITCODE_GENERATION_MODE = bitcode; CLANG_ENABLE_MODULES = YES; - CODE_SIGN_IDENTITY = ""; - CODE_SIGN_STYLE = Manual; + CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_STYLE = Automatic; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; @@ -1132,8 +1132,8 @@ buildSettings = { BITCODE_GENERATION_MODE = bitcode; CLANG_ENABLE_MODULES = YES; - CODE_SIGN_IDENTITY = ""; - CODE_SIGN_STYLE = Manual; + CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_STYLE = Automatic; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; diff --git a/MVMCoreUI/Atoms/Buttons/MFTextButton.m b/MVMCoreUI/Atoms/Buttons/MFTextButton.m index aa176923..d78df33d 100644 --- a/MVMCoreUI/Atoms/Buttons/MFTextButton.m +++ b/MVMCoreUI/Atoms/Buttons/MFTextButton.m @@ -18,9 +18,6 @@ @interface MFTextButton () - -@property (nullable, nonatomic, strong) NSLayoutConstraint *widthConstraint; - @end @implementation MFTextButton @@ -125,7 +122,6 @@ } else { [theButton setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical]; } - theButton.widthConstraint = [theButton.widthAnchor constraintEqualToConstant:0]; [theButton updateView:width]; return theButton; } @@ -140,10 +136,8 @@ [self setWithActionMap:json delegateObject:delegateObject additionalData:additionalData]; if ([self titleForState:UIControlStateNormal].length == 0) { self.heightConstraint.constant = 0; - self.widthConstraint.active = YES; } else { self.heightConstraint.constant = self.sizeObject.standardSize; - self.widthConstraint.active = NO; } } From 344163de4965e8912754f6de65307a126cb49e6b Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 23 May 2019 16:22:32 -0400 Subject: [PATCH 32/47] Switch molecule --- MVMCoreUI.xcodeproj/project.pbxproj | 14 +-- MVMCoreUI/Molecules/Switch.swift | 87 +++++++++++++++++++ MVMCoreUI/Molecules/SwitchLineItem.swift | 53 +++++------ .../MVMCoreUIMoleculeMappingObject.m | 1 + 4 files changed, 123 insertions(+), 32 deletions(-) create mode 100644 MVMCoreUI/Molecules/Switch.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 3d7bdc49..bed0e280 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ 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 */; }; + 01CA51B5229716F60071A6EE /* Switch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01CA51B4229716F60071A6EE /* Switch.swift */; }; 01DF55E021F8FAA800CC099B /* MFTextFieldListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */; }; 01DF567021FA5AB300CC099B /* TextFieldListFormViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */; }; 01E569D3223FFFA500327251 /* ThreeLayerViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = D2A5146A2214905000345BFB /* ThreeLayerViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -175,6 +176,7 @@ 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 = ""; }; + 01CA51B4229716F60071A6EE /* Switch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Switch.swift; sourceTree = ""; }; 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MFTextFieldListView.swift; sourceTree = ""; }; 01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextFieldListFormViewController.swift; sourceTree = ""; }; D206997521FB8A0B00CAE0DE /* MVMCoreUINavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUINavigationController.h; sourceTree = ""; }; @@ -445,6 +447,7 @@ D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */, D282AACA2243C61700C46919 /* ButtonView.swift */, 016A1070228122180009D605 /* SwitchLineItem.swift */, + 01CA51B4229716F60071A6EE /* Switch.swift */, D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */, D2A514662213885800345BFB /* StandardHeaderView.swift */, D2A5145C2211D22A00345BFB /* MVMCoreUIMoleculeViewProtocol.h */, @@ -940,6 +943,7 @@ D29770FC21F7C77400B2F0D0 /* MVMCoreUITextFieldView.m in Sources */, D29DF25121E6A177003B2FB9 /* MFDigitTextBox.m in Sources */, DBC4391B224421A0001AB423 /* CaretButton.swift in Sources */, + 01CA51B5229716F60071A6EE /* Switch.swift in Sources */, 0198F7A82256A80B0066C936 /* MFRadioButton.m in Sources */, D29DF13221E6851E003B2FB9 /* MVMCoreUITopAlertBaseView.m in Sources */, D29DF29C21E7ADB9003B2FB9 /* MFProgrammaticTableViewController.m in Sources */, @@ -1101,10 +1105,10 @@ buildSettings = { BITCODE_GENERATION_MODE = bitcode; CLANG_ENABLE_MODULES = YES; - CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_IDENTITY = ""; CODE_SIGN_STYLE = Automatic; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = FCMA4QKS77; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -1119,7 +1123,6 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.vzw.MVMCoreUI; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; @@ -1132,10 +1135,10 @@ buildSettings = { BITCODE_GENERATION_MODE = bitcode; CLANG_ENABLE_MODULES = YES; - CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_IDENTITY = ""; CODE_SIGN_STYLE = Automatic; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = FCMA4QKS77; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -1150,7 +1153,6 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.vzw.MVMCoreUI; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift new file mode 100644 index 00000000..81818ee3 --- /dev/null +++ b/MVMCoreUI/Molecules/Switch.swift @@ -0,0 +1,87 @@ +// +// Switch.swift +// MVMCoreUI +// +// Created by Priya on 5/23/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers public class Switch: ViewConstrainingView, FormValidationProtocol{ + public var mvmSwitch = MVMCoreUISwitch() + var isRequired = false + var delegateObject: DelegateObject? + + @objc func switchChanged() { + let delegate = delegateObject as? MVMCoreUIDelegateObject + if let delegate = delegate { + let formValidator = delegate.formValidationProtocol?.formValidatorModel?() + formValidator?.enableByValidation() + } + } + + open override func setupView() { + super.setupView() + mvmSwitch.addTarget(self, action: #selector(Switch.switchChanged), for: .valueChanged) + self.clipsToBounds = true + addSubview(mvmSwitch) + mvmSwitch.translatesAutoresizingMaskIntoConstraints = false + setupContainerConstraints() + } + + public override func updateView(_ size: CGFloat) { + super.updateView(size) + mvmSwitch.updateView(size) + } + + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + isRequired = json?[KeyRequired] as? Bool ?? false + self.delegateObject = delegateObject + if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { + FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol) + } + if let onColorString = json?.optionalStringForKey("onTintColor") { + mvmSwitch.onTintColor = .mfGet(forHex: onColorString) + } + if let offColorString = json?.optionalStringForKey("offTintColor") { + mvmSwitch.offTintColor = .mfGet(forHex: offColorString) + } + if let onKnobColorString = json?.optionalStringForKey("onKnobTintColor") { + mvmSwitch.onKnobTintColor = .mfGet(forHex: onKnobColorString) + } + if let offKnobColorString = json?.optionalStringForKey("offKnobTintColor") { + mvmSwitch.offKnobTintColor = .mfGet(forHex: offKnobColorString) + } + mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true) + } + + func setupContainerConstraints() { + mvmSwitch.topAnchor.constraint(equalTo: topAnchor).isActive = true + mvmSwitch.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true + mvmSwitch.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true + mvmSwitch.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true + } + + public func isValidField() -> Bool { + return (isRequired == false) ? true : mvmSwitch.isOn + } + + public func formFieldName() -> String? { + return json?.optionalStringForKey(KeyFieldKey) + } + + public func formFieldValue() -> Any? { + return mvmSwitch.isOn + } + + public override func needsToBeConstrained() -> Bool { + return true + } + + public override func moleculeAlignment() -> UIStackView.Alignment { + return UIStackView.Alignment.leading + } +} + diff --git a/MVMCoreUI/Molecules/SwitchLineItem.swift b/MVMCoreUI/Molecules/SwitchLineItem.swift index cc4d076f..703f5878 100644 --- a/MVMCoreUI/Molecules/SwitchLineItem.swift +++ b/MVMCoreUI/Molecules/SwitchLineItem.swift @@ -8,8 +8,8 @@ import UIKit -@objcMembers public class Switch: ViewConstrainingView, FormValidationProtocol{ - public var mvmSwitch = MVMCoreUISwitch() +@objcMembers public class SwitchLineItem: ViewConstrainingView, FormValidationProtocol{ + public var mvmSwitch = Switch() public var label = Label() public var leftContainerView = UIView() public var mfTextButton = MFTextButton(nil, constrainHeight: true, forWidth: 0) @@ -26,7 +26,7 @@ import UIKit open override func setupView() { super.setupView() - mvmSwitch.addTarget(self, action: #selector(Switch.switchChanged), for: .valueChanged) + // mvmSwitch.addTarget(self, action: #selector(SwitchLineItem.switchChanged), for: .valueChanged) leftContainerView.addSubview(label) leftContainerView.addSubview(mfTextButton) addSubview(leftContainerView) @@ -50,24 +50,25 @@ import UIKit super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) isRequired = json?[KeyRequired] as? Bool ?? false self.delegateObject = delegateObject + mvmSwitch.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) label.setWithJSON(json?.optionalDictionaryForKey("label"), delegateObject: delegateObject, additionalData: additionalData) mfTextButton.setWithJSON(json?.optionalDictionaryForKey("textButton"), delegateObject: delegateObject, additionalData: additionalData) - if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { - FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol) - } - if let onColorString = json?.optionalStringForKey("onTintColor") { - mvmSwitch.onTintColor = .mfGet(forHex: onColorString) - } - if let offColorString = json?.optionalStringForKey("offTintColor") { - mvmSwitch.offTintColor = .mfGet(forHex: offColorString) - } - if let onKnobColorString = json?.optionalStringForKey("onKnobTintColor") { - mvmSwitch.onKnobTintColor = .mfGet(forHex: onKnobColorString) - } - if let offKnobColorString = json?.optionalStringForKey("offKnobTintColor") { - mvmSwitch.offKnobTintColor = .mfGet(forHex: offKnobColorString) - } - mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true) +// if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { +// FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol) +// } +// if let onColorString = json?.optionalStringForKey("onTintColor") { +// mvmSwitch.onTintColor = .mfGet(forHex: onColorString) +// } +// if let offColorString = json?.optionalStringForKey("offTintColor") { +// mvmSwitch.offTintColor = .mfGet(forHex: offColorString) +// } +// if let onKnobColorString = json?.optionalStringForKey("onKnobTintColor") { +// mvmSwitch.onKnobTintColor = .mfGet(forHex: onKnobColorString) +// } +// if let offKnobColorString = json?.optionalStringForKey("offKnobTintColor") { +// mvmSwitch.offKnobTintColor = .mfGet(forHex: offKnobColorString) +// } +// mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true) // if left container no width if (label.text?.count ?? 0) <= 0 && (mfTextButton.titleLabel?.text?.count ?? 0) <= 0 { mvmSwitch.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 0).isActive = true @@ -129,17 +130,17 @@ import UIKit } - public func isValidField() -> Bool { - return (isRequired == false) ? true : mvmSwitch.isOn - } +// public func isValidField() -> Bool { +// return (isRequired == false) ? true : mvmSwitch.isOn +// } public func formFieldName() -> String? { return json?.optionalStringForKey(KeyFieldKey) } - - public func formFieldValue() -> Any? { - return mvmSwitch.isOn - } +// +// public func formFieldValue() -> Any? { +// return mvmSwitch.isOn +// } public override func needsToBeConstrained() -> Bool { return true diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index 391dd561..0cc21b30 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -34,6 +34,7 @@ @"caretButton": CaretButton.class, @"textField" : MFTextField.class, @"checkbox" : MVMCoreUICheckBox.class, + @"switchLineItem" : SwitchLineItem.class, @"switch" : Switch.class } mutableCopy]; }); From b73c91619275683a1a2cf2dce6b80df331648174 Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 23 May 2019 16:32:14 -0400 Subject: [PATCH 33/47] Switch molecule --- MVMCoreUI/Molecules/SwitchLineItem.swift | 28 ------------------------ 1 file changed, 28 deletions(-) diff --git a/MVMCoreUI/Molecules/SwitchLineItem.swift b/MVMCoreUI/Molecules/SwitchLineItem.swift index 703f5878..4eeae278 100644 --- a/MVMCoreUI/Molecules/SwitchLineItem.swift +++ b/MVMCoreUI/Molecules/SwitchLineItem.swift @@ -26,7 +26,6 @@ import UIKit open override func setupView() { super.setupView() - // mvmSwitch.addTarget(self, action: #selector(SwitchLineItem.switchChanged), for: .valueChanged) leftContainerView.addSubview(label) leftContainerView.addSubview(mfTextButton) addSubview(leftContainerView) @@ -53,23 +52,6 @@ import UIKit mvmSwitch.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) label.setWithJSON(json?.optionalDictionaryForKey("label"), delegateObject: delegateObject, additionalData: additionalData) mfTextButton.setWithJSON(json?.optionalDictionaryForKey("textButton"), delegateObject: delegateObject, additionalData: additionalData) -// if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { -// FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol) -// } -// if let onColorString = json?.optionalStringForKey("onTintColor") { -// mvmSwitch.onTintColor = .mfGet(forHex: onColorString) -// } -// if let offColorString = json?.optionalStringForKey("offTintColor") { -// mvmSwitch.offTintColor = .mfGet(forHex: offColorString) -// } -// if let onKnobColorString = json?.optionalStringForKey("onKnobTintColor") { -// mvmSwitch.onKnobTintColor = .mfGet(forHex: onKnobColorString) -// } -// if let offKnobColorString = json?.optionalStringForKey("offKnobTintColor") { -// mvmSwitch.offKnobTintColor = .mfGet(forHex: offKnobColorString) -// } -// mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true) - // if left container no width if (label.text?.count ?? 0) <= 0 && (mfTextButton.titleLabel?.text?.count ?? 0) <= 0 { mvmSwitch.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 0).isActive = true } @@ -127,20 +109,11 @@ import UIKit mfTextButton.topAnchor.constraint(equalTo: label.bottomAnchor).isActive = true leftContainerView.setContentHuggingPriority(.defaultHigh, for: .horizontal) mvmSwitch.setContentHuggingPriority(.defaultLow, for: .horizontal) - } - -// public func isValidField() -> Bool { -// return (isRequired == false) ? true : mvmSwitch.isOn -// } public func formFieldName() -> String? { return json?.optionalStringForKey(KeyFieldKey) } -// -// public func formFieldValue() -> Any? { -// return mvmSwitch.isOn -// } public override func needsToBeConstrained() -> Bool { return true @@ -149,7 +122,6 @@ import UIKit public override func moleculeAlignment() -> UIStackView.Alignment { return UIStackView.Alignment.leading } - } From f53bd03212a326e827a2c25b9c0e1332f2cbafa7 Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 23 May 2019 17:02:30 -0400 Subject: [PATCH 34/47] Switch molecule --- MVMCoreUI/Molecules/SwitchLineItem.swift | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/MVMCoreUI/Molecules/SwitchLineItem.swift b/MVMCoreUI/Molecules/SwitchLineItem.swift index 4eeae278..9a40c482 100644 --- a/MVMCoreUI/Molecules/SwitchLineItem.swift +++ b/MVMCoreUI/Molecules/SwitchLineItem.swift @@ -17,13 +17,13 @@ import UIKit var delegateObject: DelegateObject? @objc func switchChanged() { - let delegate = delegateObject as? MVMCoreUIDelegateObject + let delegate = delegateObject as? MVMCoreUIDelegateObject if let delegate = delegate { let formValidator = delegate.formValidationProtocol?.formValidatorModel?() formValidator?.enableByValidation() } } - + open override func setupView() { super.setupView() leftContainerView.addSubview(label) @@ -47,8 +47,6 @@ import UIKit open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - isRequired = json?[KeyRequired] as? Bool ?? false - self.delegateObject = delegateObject mvmSwitch.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) label.setWithJSON(json?.optionalDictionaryForKey("label"), delegateObject: delegateObject, additionalData: additionalData) mfTextButton.setWithJSON(json?.optionalDictionaryForKey("textButton"), delegateObject: delegateObject, additionalData: additionalData) @@ -56,14 +54,14 @@ import UIKit mvmSwitch.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 0).isActive = true } } - + func setupContainerConstraints() { leftContainerView.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true var constraint = leftContainerView.topAnchor.constraint(equalTo: topAnchor) constraint.priority = UILayoutPriority(249) constraint.isActive = true - + mvmSwitch.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true constraint = mvmSwitch.topAnchor.constraint(equalTo: topAnchor) @@ -77,7 +75,7 @@ import UIKit constraint.isActive = true bottomAnchor.constraint(greaterThanOrEqualTo: mvmSwitch.bottomAnchor).isActive = true - + constraint = bottomAnchor.constraint(equalTo: leftContainerView.bottomAnchor) constraint.isActive = true @@ -92,7 +90,7 @@ import UIKit leftContainerView.topAnchor.constraint(equalTo: label.topAnchor).isActive = true leftContainerView.trailingAnchor.constraint(greaterThanOrEqualTo: label.trailingAnchor).isActive = true - + constraint = leftContainerView.trailingAnchor.constraint(equalTo: label.trailingAnchor) constraint.priority = UILayoutPriority(249) constraint.isActive = true @@ -111,10 +109,6 @@ import UIKit mvmSwitch.setContentHuggingPriority(.defaultLow, for: .horizontal) } - public func formFieldName() -> String? { - return json?.optionalStringForKey(KeyFieldKey) - } - public override func needsToBeConstrained() -> Bool { return true } From 0f5cb47765f80fdf7e75a91ec432f1d627963633 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 23 May 2019 18:32:11 -0400 Subject: [PATCH 35/47] molecule list moduleMolecule --- MVMCoreUI.xcodeproj/project.pbxproj | 14 ++- MVMCoreUI/Atoms/Buttons/CaretButton.swift | 6 +- MVMCoreUI/Atoms/Buttons/MFTextButton.m | 2 +- MVMCoreUI/Atoms/Buttons/PrimaryButton.m | 6 +- MVMCoreUI/Atoms/TextFields/MFTextField.m | 8 +- MVMCoreUI/Atoms/Views/CaretView.swift | 2 +- MVMCoreUI/Atoms/Views/DashLine.swift | 2 +- MVMCoreUI/Atoms/Views/Label.swift | 2 +- MVMCoreUI/Atoms/Views/LabelView.m | 2 +- .../Atoms/Views/LabelWithInternalButton.swift | 2 +- MVMCoreUI/Atoms/Views/MFLoadImageView.swift | 2 +- MVMCoreUI/Atoms/Views/MFView.m | 2 +- MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m | 4 +- MVMCoreUI/Atoms/Views/SeparatorView.m | 20 ++-- MVMCoreUI/Atoms/Views/ViewConstrainingView.m | 2 +- MVMCoreUI/BaseControllers/MFViewController.h | 3 +- MVMCoreUI/BaseControllers/MFViewController.m | 9 ++ MVMCoreUI/MVMCoreUI.h | 2 + MVMCoreUI/Molecules/ButtonView.swift | 4 +- .../Molecules/MVMCoreUIMoleculeViewProtocol.h | 7 +- MVMCoreUI/Molecules/MoleculeStackView.swift | 8 +- .../Molecules/MoleculeTableViewCell.swift | 67 +++++++---- MVMCoreUI/Molecules/StandardFooterView.swift | 2 +- MVMCoreUI/Molecules/StandardHeaderView.swift | 2 +- MVMCoreUI/Molecules/TwoButtonView.swift | 4 +- .../MVMCoreUIDelegateObject.swift | 6 + .../MVMCoreUIMoleculeMappingObject.h | 27 +++-- .../MVMCoreUIMoleculeMappingObject.m | 66 ++++------- .../OtherHandlers/MoleculeDelegateProtocol.h | 15 +++ .../MoleculeMappingObject+Extension.swift | 47 ++++++++ .../Templates/MoleculeListCellProtocol.h | 23 ++++ .../Templates/MoleculeListTemplate.swift | 112 ++++++++++++++---- .../MoleculeStackCenteredTemplate.swift | 25 +--- .../Templates/MoleculeStackTemplate.swift | 33 ++---- MVMCoreUI/Utility/MVMCoreUIConstants.h | 4 +- MVMCoreUI/Utility/MVMCoreUIConstants.m | 1 + 36 files changed, 356 insertions(+), 187 deletions(-) create mode 100644 MVMCoreUI/OtherHandlers/MoleculeDelegateProtocol.h create mode 100644 MVMCoreUI/OtherHandlers/MoleculeMappingObject+Extension.swift create mode 100644 MVMCoreUI/Templates/MoleculeListCellProtocol.h diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 83b51092..e8230196 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -33,6 +33,9 @@ D282AACB2243C61700C46919 /* ButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AACA2243C61700C46919 /* ButtonView.swift */; }; D28B4F8A21FF967C00712C7A /* MVMCoreUIObject.h in Headers */ = {isa = PBXBuildFile; fileRef = D28B4F8821FF967C00712C7A /* MVMCoreUIObject.h */; settings = {ATTRIBUTES = (Public, ); }; }; D28B4F8B21FF967C00712C7A /* MVMCoreUIObject.m in Sources */ = {isa = PBXBuildFile; fileRef = D28B4F8921FF967C00712C7A /* MVMCoreUIObject.m */; }; + D296E13C229598BF0051EBE7 /* MoleculeListCellProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D296E13B2295969C0051EBE7 /* MoleculeListCellProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; + D296E1412295EBBA0051EBE7 /* MoleculeDelegateProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D296E1402295EBBA0051EBE7 /* MoleculeDelegateProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; + D296E143229729C30051EBE7 /* MoleculeMappingObject+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D296E142229729C30051EBE7 /* MoleculeMappingObject+Extension.swift */; }; D29770C821F7C4AE00B2F0D0 /* TopLabelsView.m in Sources */ = {isa = PBXBuildFile; fileRef = D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */; }; D29770C921F7C4AE00B2F0D0 /* TopLabelsView.h in Headers */ = {isa = PBXBuildFile; fileRef = D29770C721F7C4AE00B2F0D0 /* TopLabelsView.h */; settings = {ATTRIBUTES = (Public, ); }; }; D29770F221F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D29770EE21F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m */; }; @@ -192,6 +195,9 @@ D282AACA2243C61700C46919 /* ButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonView.swift; sourceTree = ""; }; D28B4F8821FF967C00712C7A /* MVMCoreUIObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIObject.h; sourceTree = ""; }; D28B4F8921FF967C00712C7A /* MVMCoreUIObject.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUIObject.m; sourceTree = ""; }; + D296E13B2295969C0051EBE7 /* MoleculeListCellProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MoleculeListCellProtocol.h; sourceTree = ""; }; + D296E1402295EBBA0051EBE7 /* MoleculeDelegateProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MoleculeDelegateProtocol.h; sourceTree = ""; }; + D296E142229729C30051EBE7 /* MoleculeMappingObject+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MoleculeMappingObject+Extension.swift"; sourceTree = ""; }; D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TopLabelsView.m; sourceTree = ""; }; D29770C721F7C4AE00B2F0D0 /* TopLabelsView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TopLabelsView.h; sourceTree = ""; }; D29770EE21F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TopLabelsAndBottomButtonsTableViewController.m; sourceTree = ""; }; @@ -319,10 +325,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 = ""; }; @@ -411,6 +417,7 @@ 01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */, D2A5146022121FBF00345BFB /* MoleculeStackTemplate.swift */, D2A514622213643100345BFB /* MoleculeStackCenteredTemplate.swift */, + D296E13B2295969C0051EBE7 /* MoleculeListCellProtocol.h */, D2E1FAE02268E81D00AEFD8C /* MoleculeListTemplate.swift */, ); path = Templates; @@ -651,8 +658,10 @@ D29DF27421E79E81003B2FB9 /* MVMCoreUILoggingHandler.m */, D2C5001621F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.h */, D2C5001721F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m */, + D296E1402295EBBA0051EBE7 /* MoleculeDelegateProtocol.h */, D2A514562211C53C00345BFB /* MVMCoreUIMoleculeMappingObject.h */, D2A514572211C53C00345BFB /* MVMCoreUIMoleculeMappingObject.m */, + D296E142229729C30051EBE7 /* MoleculeMappingObject+Extension.swift */, ); path = OtherHandlers; sourceTree = ""; @@ -773,6 +782,7 @@ D29DF12D21E6851E003B2FB9 /* MVMCoreUITopAlertBaseView.h in Headers */, D29DF24E21E6A177003B2FB9 /* MFDigitTextField.h in Headers */, D29770F321F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.h in Headers */, + D296E1412295EBBA0051EBE7 /* MoleculeDelegateProtocol.h in Headers */, D2C5001821F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.h in Headers */, D29770FD21F7C77400B2F0D0 /* MVMCoreUITextFieldView.h in Headers */, D29DF17421E69E1F003B2FB9 /* MFCustomButton.h in Headers */, @@ -781,6 +791,7 @@ D29DF2A121E7AF4E003B2FB9 /* MVMCoreUIUtility.h in Headers */, D29DF17621E69E1F003B2FB9 /* PrimaryButton.h in Headers */, D29DF2C821E7BFC1003B2FB9 /* MFSizeObject.h in Headers */, + D296E13C229598BF0051EBE7 /* MoleculeListCellProtocol.h in Headers */, D29DF32021ED0CBA003B2FB9 /* LabelView.h in Headers */, D29770C921F7C4AE00B2F0D0 /* TopLabelsView.h in Headers */, D29DF2E121E9240B003B2FB9 /* MVMCoreUIPanelProtocol.h in Headers */, @@ -913,6 +924,7 @@ D29DF28321E7AB24003B2FB9 /* MVMCoreUICommonViewsUtility.m in Sources */, D206997821FB8A0B00CAE0DE /* MVMCoreUINavigationController.m in Sources */, D29DF27A21E7A533003B2FB9 /* MVMCoreUISession.m in Sources */, + D296E143229729C30051EBE7 /* MoleculeMappingObject+Extension.swift in Sources */, 01DF55E021F8FAA800CC099B /* MFTextFieldListView.swift in Sources */, D2A5146B2214905000345BFB /* ThreeLayerViewController.swift in Sources */, D29DF2C921E7BFC6003B2FB9 /* MFSizeObject.m in Sources */, diff --git a/MVMCoreUI/Atoms/Buttons/CaretButton.swift b/MVMCoreUI/Atoms/Buttons/CaretButton.swift index 0176b147..4503a1f3 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretButton.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretButton.swift @@ -9,6 +9,7 @@ open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol { + //------------------------------------------------------ // MARK: - Constants //------------------------------------------------------ @@ -51,6 +52,9 @@ open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol { changeCaretColor() } + public func updateView(_ size: CGFloat) { + } + //------------------------------------------------------ // MARK: - Functions //------------------------------------------------------ @@ -110,7 +114,7 @@ open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol { setTitleColor(disabledColor, for: .disabled) } - @objc public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + @objc public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { setWithActionMap(json, delegateObject: delegateObject, additionalData: additionalData) guard let dictionary = json else { return } diff --git a/MVMCoreUI/Atoms/Buttons/MFTextButton.m b/MVMCoreUI/Atoms/Buttons/MFTextButton.m index d78df33d..4c513ef9 100644 --- a/MVMCoreUI/Atoms/Buttons/MFTextButton.m +++ b/MVMCoreUI/Atoms/Buttons/MFTextButton.m @@ -128,7 +128,7 @@ #pragma mark - MVMCoreUIMoleculeViewProtocol -- (void)setWithJSON:(NSDictionary *)json delegateObject:(DelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { +- (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { NSString *color = [json string:KeyTextColor]; if (color) { [self setTitleColor:[UIColor mfGetColorForHex:color] forState:UIControlStateNormal]; diff --git a/MVMCoreUI/Atoms/Buttons/PrimaryButton.m b/MVMCoreUI/Atoms/Buttons/PrimaryButton.m index 2085b5c8..b2fe18d2 100644 --- a/MVMCoreUI/Atoms/Buttons/PrimaryButton.m +++ b/MVMCoreUI/Atoms/Buttons/PrimaryButton.m @@ -648,10 +648,8 @@ [self setAsStandardCustom]; } -- (void)setWithJSON:(NSDictionary *)json delegateObject:(DelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { - if ([delegateObject isKindOfClass:[MVMCoreUIDelegateObject class]]) { - [FormValidator setupValidationWithMolecule:self delegate:((MVMCoreUIDelegateObject *)delegateObject).formValidationProtocol]; - } +- (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { + [FormValidator setupValidationWithMolecule:self delegate:delegateObject.formValidationProtocol]; self.primaryButtonType = PrimaryButtonTypeCustom; NSString *color = [json string:@"fillColor"]; diff --git a/MVMCoreUI/Atoms/TextFields/MFTextField.m b/MVMCoreUI/Atoms/TextFields/MFTextField.m index 52580f46..55d6f8e6 100644 --- a/MVMCoreUI/Atoms/TextFields/MFTextField.m +++ b/MVMCoreUI/Atoms/TextFields/MFTextField.m @@ -559,14 +559,14 @@ self.isMolecule = YES; } -- (void)setWithJSON:(NSDictionary *)json delegateObject:(DelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { +- (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { if ([delegateObject isKindOfClass:[MVMCoreUIDelegateObject class]]) { - [FormValidator setupValidationWithMolecule:self delegate:((MVMCoreUIDelegateObject *)delegateObject).formValidationProtocol]; - FormValidator *formValidator = [FormValidator getFormValidatorForDelegate:((MVMCoreUIDelegateObject *)delegateObject).formValidationProtocol]; + [FormValidator setupValidationWithMolecule:self delegate:delegateObject.formValidationProtocol]; + FormValidator *formValidator = [FormValidator getFormValidatorForDelegate:delegateObject.formValidationProtocol]; [self setWithMap:json]; self.mfTextFieldDelegate = formValidator; - self.uiTextFieldDelegate = ((MVMCoreUIDelegateObject *)delegateObject).uiTextFieldDelegate; + self.uiTextFieldDelegate = delegateObject.uiTextFieldDelegate; [MVMCoreUICommonViewsUtility addDismissToolbar:self.textField delegate:self.uiTextFieldDelegate]; } } diff --git a/MVMCoreUI/Atoms/Views/CaretView.swift b/MVMCoreUI/Atoms/Views/CaretView.swift index 56566287..f5ee49c3 100644 --- a/MVMCoreUI/Atoms/Views/CaretView.swift +++ b/MVMCoreUI/Atoms/Views/CaretView.swift @@ -103,7 +103,7 @@ open class CaretView: MFView { defaultState() } - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + 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 guard let dictionary = json else { return } diff --git a/MVMCoreUI/Atoms/Views/DashLine.swift b/MVMCoreUI/Atoms/Views/DashLine.swift index 82c05b27..e9ca4a78 100644 --- a/MVMCoreUI/Atoms/Views/DashLine.swift +++ b/MVMCoreUI/Atoms/Views/DashLine.swift @@ -68,7 +68,7 @@ open class DashLine: MFView { isHidden = false } - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + 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 diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index 0cd77ee0..6302ed90 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -295,7 +295,7 @@ import MVMCore // MARK: - Atomization //------------------------------------------------------ - @objc public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + @objc public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { Label.setUILabel(self, withJSON: json, delegate: delegateObject, additionalData: additionalData) originalAttributedString = attributedText } diff --git a/MVMCoreUI/Atoms/Views/LabelView.m b/MVMCoreUI/Atoms/Views/LabelView.m index 56091d24..e0817374 100644 --- a/MVMCoreUI/Atoms/Views/LabelView.m +++ b/MVMCoreUI/Atoms/Views/LabelView.m @@ -73,7 +73,7 @@ } } -- (void)setWithJSON:(NSDictionary *)json delegateObject:(DelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { +- (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { [super setWithJSON:json delegateObject:delegateObject additionalData:additionalData]; [self.label setWithJSON:json delegateObject:delegateObject additionalData:additionalData]; } diff --git a/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift b/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift index 502c766a..76693a6b 100644 --- a/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift +++ b/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift @@ -734,7 +734,7 @@ extension LabelWithInternalButton: MVMCoreUIMoleculeViewProtocol { } - @objc open func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + @objc open func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { // Configure class properties with JSON values guard let dictionary = json else { return } diff --git a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift index 69ef1b6f..3593e9e4 100644 --- a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift +++ b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift @@ -203,7 +203,7 @@ import UIKit } // MARK: - MVMCoreUIMoleculeViewProtocol functions - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) if let backgroundColorString = json?.optionalStringForKey(KeyBackgroundColor) { backgroundColor = UIColor.mfGet(forHex: backgroundColorString) diff --git a/MVMCoreUI/Atoms/Views/MFView.m b/MVMCoreUI/Atoms/Views/MFView.m index b22a5674..029c6ce2 100644 --- a/MVMCoreUI/Atoms/Views/MFView.m +++ b/MVMCoreUI/Atoms/Views/MFView.m @@ -44,7 +44,7 @@ #pragma mark - MVMCoreUIMoleculeViewProtocol -- (void)setWithJSON:(NSDictionary *)json delegateObject:(DelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { +- (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { self.json = json; } diff --git a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m index 0158beb1..73a29011 100644 --- a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m +++ b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m @@ -58,9 +58,9 @@ static const CGFloat CheckBoxHeightWidth = 18.0; return UIStackViewAlignmentLeading; } -- (void)setWithJSON:(NSDictionary *)json delegateObject:(DelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { +- (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { - [FormValidator setupValidationWithMolecule:self delegate:((MVMCoreUIDelegateObject *)delegateObject).formValidationProtocol]; + [FormValidator setupValidationWithMolecule:self delegate:delegateObject.formValidationProtocol]; self.delegate = delegateObject; self.fieldKey = [json stringForKey:KeyFieldKey]; self.isRequired = [json boolForKey:KeyRequired]; diff --git a/MVMCoreUI/Atoms/Views/SeparatorView.m b/MVMCoreUI/Atoms/Views/SeparatorView.m index 95fe8bb8..50e59758 100644 --- a/MVMCoreUI/Atoms/Views/SeparatorView.m +++ b/MVMCoreUI/Atoms/Views/SeparatorView.m @@ -95,17 +95,21 @@ } } -- (void)setWithJSON:(NSDictionary *)json delegateObject:(DelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { +- (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { [super setWithJSON:json delegateObject:delegateObject additionalData:additionalData]; if (json) { - self.hidden = NO; NSString *type = [json string:KeyType]; - if ([type isEqualToString:@"standard"]) { - [self setSize:1]; - } else if ([type isEqualToString:@"medium"]) { - [self setSize:2]; - } else if ([type isEqualToString:@"heavy"]) { - [self setSize:4]; + if ([type isEqualToString:@"none"]) { + self.hidden = YES; + } else { + self.hidden = NO; + if ([type isEqualToString:@"medium"]) { + [self setAsMedium]; + } else if ([type isEqualToString:@"heavy"]) { + [self setAsHeavy]; + } else { + [self setAsLight]; + } } NSString *backgroundColor = [json string:KeyBackgroundColor]; if (backgroundColor) { diff --git a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m index c1e3e5ff..d433388c 100644 --- a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m +++ b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m @@ -151,7 +151,7 @@ self.updateViewHorizontalDefaults = YES; } -- (void)setWithJSON:(NSDictionary *)json delegateObject:(DelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { +- (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { [super setWithJSON:json delegateObject:delegateObject additionalData:additionalData]; if (self.molecule) { [self.molecule setWithJSON:json delegateObject:delegateObject additionalData:additionalData]; diff --git a/MVMCoreUI/BaseControllers/MFViewController.h b/MVMCoreUI/BaseControllers/MFViewController.h index 8c1d5766..f1b87dc6 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.h +++ b/MVMCoreUI/BaseControllers/MFViewController.h @@ -27,13 +27,14 @@ #import #import #import +#import @class MainMenuViewController; @class MVMCoreUITabBarPageControlViewController; @class MVMAnimationManager; @class DelegateObject; -@interface MFViewController : UIViewController +@interface MFViewController : UIViewController // Stores the load object that this screen was loaded with. @property (nullable, strong, nonatomic) MVMCoreLoadObject *loadObject; diff --git a/MVMCoreUI/BaseControllers/MFViewController.m b/MVMCoreUI/BaseControllers/MFViewController.m index b6f71412..6aff745a 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.m +++ b/MVMCoreUI/BaseControllers/MFViewController.m @@ -786,6 +786,15 @@ } } +#pragma mark - MoleculeDelegateProtocol + +- (NSDictionary *)getModuleWithName:(NSString *)name { + if (!name) { + return nil; + } + return [self.loadObject.modulesJSON dict:name]; +} + #pragma mark - adobe analytics - (nullable NSArray *)additionalActionsToTrackWithMainActionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData { diff --git a/MVMCoreUI/MVMCoreUI.h b/MVMCoreUI/MVMCoreUI.h index 8b4e24bd..b5ccd8e1 100644 --- a/MVMCoreUI/MVMCoreUI.h +++ b/MVMCoreUI/MVMCoreUI.h @@ -20,6 +20,8 @@ FOUNDATION_EXPORT const unsigned char MVMCoreUIVersionString[]; #import #import #import +#import +#import #import #pragma mark - TopAlert diff --git a/MVMCoreUI/Molecules/ButtonView.swift b/MVMCoreUI/Molecules/ButtonView.swift index c23f1aa9..c01a48ce 100644 --- a/MVMCoreUI/Molecules/ButtonView.swift +++ b/MVMCoreUI/Molecules/ButtonView.swift @@ -33,7 +33,7 @@ import UIKit primaryButton?.isEnabled = enabled } - public init(withJSON json: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) { + public init(withJSON json: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) { super.init(frame: .zero) setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) } @@ -58,7 +58,7 @@ import UIKit primaryButton?.setAsMolecule() } - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) primaryButton?.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) } diff --git a/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h b/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h index 12557967..8b7a3745 100644 --- a/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h +++ b/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h @@ -7,12 +7,13 @@ // #import -@class DelegateObject; +@import MVMCore.MVMCoreViewProtocol; +@class MVMCoreUIDelegateObject; -@protocol MVMCoreUIMoleculeViewProtocol +@protocol MVMCoreUIMoleculeViewProtocol // Sets up the ui based on the json -- (void)setWithJSON:(nullable NSDictionary *)json delegateObject:(nullable DelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData; +- (void)setWithJSON:(nullable NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData; @optional diff --git a/MVMCoreUI/Molecules/MoleculeStackView.swift b/MVMCoreUI/Molecules/MoleculeStackView.swift index ef060718..5f7f8957 100644 --- a/MVMCoreUI/Molecules/MoleculeStackView.swift +++ b/MVMCoreUI/Molecules/MoleculeStackView.swift @@ -18,12 +18,12 @@ public class MoleculeStackView: MFView { super.init(frame: frame) } - public init(withJSON json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) { + public init(withJSON json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { super.init(frame: CGRect.zero) setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) } - public convenience init(withJSON json: [AnyHashable: Any]?, delegateObject: DelegateObject?, spacingBlock: ((Any) -> UIEdgeInsets)?) { + public convenience init(withJSON json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, spacingBlock: ((Any) -> UIEdgeInsets)?) { self.init(withJSON: json, delegateObject: delegateObject, additionalData: nil) self.spacingBlock = spacingBlock } @@ -51,7 +51,7 @@ public class MoleculeStackView: MFView { } // MARK: - MVMCoreUIMoleculeViewProtocol - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) guard let molecules = json?.arrayForKey(KeyMolecules) as? [[String: Any]] else { return @@ -60,7 +60,7 @@ public class MoleculeStackView: MFView { // Create the molecules and set the json. var moleculesArray = [] as [UIView] for moleculeJSON in molecules { - if let molecule = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeForStack(withJSON: moleculeJSON, delegateObject: delegateObject) { + if let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject, constrainIfNeeded: true) { moleculesArray.append(molecule) } } diff --git a/MVMCoreUI/Molecules/MoleculeTableViewCell.swift b/MVMCoreUI/Molecules/MoleculeTableViewCell.swift index 1df0e67d..f84776f4 100644 --- a/MVMCoreUI/Molecules/MoleculeTableViewCell.swift +++ b/MVMCoreUI/Molecules/MoleculeTableViewCell.swift @@ -8,8 +8,10 @@ import UIKit -@objcMembers open class MoleculeTableViewCell: UITableViewCell, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { +@objcMembers open class MoleculeTableViewCell: UITableViewCell, MVMCoreUIMoleculeViewProtocol, MoleculeListCellProtocol { + open var molecule: (UIView & MVMCoreUIMoleculeViewProtocol)? + open var json: [AnyHashable: Any]? // For the accessory view convenience. public var caretView: CaretView? @@ -50,9 +52,7 @@ import UIKit bottomSeparatorView?.setLeftAndRightPinConstant(layoutMargins.left) } - if let molecule = molecule as? MVMCoreViewProtocol { - molecule.updateView(size) - } + molecule?.updateView(size) if let _ = accessoryView, let caretView = caretView, let widthObject = caretViewWidthSizeObject, let heightObject = caretViewHeightSizeObject { caretView.frame = CGRect(x: 0, y: 0, width: widthObject.getValueBased(onSize: size), height: heightObject.getValueBased(onSize: size)) } @@ -67,23 +67,31 @@ import UIKit } // MARK: - MVMCoreUIMoleculeViewProtocol - public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) { - guard let json = json else { + public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { + self.json = json; + guard let json = json, let moleculeJSON = json.optionalDictionaryForKey(KeyMolecule) else { return } if molecule == nil { - if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeForStack(withJSON: json, delegateObject: delegateObject) { + if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject, constrainIfNeeded: true) { contentView.addSubview(moleculeView) NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: moleculeView.needsToBeConstrained?() ?? false).values)) molecule = moleculeView } } else { - molecule?.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + molecule?.setWithJSON(moleculeJSON, delegateObject: delegateObject, additionalData: additionalData) } backgroundColor = molecule?.backgroundColor + + // Add the caret if there is an action and it's not declared hidden. + if let _ = json.optionalDictionaryForKey("actionMap"), !json.boolForKey("hideArrow") { + addCaretViewAccessory() + } else { + accessoryView = nil + } } - // MARK: - Convenience + // MARK: - Arrow /// Adds the standard mvm style caret to the accessory view public func addCaretViewAccessory() { guard accessoryView == nil else { @@ -98,6 +106,34 @@ import UIKit accessoryView = caretView } + // MARK: - MoleculeListCellProtocol + public static func moleculeName(_ molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? { + return molecule?.optionalDictionaryForKey(KeyMolecule)?.optionalStringForKey(KeyMoleculeName) + } + + /// For when the separator between cells shows using json and frequency. Default is type: standard, frequency: allExceptTop. + public func setSeparatorWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?, indexPath: IndexPath) { + addSeparatorsIfNeeded() + if let json = json { + topSeparatorView?.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + bottomSeparatorView?.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + if let separatorFrequencyString = json.optionalStringForKey("frequency"), let separatorFrequency = SeparatorFrequency(rawValue: separatorFrequencyString) { + setSeparatorFrequency(separatorFrequency, indexPath: indexPath) + } + } else { + topSeparatorView?.hide() + bottomSeparatorView?.setAsLight() + setSeparatorFrequency(MoleculeTableViewCell.SeparatorFrequency.AllExceptTop, indexPath: indexPath) + } + } + + public func didSelectCell(atIndex indexPath: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { + if let actionMap = json?.optionalDictionaryForKey("actionMap") { + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) + } + } + + // MARK: - Separator func addSeparatorsIfNeeded() { if topSeparatorView == nil { topSeparatorView = SeparatorView.separatorAdd(to: self, position: SeparatorPositionTop) @@ -109,19 +145,6 @@ import UIKit } } - /// For when the separator between cells shows using json and frequency. - public func setSeparatorWithJSON(_ json: [AnyHashable : Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?, indexPath: IndexPath) { - guard let json = json else { - return - } - addSeparatorsIfNeeded() - topSeparatorView?.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - bottomSeparatorView?.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - if let separatorFrequencyString = json.optionalStringForKey("frequency"), let separatorFrequency = SeparatorFrequency(rawValue: separatorFrequencyString) { - setSeparatorFrequency(separatorFrequency, indexPath: indexPath) - } - } - /// For when the separator between cells shows. public func setSeparatorFrequency(_ separatorFrequency: SeparatorFrequency, indexPath: IndexPath) { switch separatorFrequency { diff --git a/MVMCoreUI/Molecules/StandardFooterView.swift b/MVMCoreUI/Molecules/StandardFooterView.swift index 06d39c47..5c4aa688 100644 --- a/MVMCoreUI/Molecules/StandardFooterView.swift +++ b/MVMCoreUI/Molecules/StandardFooterView.swift @@ -93,7 +93,7 @@ public class StandardFooterView: ViewConstrainingView { layoutIfNeeded() } - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) if let colorString = json?.optionalStringForKey(KeyBackgroundColor) { backgroundColor = .mfGet(forHex: colorString) diff --git a/MVMCoreUI/Molecules/StandardHeaderView.swift b/MVMCoreUI/Molecules/StandardHeaderView.swift index 58aa727c..308341fa 100644 --- a/MVMCoreUI/Molecules/StandardHeaderView.swift +++ b/MVMCoreUI/Molecules/StandardHeaderView.swift @@ -110,7 +110,7 @@ public class StandardHeaderView: ViewConstrainingView { separatorView?.rightPin?.constant = constant } - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) if let colorString = json?.optionalStringForKey(KeyBackgroundColor) { backgroundColor = .mfGet(forHex: colorString) diff --git a/MVMCoreUI/Molecules/TwoButtonView.swift b/MVMCoreUI/Molecules/TwoButtonView.swift index 66b7210a..ca3c8215 100644 --- a/MVMCoreUI/Molecules/TwoButtonView.swift +++ b/MVMCoreUI/Molecules/TwoButtonView.swift @@ -39,7 +39,7 @@ import UIKit } // MARK: - MVMCoreUIMoleculeViewProtocol - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) if let backgroundColorString = json?.optionalStringForKey(KeyBackgroundColor) { backgroundColor = UIColor.mfGet(forHex: backgroundColorString) @@ -142,7 +142,7 @@ import UIKit } } - open func set(primaryButtonJSON: [AnyHashable: Any]?, secondaryButtonJSON: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + open func set(primaryButtonJSON: [AnyHashable: Any]?, secondaryButtonJSON: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { setupUI(withPrimaryButtonMap: primaryButtonJSON, secondaryButtonMap: secondaryButtonJSON, legacy: false) setDefaultCustom() primaryButton?.setWithJSON(primaryButtonJSON, delegateObject: delegateObject, additionalData: additionalData) diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift b/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift index 92744a8c..c0c8211f 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift @@ -12,11 +12,17 @@ open class MVMCoreUIDelegateObject: DelegateObject { public weak var formValidationProtocol: FormValidationProtocol? public weak var buttonDelegate: ButtonDelegateProtocol? public weak var uiTextFieldDelegate: UITextFieldDelegate? + public weak var moleculeDelegate: MoleculeDelegateProtocol? open override func setAll(withDelegate delegate: Any) { super.setAll(withDelegate: delegate) formValidationProtocol = delegate as? FormValidationProtocol buttonDelegate = delegate as? ButtonDelegateProtocol uiTextFieldDelegate = delegate as? UITextFieldDelegate + moleculeDelegate = delegate as? MoleculeDelegateProtocol + } + + class func delegateObject(from controller: MVMCoreViewControllerProtocol?) -> MVMCoreUIDelegateObject? { + return controller?.delegateObject?() as? MVMCoreUIDelegateObject } } diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h index 79534f20..4b5cb909 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h @@ -8,7 +8,7 @@ #import #import -@class DelegateObject; +@class MVMCoreUIDelegateObject; @class MVMCoreLoadObject; @class MVMCoreErrorObject; @@ -20,20 +20,23 @@ /// Returns the shared instance + (nullable instancetype)sharedMappingObject; -/// Returns the molecule for the given name. -- (nullable UIView *)getMoleculeForName:(nonnull NSString *)name; -- (nullable UIView *)getMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable DelegateObject *)delegateObject; +/// Returns the molecule class. +- (nullable Class)getMoleculeClassWithJSON:(nonnull NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject; -/// Returns the molecule for the json. Also checks if the molecule needs to be constrained for a stack. -- (nullable UIView *)getMoleculeForStackWithJSON:(nonnull NSDictionary *)json delegateObject:(nullable DelegateObject *)delegateObject; +#pragma mark - Molecule Creation -/// Returns the molecule for the json. Checks if the molecule needs to be constrained for a stack. Load object may be used if the molecule needs to be loaded from the page or module map. -- (nullable UIView *)getMoleculeForStackWithJSON:(nonnull NSDictionary *)json delegateObject:(nullable DelegateObject *)delegateObject loadObject:(nullable MVMCoreLoadObject *)loadObject; +/// Creates the molecule for the given name. +- (nullable UIView *)createMoleculeForName:(nonnull NSString *)name; -#pragma mark - Helpers +/// Creates the molecule for the molecule json. Takes into account moduleMolecule as well. +- (nullable UIView *)createMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject; -/// Gets the molecule from the passed in module map. -+ (nullable NSDictionary *)getMoleculeMapForModuleMolecule:(nullable NSDictionary *)moduleMolecule moduleMap:(nullable NSDictionary *)moduleMap error:(MVMCoreErrorObject *_Nullable *_Nullable)error; -+ (nullable NSString *)getMoleculeNameForModuleMolecule:(nullable NSDictionary *)moduleMolecule moduleMap:(nullable NSDictionary *)moduleMap error:(MVMCoreErrorObject *_Nullable *_Nullable)error; +/// Creates the molecule for the molecule json. Takes into account moduleMolecule as well. Also checks if the molecule needs to be constrained for a stack/list style situation. +- (nullable UIView *)createMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject constrainIfNeeded:(BOOL)constrainIfNeeded; + +#pragma mark - ModuleMolecule Helpers + +/// If the molecule is a module molecule, will get the map for the molecule to load from a module. Otherwise nil. ++ (nullable NSDictionary *)getMoleculeMapForModuleMolecule:(nullable NSDictionary *)moduleMolecule delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject error:(MVMCoreErrorObject *_Nullable *_Nullable)error; @end diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index 58586bb5..ba846a1f 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -45,7 +45,18 @@ return [MVMCoreActionUtility initializerClassCheck:[MVMCoreUIObject sharedInstance].moleculeMap classToVerify:self]; } -- (nullable UIView *)getMoleculeForName:(nonnull NSString *)name { +- (nullable Class)getMoleculeClassWithJSON:(nonnull NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject { + NSDictionary *moleculeJSON = [MVMCoreUIMoleculeMappingObject getMoleculeMapForModuleMolecule:json delegateObject:delegateObject error:nil] ?: json; + NSString *moleculeName = [moleculeJSON string:KeyMoleculeName]; + if (moleculeName) { + return [self.moleculeMapping objectForKey:moleculeName]; + } + return nil; +} + +#pragma mark - Molecule Creation + +- (nullable UIView *)createMoleculeForName:(nonnull NSString *)name { Class class = [self.moleculeMapping objectForKey:name]; if (!class) { return nil; @@ -57,58 +68,31 @@ return molecule; } -- (nullable UIView *)getMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable DelegateObject *)delegateObject { - NSString *moleculeName = [json string:KeyMoleculeName]; - if (!moleculeName) { - return nil; - } - UIView *molecule = [self getMoleculeForName:moleculeName]; - [molecule setWithJSON:json delegateObject:delegateObject additionalData:nil]; - return molecule; +- (nullable UIView *)createMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject { + return [self createMoleculeForJSON:json delegateObject:delegateObject constrainIfNeeded:NO]; } - -- (nullable UIView *)getMoleculeForStackWithJSON:(nonnull NSDictionary *)json delegateObject:(nullable DelegateObject *)delegateObject { - NSString *moleculeName = [json string:KeyMoleculeName]; +- (nullable UIView *)createMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject constrainIfNeeded:(BOOL)constrainIfNeeded { + NSDictionary *moleculeJSON = [MVMCoreUIMoleculeMappingObject getMoleculeMapForModuleMolecule:json delegateObject:delegateObject error:nil] ?: json; + NSString *moleculeName = [moleculeJSON string:KeyMoleculeName]; if (!moleculeName) { return nil; } - UIView *molecule = [self getMoleculeForName:moleculeName]; - if ([molecule respondsToSelector:@selector(needsToBeConstrained)] && [molecule needsToBeConstrained]) { + UIView *molecule = [self createMoleculeForName:moleculeName]; + if (constrainIfNeeded && [molecule respondsToSelector:@selector(needsToBeConstrained)] && [molecule needsToBeConstrained]) { molecule = [[ViewConstrainingView alloc] initWithMolecule:molecule alignment:[molecule respondsToSelector:@selector(moleculeAlignment)] ? [molecule moleculeAlignment] : UIStackViewAlignmentFill]; } - [molecule setWithJSON:json delegateObject:delegateObject additionalData:nil]; + [molecule setWithJSON:moleculeJSON delegateObject:delegateObject additionalData:nil]; return molecule; } -- (nullable UIView *)getMoleculeForStackWithJSON:(nonnull NSDictionary *)json delegateObject:(nullable DelegateObject *)delegateObject loadObject:(nullable MVMCoreLoadObject *)loadObject { - NSString *moleculeName = [json string:KeyMoleculeName]; - if (!moleculeName) { - return nil; - } else if ([moleculeName isEqualToString:@"moduleMolecule"]) { - NSString *moduleName = [json string:@"moduleName"]; - if (moduleName) { - NSDictionary *newJSON = [loadObject.modulesJSON dict:moduleName]; - if (newJSON) { - json = newJSON; - } - } - } - UIView *molecule = [self getMoleculeForName:moleculeName]; - if ([molecule respondsToSelector:@selector(needsToBeConstrained)] && [molecule needsToBeConstrained]) { - molecule = [[ViewConstrainingView alloc] initWithMolecule:molecule alignment:[molecule respondsToSelector:@selector(moleculeAlignment)] ? [molecule moleculeAlignment] : UIStackViewAlignmentFill]; - } - [molecule setWithJSON:json delegateObject:delegateObject additionalData:nil]; - return molecule; -} +#pragma mark - ModuleMolecule Helpers -#pragma mark - Helpers - -+ (nullable NSDictionary *)getMoleculeMapForModuleMolecule:(nullable NSDictionary *)moduleMolecule moduleMap:(nullable NSDictionary *)moduleMap error:(MVMCoreErrorObject *_Nullable *_Nullable)error { ++ (nullable NSDictionary *)getMoleculeMapForModuleMolecule:(nullable NSDictionary *)moduleMolecule delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject error:(MVMCoreErrorObject *_Nullable *_Nullable)error { NSString *moleculeName = [moduleMolecule string:KeyMoleculeName]; if ([moleculeName isEqualToString:@"moduleMolecule"]) { NSString *moduleName = [moduleMolecule string:@"moduleName"]; - NSDictionary *module = moduleName ? [moduleMap dict:moduleName] : nil; + NSDictionary *module = moduleName ? [delegateObject.moleculeDelegate getModuleWithName:moduleName] : nil; if (!module && error) { *error = [[MVMCoreErrorObject alloc] initWithTitle:nil message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeModuleMolecule domain:ErrorDomainNative location:NSStringFromClass(self)]; } @@ -118,8 +102,4 @@ } } -+ (nullable NSString *)getMoleculeNameForModuleMolecule:(nullable NSDictionary *)moduleMolecule moduleMap:(nullable NSDictionary *)moduleMap error:(MVMCoreErrorObject *_Nullable *_Nullable)error { - return [[self getMoleculeMapForModuleMolecule:moduleMolecule moduleMap:moduleMap error:error] string:KeyMoleculeName]; -} - @end diff --git a/MVMCoreUI/OtherHandlers/MoleculeDelegateProtocol.h b/MVMCoreUI/OtherHandlers/MoleculeDelegateProtocol.h new file mode 100644 index 00000000..0d027386 --- /dev/null +++ b/MVMCoreUI/OtherHandlers/MoleculeDelegateProtocol.h @@ -0,0 +1,15 @@ +// +// MoleculeDelegateProtocol.h +// MVMCoreUI +// +// Created by Scott Pfeil on 5/22/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// +#import + +@protocol MoleculeDelegateProtocol + +/// returns a module for the corresponding module name. +- (nullable NSDictionary *)getModuleWithName:(nullable NSString *)name; + +@end diff --git a/MVMCoreUI/OtherHandlers/MoleculeMappingObject+Extension.swift b/MVMCoreUI/OtherHandlers/MoleculeMappingObject+Extension.swift new file mode 100644 index 00000000..a5dd2cbe --- /dev/null +++ b/MVMCoreUI/OtherHandlers/MoleculeMappingObject+Extension.swift @@ -0,0 +1,47 @@ +// +// MoleculeMappingObject+Extension.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 5/23/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + +public extension MVMCoreUIMoleculeMappingObject { + + /// Gets the molecule, and if it belonged to a moduleMolecule, the module name or error. + static func getMoleculeJSON(for map: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> (molecule: [AnyHashable: Any]?, moduleName: String?, error: MVMCoreErrorObject?)? { + guard let map = map, let moleculeName = map.optionalStringForKey(KeyMoleculeName) else { + return nil + } + guard moleculeName == "moduleMolecule" else { + // Not a module molecule. + return (map, moleculeName, nil) + } + + guard let moduleName = map.optionalStringForKey("moduleName"), + let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else { + guard let error = MVMCoreErrorObject(title: nil, message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess), code: CoreUIErrorCode.ErrorCodeModuleMolecule.rawValue, domain: ErrorDomainNative, location: String(describing: self)) else { + return nil + } + MVMCoreUILoggingHandler.shared()?.addError(toLog: error) + return (nil, nil, error) + } + return (module, moduleName, nil) + } + + /// Gets the molecule, and if it belonged to a moduleMolecule adds the module name or error to the passed lists. + static func getMoleculeJSON(for map: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, moduleNames: inout [String]?, errors: inout [MVMCoreErrorObject]?) -> [AnyHashable: Any]? { + guard let molecule = getMoleculeJSON(for: map, delegateObject: delegateObject) else { + return nil + } + if let moduleName = molecule.moduleName { + moduleNames?.append(moduleName) + } + if let error = molecule.error { + errors?.append(error) + } + return molecule.molecule + } +} diff --git a/MVMCoreUI/Templates/MoleculeListCellProtocol.h b/MVMCoreUI/Templates/MoleculeListCellProtocol.h new file mode 100644 index 00000000..3bc390f2 --- /dev/null +++ b/MVMCoreUI/Templates/MoleculeListCellProtocol.h @@ -0,0 +1,23 @@ +// +// MoleculeListCellProtocol.h +// MVMCoreUI +// +// Created by Scott Pfeil on 5/22/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// +#import +@class MVMCoreLoadObject; +@class MVMCoreUIDelegateObject; + +@protocol MoleculeListCellProtocol +@optional +/// Can override the molecule name for the given molecule. Otherwise we assume value for key moleculeName. ++ (nullable NSString *)moleculeName:(nullable NSDictionary *)molecule loadObject:(nullable MVMCoreLoadObject *)loadObject; + +/// Can set the separator according to what the moleculeList commands. +- (void)setSeparatorWithJSON:(nullable NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData indexPath:(nonnull NSIndexPath *)indexPath; + +/// Handle action +- (void)didSelectCellAtIndex:(nonnull NSIndexPath *)indexPath delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData; + +@end diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index fe891a93..1bc590e0 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -10,27 +10,27 @@ import UIKit open class MoleculeListTemplate: ThreeLayerTableViewController { - open override func registerWithTable() { - super.registerWithTable() - guard let molecules = loadObject?.pageJSON?.arrayForKey(KeyMolecules) else { - return - } - for case let molecule as Dictionary in molecules { - if let moleculeName = molecule.optionalStringForKey(KeyMoleculeName) { - tableView?.register(MoleculeTableViewCell.self, forCellReuseIdentifier: moleculeName) - } + open override func shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject, error: AutoreleasingUnsafeMutablePointer) -> Bool { + var shouldFinish = super.shouldFinishProcessingLoad(loadObject, error: error) + if shouldFinish, let firstError = modulesNeeded().errors?.first { + // Don't continue if there was an error loading needed modules. + error.pointee = firstError + shouldFinish = false } + return shouldFinish } open override func viewForTop() -> UIView { - guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("header"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeForStack(withJSON: moleculeJSON, delegateObject: delegateObject()) else { + guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("header"), + let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else { return super.viewForTop() } return molecule } override open func viewForBottom() -> UIView { - guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("footer"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeForStack(withJSON: moleculeJSON, delegateObject: delegateObject()) else { + guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("footer"), + let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else { return viewForBottom() } return molecule @@ -41,12 +41,26 @@ open class MoleculeListTemplate: ThreeLayerTableViewController { registerWithTable() } - open override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { - if let moleculeName = loadObject?.pageJSON?.stringOptionalWithChainOfKeysOrIndexes([KeyMolecules,indexPath.row,KeyMoleculeName]), let theClass = MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping?[moleculeName] as? MVMCoreUIMoleculeViewProtocol.Type, - let estimatedHeightForRow = theClass.estimatedHeightForRow { - return estimatedHeightForRow() + // MARK: - table + open override func registerWithTable() { + super.registerWithTable() + guard let molecules = loadObject?.pageJSON?.arrayForKey(KeyMolecules) else { + return } - return 0 + for case let map as Dictionary in molecules { + if let molecule = getMoleculeInfo(with: map), let moleculeToRegister = molecule.name { + tableView?.register(molecule.class, forCellReuseIdentifier: moleculeToRegister) + } + } + } + + open override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { + guard let map = loadObject?.pageJSON?.optionalDictionaryWithChainOfKeysOrIndexes([KeyMolecules,indexPath.row]), + let molecule = getMoleculeInfo(with: map), + let estimatedHeightForRow = molecule.class.estimatedHeightForRow else { + return 0 + } + return estimatedHeightForRow() } open override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { @@ -54,15 +68,67 @@ open class MoleculeListTemplate: ThreeLayerTableViewController { } open override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - guard let molecule = loadObject?.pageJSON?.optionalDictionaryWithChainOfKeysOrIndexes([KeyMolecules,indexPath.row]), - let moleculeName = molecule.optionalStringForKey(KeyMoleculeName), - let cell = tableView.dequeueReusableCell(withIdentifier: moleculeName) as? MoleculeTableViewCell else { + let delegate = delegateObject() as? MVMCoreUIDelegateObject + guard let map = loadObject?.pageJSON?.optionalDictionaryWithChainOfKeysOrIndexes([KeyMolecules,indexPath.row]), + let moleculeJSON = MVMCoreUIMoleculeMappingObject.getMoleculeJSON(for: map, delegateObject: delegate)?.molecule, + let moleculeName = moleculeJSON.optionalStringForKey(KeyMoleculeName), + let cell = tableView.dequeueReusableCell(withIdentifier: moleculeName) else { return UITableViewCell() } - let delegate = delegateObject() - cell.setWithJSON(molecule, delegateObject: delegate, additionalData: nil) - cell.setSeparatorWithJSON(loadObject?.pageJSON?.optionalDictionaryForKey("separator"), delegateObject: delegate, additionalData: nil, indexPath: indexPath) - cell.updateView(tableView.bounds.width) + if let protocolCell = cell as? MoleculeListCellProtocol { + protocolCell.setSeparatorWithJSON?(loadObject?.pageJSON?.optionalDictionaryForKey("separator"), delegateObject: delegate, additionalData: nil, indexPath: indexPath) + } + if let protocolCell = cell as? MVMCoreUIMoleculeViewProtocol { + protocolCell.setWithJSON(moleculeJSON, delegateObject: delegate, additionalData: nil) + protocolCell.updateView(tableView.bounds.width) + } return cell } + + open override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + if let cell = tableView.cellForRow(at: indexPath) as? MoleculeListCellProtocol { + cell.didSelectCell?(atIndex: indexPath, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, additionalData: nil) + } + } + + // MARK: - cache handling + open override func pageTypesToListenFor() -> [Any]? { + guard let pageType = self.pageType else { + return super.pageTypesToListenFor() + } + return [pageType] + } + + open override func modulesToListenFor() -> [Any]? { + // Get all of the molecules that need modules. + return modulesNeeded().modules + } + + // MARK: - Module Molecule Handling + /// Returns the (name, class) of the molecule for the given map. + func getMoleculeInfo(with map: [AnyHashable: Any]?) -> (name: String?, class: AnyClass)? { + guard let map = map, let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: map, delegateObject: delegateObject() as? MVMCoreUIDelegateObject) else { + return nil + } + if let moleculeClass = moleculeClass as? MoleculeListCellProtocol.Type, let moleculeName = moleculeClass.moleculeName { + return (moleculeName(map, loadObject), moleculeClass) + } else { + return (map.optionalStringForKey(KeyMoleculeName), moleculeClass) + } + } + + func modulesNeeded() -> (modules: [String]?, errors: [MVMCoreErrorObject]?) { + var modules: [String]? = [] + var errors: [MVMCoreErrorObject]? = [] + let delegate = delegateObject() as? MVMCoreUIDelegateObject + + let _ = MVMCoreUIMoleculeMappingObject.getMoleculeJSON(for: loadObject?.pageJSON?.optionalDictionaryForKey("header"), delegateObject: delegate, moduleNames: &modules, errors: &errors) + let _ = MVMCoreUIMoleculeMappingObject.getMoleculeJSON(for: loadObject?.pageJSON?.optionalDictionaryForKey("footer"), delegateObject: delegate, moduleNames: &modules, errors: &errors) + if let molecules = loadObject?.pageJSON?.optionalArrayForKey(KeyMolecules) as? [[AnyHashable: Any]] { + for molecule in molecules { + let _ = MVMCoreUIMoleculeMappingObject.getMoleculeJSON(for: molecule, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, moduleNames: &modules, errors: &errors) + } + } + return (modules?.count ?? 0 > 0 ? modules : nil, errors?.count ?? 0 > 0 ? errors : nil) + } } diff --git a/MVMCoreUI/Templates/MoleculeStackCenteredTemplate.swift b/MVMCoreUI/Templates/MoleculeStackCenteredTemplate.swift index b359ecf5..af5af39c 100644 --- a/MVMCoreUI/Templates/MoleculeStackCenteredTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeStackCenteredTemplate.swift @@ -8,27 +8,8 @@ import UIKit -public class MoleculeStackCenteredTemplate: ThreeLayerViewController { - - public override func viewForMiddle() -> UIView? { - let molecule = loadObject?.pageJSON?.optionalDictionaryForKey("moleculeStack") - let moleculeStack = MoleculeStackView(withJSON: molecule, delegateObject: delegateObject(), additionalData: nil) - return moleculeStack - } - - public override func viewForTop() -> UIView? { - guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("header"), - let molecule = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeForStack(withJSON: moleculeJSON, delegateObject: delegateObject()) else { - return nil - } - return molecule - } - - override public func viewForBottom() -> UIView? { - guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("footer"), - let molecule = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeForStack(withJSON: moleculeJSON, delegateObject: delegateObject()) else { - return nil - } - return molecule +public class MoleculeStackCenteredTemplate: MoleculeStackTemplate { + public override func spaceBetweenTopAndMiddle() -> CGFloat? { + return nil } } diff --git a/MVMCoreUI/Templates/MoleculeStackTemplate.swift b/MVMCoreUI/Templates/MoleculeStackTemplate.swift index 10a291d7..3f5e04da 100644 --- a/MVMCoreUI/Templates/MoleculeStackTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeStackTemplate.swift @@ -25,7 +25,7 @@ public class MoleculeStackTemplate: ThreeLayerViewController { } public override func viewForTop() -> UIView? { - guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("header"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeForStack(withJSON: moleculeJSON, delegateObject: delegateObject()) else { + guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("header"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else { return nil } return molecule @@ -35,11 +35,11 @@ public class MoleculeStackTemplate: ThreeLayerViewController { guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("moleculeStack") else { return nil } - return MoleculeStackView(withJSON: moleculeJSON, delegateObject: delegateObject(), additionalData: nil) + return MoleculeStackView(withJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, additionalData: nil) } override public func viewForBottom() -> UIView? { - guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("footer"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeForStack(withJSON: moleculeJSON, delegateObject: delegateObject()) else { + guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("footer"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else { return nil } return molecule @@ -59,27 +59,18 @@ public class MoleculeStackTemplate: ThreeLayerViewController { } // MARK: - Module Molecule Handling - func addModule(for moduleMolecule: [AnyHashable: Any]?, modules: inout [String], errors: inout [MVMCoreErrorObject]) { - var error: MVMCoreErrorObject? - if let moleculeName = MVMCoreUIMoleculeMappingObject.getMoleculeName(forModuleMolecule: moduleMolecule, moduleMap: loadObject?.modulesJSON, error: &error) { - modules.append(moleculeName) - if let errorObject = error { - MVMCoreLoggingHandler.shared()?.addError(toLog: errorObject) - errors.append(errorObject) - } - } - } - func modulesNeeded() -> (modules: [String]?, errors: [MVMCoreErrorObject]?) { - var modules: [String] = [] - var errors: [MVMCoreErrorObject] = [] - addModule(for: loadObject?.pageJSON?.optionalDictionaryForKey("header"), modules: &modules, errors: &errors) - addModule(for: loadObject?.pageJSON?.optionalDictionaryForKey("footer"), modules: &modules, errors: &errors) - if let molecules = loadObject?.pageJSON?.optionalArrayForChainOfKeysOrIndexes(["moleculeStack","molecules"]) as? [[AnyHashable: Any]] { + var modules: [String]? = [] + var errors: [MVMCoreErrorObject]? = [] + let delegate = delegateObject() as? MVMCoreUIDelegateObject + + let _ = MVMCoreUIMoleculeMappingObject.getMoleculeJSON(for: loadObject?.pageJSON?.optionalDictionaryForKey("header"), delegateObject: delegate, moduleNames: &modules, errors: &errors) + let _ = MVMCoreUIMoleculeMappingObject.getMoleculeJSON(for: loadObject?.pageJSON?.optionalDictionaryForKey("footer"), delegateObject: delegate, moduleNames: &modules, errors: &errors) + if let molecules = loadObject?.pageJSON?.optionalArrayForChainOfKeysOrIndexes(["moleculeStack",KeyMolecules]) as? [[AnyHashable: Any]] { for molecule in molecules { - addModule(for: molecule, modules: &modules, errors: &errors) + let _ = MVMCoreUIMoleculeMappingObject.getMoleculeJSON(for: molecule, delegateObject: delegate, moduleNames: &modules, errors: &errors) } } - return (modules.count > 0 ? modules : nil, errors.count > 0 ? errors : nil) + return (modules?.count ?? 0 > 0 ? modules : nil, errors?.count ?? 0 > 0 ? errors : nil) } } diff --git a/MVMCoreUI/Utility/MVMCoreUIConstants.h b/MVMCoreUI/Utility/MVMCoreUIConstants.h index 6a3f930c..778ede4f 100644 --- a/MVMCoreUI/Utility/MVMCoreUIConstants.h +++ b/MVMCoreUI/Utility/MVMCoreUIConstants.h @@ -15,6 +15,7 @@ extern NSString * const KeyScreenHeading; extern NSString * const KeyMolecules; extern NSString * const KeyMoleculeName; +extern NSString * const KeyMolecule; extern NSString * const KeyDisableButton; @@ -73,5 +74,6 @@ extern NSString * const KeyHandScroll; // Native Error Codes (Add new ones to bottom, don't change order!) typedef NS_ENUM(NSInteger, CoreUIErrorCode) { - ErrorCodeModuleMolecule = 100 + ErrorCodeModuleMolecule = 100, + ErrorCodeListMolecule = 101 }; diff --git a/MVMCoreUI/Utility/MVMCoreUIConstants.m b/MVMCoreUI/Utility/MVMCoreUIConstants.m index 9735675e..26636266 100644 --- a/MVMCoreUI/Utility/MVMCoreUIConstants.m +++ b/MVMCoreUI/Utility/MVMCoreUIConstants.m @@ -14,6 +14,7 @@ NSString * const KeyScreenHeading = @"screenHeading"; NSString * const KeyMolecules = @"molecules"; NSString * const KeyMoleculeName = @"moleculeName"; +NSString * const KeyMolecule = @"molecule"; NSString * const KeyDisableButton = @"disableAction"; From cf4af8731ebee9ec188dc018fc3e8559bef2db6d Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 24 May 2019 09:42:20 -0400 Subject: [PATCH 36/47] fix to parameter --- MVMCoreUI/OtherHandlers/MoleculeMappingObject+Extension.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/OtherHandlers/MoleculeMappingObject+Extension.swift b/MVMCoreUI/OtherHandlers/MoleculeMappingObject+Extension.swift index a5dd2cbe..3c88a743 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeMappingObject+Extension.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeMappingObject+Extension.swift @@ -17,7 +17,7 @@ public extension MVMCoreUIMoleculeMappingObject { } guard moleculeName == "moduleMolecule" else { // Not a module molecule. - return (map, moleculeName, nil) + return (map, nil, nil) } guard let moduleName = map.optionalStringForKey("moduleName"), From b03fa77dfd993475717700268f5b0faf9bd05d34 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 24 May 2019 09:45:42 -0400 Subject: [PATCH 37/47] added to molecule list --- MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index ba846a1f..f69d74f5 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -33,8 +33,9 @@ @"standardFooter": StandardFooterView.class, @"caretView": CaretView.class, @"caretButton": CaretButton.class, - @"textField" : MFTextField.class, - @"checkbox" : MVMCoreUICheckBox.class + @"textField": MFTextField.class, + @"checkbox": MVMCoreUICheckBox.class, + @"listItem": MoleculeTableViewCell.class } mutableCopy]; }); return mapping; From 699aa94d0a0f3068cf104b193cf9c0eef4b4545b Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 24 May 2019 11:56:07 -0400 Subject: [PATCH 38/47] fixes --- MVMCoreUI/Molecules/ButtonView.swift | 4 + .../Molecules/MVMCoreUIMoleculeViewProtocol.h | 2 +- .../Molecules/MoleculeTableViewCell.swift | 9 ++ .../MVMCoreUIMoleculeMappingObject.h | 2 +- .../Templates/MoleculeListTemplate.swift | 104 +++++++++++++----- 5 files changed, 92 insertions(+), 29 deletions(-) diff --git a/MVMCoreUI/Molecules/ButtonView.swift b/MVMCoreUI/Molecules/ButtonView.swift index c01a48ce..6f81ce9c 100644 --- a/MVMCoreUI/Molecules/ButtonView.swift +++ b/MVMCoreUI/Molecules/ButtonView.swift @@ -63,6 +63,10 @@ import UIKit primaryButton?.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) } + public static func estimatedHeight(forRow json: [AnyHashable : Any]?) -> CGFloat { + return 40 + } + // MARK: - Constraining func setupButton() { if let primaryButton = primaryButton, !subviews.contains(primaryButton) { diff --git a/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h b/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h index 8b7a3745..67e64d24 100644 --- a/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h +++ b/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h @@ -27,7 +27,7 @@ - (UIStackViewAlignment)moleculeAlignment; // For the molecule list to load more efficiently. -+ (CGFloat)estimatedHeightForRow; ++ (CGFloat)estimatedHeightForRow:(nullable NSDictionary *)json; @end diff --git a/MVMCoreUI/Molecules/MoleculeTableViewCell.swift b/MVMCoreUI/Molecules/MoleculeTableViewCell.swift index f84776f4..e0401f38 100644 --- a/MVMCoreUI/Molecules/MoleculeTableViewCell.swift +++ b/MVMCoreUI/Molecules/MoleculeTableViewCell.swift @@ -91,6 +91,15 @@ import UIKit } } + public static func estimatedHeight(forRow json: [AnyHashable : Any]?) -> CGFloat { + guard let moleculeJSON = json?.optionalDictionaryForKey(KeyMolecule), + let theClass = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: moleculeJSON, delegateObject: nil), + let estimatedHeightFor = theClass.estimatedHeight else { + return 0 + } + return estimatedHeightFor(moleculeJSON) + } + // MARK: - Arrow /// Adds the standard mvm style caret to the accessory view public func addCaretViewAccessory() { diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h index 4b5cb909..4e7dd8db 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h @@ -15,7 +15,7 @@ @interface MVMCoreUIMoleculeMappingObject : NSObject /// Maps molecule name to class. -@property (nullable, strong, nonatomic) NSMutableDictionary *moleculeMapping; +@property (nonnull, strong, nonatomic) NSMutableDictionary *moleculeMapping; /// Returns the shared instance + (nullable instancetype)sharedMappingObject; diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index 1bc590e0..11e3bddb 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -9,10 +9,15 @@ import UIKit open class MoleculeListTemplate: ThreeLayerTableViewController { + var molecules: [(molecule: [AnyHashable: Any]?, moduleName: String?, error: MVMCoreErrorObject?)]? open override func shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject, error: AutoreleasingUnsafeMutablePointer) -> Bool { var shouldFinish = super.shouldFinishProcessingLoad(loadObject, error: error) - if shouldFinish, let firstError = modulesNeeded().errors?.first { + guard shouldFinish else { + return shouldFinish + } + + if let firstError = setup()?.first { // Don't continue if there was an error loading needed modules. error.pointee = firstError shouldFinish = false @@ -38,48 +43,49 @@ open class MoleculeListTemplate: ThreeLayerTableViewController { open override func newDataBuildScreen() { super.newDataBuildScreen() + _ = setupMoleculeList() registerWithTable() } // MARK: - table open override func registerWithTable() { super.registerWithTable() - guard let molecules = loadObject?.pageJSON?.arrayForKey(KeyMolecules) else { + guard let molecules = molecules else { return } - for case let map as Dictionary in molecules { - if let molecule = getMoleculeInfo(with: map), let moleculeToRegister = molecule.name { - tableView?.register(molecule.class, forCellReuseIdentifier: moleculeToRegister) + for molecule in molecules { + if let moleculeInfo = getMoleculeInfo(with: molecule), let moleculeToRegister = moleculeInfo.name { + tableView?.register(moleculeInfo.class, forCellReuseIdentifier: moleculeToRegister) } } } open override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { - guard let map = loadObject?.pageJSON?.optionalDictionaryWithChainOfKeysOrIndexes([KeyMolecules,indexPath.row]), - let molecule = getMoleculeInfo(with: map), - let estimatedHeightForRow = molecule.class.estimatedHeightForRow else { + guard let molecule = molecules?[indexPath.row], + let moleculeInfo = getMoleculeInfo(with: molecule), + let estimatedHeight = moleculeInfo.class.estimatedHeight else { return 0 } - return estimatedHeightForRow() + return estimatedHeight(molecule.molecule) } open override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return loadObject?.pageJSON?.arrayForKey(KeyMolecules).count ?? 0 + return molecules?.count ?? 0 } open override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let delegate = delegateObject() as? MVMCoreUIDelegateObject - guard let map = loadObject?.pageJSON?.optionalDictionaryWithChainOfKeysOrIndexes([KeyMolecules,indexPath.row]), - let moleculeJSON = MVMCoreUIMoleculeMappingObject.getMoleculeJSON(for: map, delegateObject: delegate)?.molecule, - let moleculeName = moleculeJSON.optionalStringForKey(KeyMoleculeName), + guard let molecule = molecules?[indexPath.row], + let moleculeInfo = getMoleculeInfo(with: molecule), + let moleculeName = moleculeInfo.name, let cell = tableView.dequeueReusableCell(withIdentifier: moleculeName) else { return UITableViewCell() } + let delegate = delegateObject() as? MVMCoreUIDelegateObject if let protocolCell = cell as? MoleculeListCellProtocol { protocolCell.setSeparatorWithJSON?(loadObject?.pageJSON?.optionalDictionaryForKey("separator"), delegateObject: delegate, additionalData: nil, indexPath: indexPath) } if let protocolCell = cell as? MVMCoreUIMoleculeViewProtocol { - protocolCell.setWithJSON(moleculeJSON, delegateObject: delegate, additionalData: nil) + protocolCell.setWithJSON(molecule.molecule, delegateObject: delegate, additionalData: nil) protocolCell.updateView(tableView.bounds.width) } return cell @@ -101,34 +107,78 @@ open class MoleculeListTemplate: ThreeLayerTableViewController { open override func modulesToListenFor() -> [Any]? { // Get all of the molecules that need modules. - return modulesNeeded().modules + return modulesNeeded() } // MARK: - Module Molecule Handling /// Returns the (name, class) of the molecule for the given map. - func getMoleculeInfo(with map: [AnyHashable: Any]?) -> (name: String?, class: AnyClass)? { - guard let map = map, let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: map, delegateObject: delegateObject() as? MVMCoreUIDelegateObject) else { + func getMoleculeInfo(with molecule: (molecule: [AnyHashable: Any]?, moduleName: String?, error: MVMCoreErrorObject?)) -> (name: String?, class: AnyClass)? { + guard let map = molecule.molecule, let moleculeName = map.optionalStringForKey(KeyMoleculeName), let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping[moleculeName] as? AnyClass else { return nil } if let moleculeClass = moleculeClass as? MoleculeListCellProtocol.Type, let moleculeName = moleculeClass.moleculeName { return (moleculeName(map, loadObject), moleculeClass) } else { - return (map.optionalStringForKey(KeyMoleculeName), moleculeClass) + return (moleculeName, moleculeClass) } } - func modulesNeeded() -> (modules: [String]?, errors: [MVMCoreErrorObject]?) { - var modules: [String]? = [] - var errors: [MVMCoreErrorObject]? = [] + /// Sets up the molecule list and ensures no errors loading all content. + func setupMoleculeList() -> [MVMCoreErrorObject]? { + var errors: [MVMCoreErrorObject] = [] let delegate = delegateObject() as? MVMCoreUIDelegateObject - - let _ = MVMCoreUIMoleculeMappingObject.getMoleculeJSON(for: loadObject?.pageJSON?.optionalDictionaryForKey("header"), delegateObject: delegate, moduleNames: &modules, errors: &errors) - let _ = MVMCoreUIMoleculeMappingObject.getMoleculeJSON(for: loadObject?.pageJSON?.optionalDictionaryForKey("footer"), delegateObject: delegate, moduleNames: &modules, errors: &errors) + var moleculeList: [(molecule: [AnyHashable: Any]?, moduleName: String?, error: MVMCoreErrorObject?)] = [] if let molecules = loadObject?.pageJSON?.optionalArrayForKey(KeyMolecules) as? [[AnyHashable: Any]] { for molecule in molecules { - let _ = MVMCoreUIMoleculeMappingObject.getMoleculeJSON(for: molecule, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, moduleNames: &modules, errors: &errors) + if let object = MVMCoreUIMoleculeMappingObject.getMoleculeJSON(for: molecule, delegateObject: delegate) { + if let error = object.error { + errors.append(error) + } else { + moleculeList.append(object) + } + } } } - return (modules?.count ?? 0 > 0 ? modules : nil, errors?.count ?? 0 > 0 ? errors : nil) + molecules = moleculeList + return errors.count > 0 ? errors : nil + } + + /// Sets up the header, footer, molecule list and ensures no errors loading all content. + func setup() -> [MVMCoreErrorObject]? { + var errors: [MVMCoreErrorObject] = [] + let delegate = delegateObject() as? MVMCoreUIDelegateObject + MoleculeListTemplate.addToErrorList(with: MVMCoreUIMoleculeMappingObject.getMoleculeJSON(for: loadObject?.pageJSON?.optionalDictionaryForKey("header"), delegateObject: delegate), errors: &errors) + MoleculeListTemplate.addToErrorList(with: MVMCoreUIMoleculeMappingObject.getMoleculeJSON(for: loadObject?.pageJSON?.optionalDictionaryForKey("footer"), delegateObject: delegate), errors: &errors) + if let newErrors = setupMoleculeList() { + errors.append(contentsOf: newErrors) + } + return errors.count > 0 ? errors : nil + } + + static func addToErrorList(with moleculeObject: (molecule: [AnyHashable: Any]?, moduleName: String?, error: MVMCoreErrorObject?)?, errors: inout [MVMCoreErrorObject]) { + if let error = moleculeObject?.error { + errors.append(error) + } + } + + static func addToModuleList(with moleculeObject: (molecule: [AnyHashable: Any]?, moduleName: String?, error: MVMCoreErrorObject?)?, moduleNames: inout [String]) { + if let moduleName = moleculeObject?.moduleName { + moduleNames.append(moduleName) + } + } + + /// Gets a list of required modules + func modulesNeeded() -> [String]? { + var modules: [String] = [] + let delegate = delegateObject() as? MVMCoreUIDelegateObject + + MoleculeListTemplate.addToModuleList(with: MVMCoreUIMoleculeMappingObject.getMoleculeJSON(for: loadObject?.pageJSON?.optionalDictionaryForKey("header"), delegateObject: delegate), moduleNames: &modules) + MoleculeListTemplate.addToModuleList(with: MVMCoreUIMoleculeMappingObject.getMoleculeJSON(for: loadObject?.pageJSON?.optionalDictionaryForKey("footer"), delegateObject: delegate), moduleNames: &modules) + if let molecules = molecules { + for molecule in molecules { + MoleculeListTemplate.addToModuleList(with: molecule, moduleNames: &modules) + } + } + return (modules.count > 0 ? modules : nil) } } From 89ed78a0eba8b22a76cd3fd0153389990a9baa88 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 24 May 2019 11:57:00 -0400 Subject: [PATCH 39/47] miss --- MVMCoreUI/Molecules/ButtonView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Molecules/ButtonView.swift b/MVMCoreUI/Molecules/ButtonView.swift index 6f81ce9c..aab2d17b 100644 --- a/MVMCoreUI/Molecules/ButtonView.swift +++ b/MVMCoreUI/Molecules/ButtonView.swift @@ -63,7 +63,7 @@ import UIKit primaryButton?.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) } - public static func estimatedHeight(forRow json: [AnyHashable : Any]?) -> CGFloat { + public override static func estimatedHeight(forRow json: [AnyHashable : Any]?) -> CGFloat { return 40 } From f4cfd0386ca57690371959014c5819e75e9a28e9 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 24 May 2019 12:30:04 -0400 Subject: [PATCH 40/47] add forgotten separator override --- MVMCoreUI/Molecules/MoleculeTableViewCell.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MVMCoreUI/Molecules/MoleculeTableViewCell.swift b/MVMCoreUI/Molecules/MoleculeTableViewCell.swift index e0401f38..e0053437 100644 --- a/MVMCoreUI/Molecules/MoleculeTableViewCell.swift +++ b/MVMCoreUI/Molecules/MoleculeTableViewCell.swift @@ -89,6 +89,12 @@ import UIKit } else { accessoryView = nil } + + // override the separator + if let separator = json.optionalDictionaryForKey("separator") { + addSeparatorsIfNeeded() + bottomSeparatorView?.setWithJSON(separator, delegateObject: delegateObject, additionalData: additionalData) + } } public static func estimatedHeight(forRow json: [AnyHashable : Any]?) -> CGFloat { From 1799f166ee14d26b5606a48d8b61a4d4e2f34c3a Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 28 May 2019 10:08:04 -0400 Subject: [PATCH 41/47] remove duplicate --- MVMCoreUI/Atoms/Views/MFLoadImageView.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift index 3593e9e4..2a72481e 100644 --- a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift +++ b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift @@ -197,7 +197,6 @@ import UIKit if let imageName = json?.optionalStringForKey("image"), shouldLoadImage(withName: imageName, width: width) { imageView.image = nil imageView.animatedImage = nil - loadImage(withName: imageName, format: json?.optionalStringForKey("imageFormat"), width: NSNumber(value: Double(width)), height: nil) loadImage(withName: imageName, format: json?.optionalStringForKey("imageFormat"), width: NSNumber(value: Double(width)), height: nil, customFallbackImage: json?.optionalStringForKey("fallbackImage")) } } From 59900d987ab6666f200a3540196d03d0d8a436b1 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 28 May 2019 16:00:00 -0400 Subject: [PATCH 42/47] fix to mismatch --- MVMCoreUI/Templates/MoleculeListCellProtocol.h | 3 +-- MVMCoreUI/Templates/MoleculeListTemplate.swift | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Templates/MoleculeListCellProtocol.h b/MVMCoreUI/Templates/MoleculeListCellProtocol.h index 3bc390f2..08ca2a37 100644 --- a/MVMCoreUI/Templates/MoleculeListCellProtocol.h +++ b/MVMCoreUI/Templates/MoleculeListCellProtocol.h @@ -6,13 +6,12 @@ // Copyright © 2019 Verizon Wireless. All rights reserved. // #import -@class MVMCoreLoadObject; @class MVMCoreUIDelegateObject; @protocol MoleculeListCellProtocol @optional /// Can override the molecule name for the given molecule. Otherwise we assume value for key moleculeName. -+ (nullable NSString *)moleculeName:(nullable NSDictionary *)molecule loadObject:(nullable MVMCoreLoadObject *)loadObject; ++ (nullable NSString *)moleculeName:(nullable NSDictionary *)molecule delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject; /// Can set the separator according to what the moleculeList commands. - (void)setSeparatorWithJSON:(nullable NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData indexPath:(nonnull NSIndexPath *)indexPath; diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index 11e3bddb..92805511 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -116,8 +116,8 @@ open class MoleculeListTemplate: ThreeLayerTableViewController { guard let map = molecule.molecule, let moleculeName = map.optionalStringForKey(KeyMoleculeName), let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping[moleculeName] as? AnyClass else { return nil } - if let moleculeClass = moleculeClass as? MoleculeListCellProtocol.Type, let moleculeName = moleculeClass.moleculeName { - return (moleculeName(map, loadObject), moleculeClass) + if let moleculeClass = moleculeClass as? MoleculeListCellProtocol.Type, let moleculeNameFunc = moleculeClass.moleculeName { + return (moleculeNameFunc(map, delegateObject() as? MVMCoreUIDelegateObject), moleculeClass) } else { return (moleculeName, moleculeClass) } From 9cf37d0850b9c78d5e7f9cd1c7a0c7f885d67956 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 28 May 2019 16:26:23 -0400 Subject: [PATCH 43/47] fix extra space --- MVMCoreUI/Templates/MoleculeListTemplate.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index 92805511..db69218b 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -113,7 +113,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController { // MARK: - Module Molecule Handling /// Returns the (name, class) of the molecule for the given map. func getMoleculeInfo(with molecule: (molecule: [AnyHashable: Any]?, moduleName: String?, error: MVMCoreErrorObject?)) -> (name: String?, class: AnyClass)? { - guard let map = molecule.molecule, let moleculeName = map.optionalStringForKey(KeyMoleculeName), let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping[moleculeName] as? AnyClass else { + guard let map = molecule.molecule, let moleculeName = map.optionalStringForKey(KeyMoleculeName), let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping[moleculeName] as? AnyClass else { return nil } if let moleculeClass = moleculeClass as? MoleculeListCellProtocol.Type, let moleculeNameFunc = moleculeClass.moleculeName { From 403f0bbea881ed6a20bea8ab0ea5aad4ab241b56 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 28 May 2019 16:47:07 -0400 Subject: [PATCH 44/47] 42 update to estimated height --- MVMCoreUI/Molecules/ButtonView.swift | 2 +- MVMCoreUI/Molecules/TwoButtonView.swift | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Molecules/ButtonView.swift b/MVMCoreUI/Molecules/ButtonView.swift index aab2d17b..d03a2e72 100644 --- a/MVMCoreUI/Molecules/ButtonView.swift +++ b/MVMCoreUI/Molecules/ButtonView.swift @@ -64,7 +64,7 @@ import UIKit } public override static func estimatedHeight(forRow json: [AnyHashable : Any]?) -> CGFloat { - return 40 + return 42 } // MARK: - Constraining diff --git a/MVMCoreUI/Molecules/TwoButtonView.swift b/MVMCoreUI/Molecules/TwoButtonView.swift index ca3c8215..3e965667 100644 --- a/MVMCoreUI/Molecules/TwoButtonView.swift +++ b/MVMCoreUI/Molecules/TwoButtonView.swift @@ -49,6 +49,10 @@ import UIKit set(primaryButtonJSON: primaryButtonMap, secondaryButtonJSON: secondaryButtonMap, delegateObject: delegateObject, additionalData: additionalData) } + public override static func estimatedHeight(forRow json: [AnyHashable : Any]?) -> CGFloat { + return 42 + } + // MARK: - Constraining override func setupButton() { setupWithTwoButtons() From a3325035b9e9ca896eff89f69507797169f25b01 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 28 May 2019 17:04:25 -0400 Subject: [PATCH 45/47] fix override... --- MVMCoreUI/Molecules/TwoButtonView.swift | 4 ---- 1 file changed, 4 deletions(-) diff --git a/MVMCoreUI/Molecules/TwoButtonView.swift b/MVMCoreUI/Molecules/TwoButtonView.swift index 3e965667..ca3c8215 100644 --- a/MVMCoreUI/Molecules/TwoButtonView.swift +++ b/MVMCoreUI/Molecules/TwoButtonView.swift @@ -49,10 +49,6 @@ import UIKit set(primaryButtonJSON: primaryButtonMap, secondaryButtonJSON: secondaryButtonMap, delegateObject: delegateObject, additionalData: additionalData) } - public override static func estimatedHeight(forRow json: [AnyHashable : Any]?) -> CGFloat { - return 42 - } - // MARK: - Constraining override func setupButton() { setupWithTwoButtons() From 341aef0184faa956b5163e1141ea6674fa91a044 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 29 May 2019 10:13:48 -0400 Subject: [PATCH 46/47] more merge fixes --- MVMCoreUI/Molecules/Switch.swift | 4 ++-- MVMCoreUI/Molecules/SwitchLineItem.swift | 2 +- MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index 81818ee3..b97496a3 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -35,11 +35,11 @@ import UIKit mvmSwitch.updateView(size) } - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) isRequired = json?[KeyRequired] as? Bool ?? false self.delegateObject = delegateObject - if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { + if let delegateObject = delegateObject { FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol) } if let onColorString = json?.optionalStringForKey("onTintColor") { diff --git a/MVMCoreUI/Molecules/SwitchLineItem.swift b/MVMCoreUI/Molecules/SwitchLineItem.swift index 9a40c482..665de248 100644 --- a/MVMCoreUI/Molecules/SwitchLineItem.swift +++ b/MVMCoreUI/Molecules/SwitchLineItem.swift @@ -45,7 +45,7 @@ import UIKit mfTextButton.updateView(size) } - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) mvmSwitch.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) label.setWithJSON(json?.optionalDictionaryForKey("label"), delegateObject: delegateObject, additionalData: additionalData) diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index e629dbc1..0d80000b 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -35,8 +35,7 @@ @"caretButton": CaretButton.class, @"textField": MFTextField.class, @"checkbox": MVMCoreUICheckBox.class, - @"listItem": MoleculeTableViewCell.class - @"checkbox": MVMCoreUICheckBox.class, + @"listItem": MoleculeTableViewCell.class, @"switchLineItem": SwitchLineItem.class, @"switch": Switch.class } mutableCopy]; From 674dc70b8426b86fce8183682416043e22199324 Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Fri, 31 May 2019 10:46:44 -0400 Subject: [PATCH 47/47] Creates method to dismiss regular picker view to avoid relying on dismissDatePicker method --- MVMCoreUI/Atoms/TextFields/MFTextField.h | 1 + MVMCoreUI/Atoms/TextFields/MFTextField.m | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/MVMCoreUI/Atoms/TextFields/MFTextField.h b/MVMCoreUI/Atoms/TextFields/MFTextField.h index 27dd8414..63694bfb 100644 --- a/MVMCoreUI/Atoms/TextFields/MFTextField.h +++ b/MVMCoreUI/Atoms/TextFields/MFTextField.h @@ -116,6 +116,7 @@ - (void)inputFromDatePickerFromDate:(nullable NSDate *)fromDate toDate:(nullable NSDate *)toDate showFromDateAsDefaultInput:(BOOL)show; - (void)setDatePickerFromDate:(nullable NSDate *)fromDate toDate:(nullable NSDate *)toDate; - (nonnull NSDate *)dismissDatePicker; +- (void)dismissPicker; //get all enabled textfields, can be pairly used with the primary button's handleEnablingWithTextFields if you only want the enable testfield's validation to be tested + (nullable NSArray *)getEnabledTextfields:(nullable NSArray *)textFieldToDetermine; diff --git a/MVMCoreUI/Atoms/TextFields/MFTextField.m b/MVMCoreUI/Atoms/TextFields/MFTextField.m index 55d6f8e6..26934699 100644 --- a/MVMCoreUI/Atoms/TextFields/MFTextField.m +++ b/MVMCoreUI/Atoms/TextFields/MFTextField.m @@ -181,6 +181,10 @@ return pickedDate; } +- (void)dismissPicker { + [self.textField resignFirstResponder]; +} + - (void)setErrorMessage:(NSString *)errorMessage { [MVMCoreDispatchUtility performBlockOnMainThread:^{