From 0ca77eadc21b45187ee8e06dcfeb6f06b2d7c894 Mon Sep 17 00:00:00 2001 From: "Chintakrinda, Arun Kumar (Arun)" Date: Thu, 9 Jan 2020 18:24:18 +0530 Subject: [PATCH 01/11] Chatbot disable to BD users --- MVMCoreUI/BaseControllers/MFViewController.m | 2 +- MVMCoreUI/OtherHandlers/MVMCoreUISession.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/BaseControllers/MFViewController.m b/MVMCoreUI/BaseControllers/MFViewController.m index 2c8e3997..6484c7ec 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.m +++ b/MVMCoreUI/BaseControllers/MFViewController.m @@ -146,7 +146,7 @@ // Avoid the setter so we are only setting the bool and wait for view will appear to update the navigation bar. _masterShouldBeAccessible = [self isMasterInitiallyAccessible]; - _supportShouldBeAccessible = [self isSupportInitiallyAccessible]; + _supportShouldBeAccessible = ![MVMCoreUISession sharedGlobal].disableSupport && [self isSupportInitiallyAccessible]; // Observe for cache updates if desired. [self observeForResponseJSONUpdates]; diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUISession.h b/MVMCoreUI/OtherHandlers/MVMCoreUISession.h index ca2db26e..ac7b2dbc 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUISession.h +++ b/MVMCoreUI/OtherHandlers/MVMCoreUISession.h @@ -31,6 +31,9 @@ NS_ASSUME_NONNULL_BEGIN //indicates if the app launched successfully @property (assign, nonatomic) BOOL launchAppLoadedSuccessfully; +//indicates if support is enabled +@property (assign, nonatomic) BOOL disableSupport; + // Allows a global overload of the title view of navigation item. - (nullable UIView *)titleViewForController:(nonnull MFViewController *)controller; From c8fcbeaefd82fd50f101b167e62ee89b62129d76 Mon Sep 17 00:00:00 2001 From: panxi Date: Thu, 9 Jan 2020 12:47:03 -0500 Subject: [PATCH 02/11] update right panel view controller --- MVMCoreUI/BaseControllers/MFViewController.m | 2 +- .../MVMCoreUISplitViewController.h | 4 ++++ .../MVMCoreUISplitViewController.m | 20 +++++++++++++++++++ MVMCoreUI/OtherHandlers/MVMCoreUISession.h | 3 --- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/BaseControllers/MFViewController.m b/MVMCoreUI/BaseControllers/MFViewController.m index 6484c7ec..2c8e3997 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.m +++ b/MVMCoreUI/BaseControllers/MFViewController.m @@ -146,7 +146,7 @@ // Avoid the setter so we are only setting the bool and wait for view will appear to update the navigation bar. _masterShouldBeAccessible = [self isMasterInitiallyAccessible]; - _supportShouldBeAccessible = ![MVMCoreUISession sharedGlobal].disableSupport && [self isSupportInitiallyAccessible]; + _supportShouldBeAccessible = [self isSupportInitiallyAccessible]; // Observe for cache updates if desired. [self observeForResponseJSONUpdates]; diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h index af02281d..8c1a7715 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h @@ -120,6 +120,10 @@ typedef NS_ENUM(NSInteger, MFNumberOfDrawers) { - (nullable UIViewController *)createLeftPanelViewController; - (nullable UIViewController *)createRightPanelViewController; +//replace gloabl panel +- (void)updateGlobalLeftPanelViewController:(nullable UIViewController *)leftPanelController; +- (void)updateGlobalRightPanelViewController:(nullable UIViewController *)rightPanelController; + // subclass to change image of back button - (nullable UIImage *)imageForBackButton; diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m index b5177b9b..15dfba04 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m @@ -114,6 +114,14 @@ CGFloat const PanelAnimationDuration = 0.2; return nil; } +- (void)updateGlobalLeftPanelViewController:(nullable UIViewController *)leftPanelController { + self.globalLeftPanel = leftPanelController; +} + +- (void)updateGlobalRightPanelViewController:(nullable UIViewController *)rightPanelController { + self.globalRightPanel = rightPanelController; +} + - (nullable NSArray *)additionalLeftButtons { return nil; } @@ -316,6 +324,9 @@ CGFloat const PanelAnimationDuration = 0.2; } - (void)hideLeftPanelAnimated:(BOOL)animated checkingForOtherExtendedDrawers:(BOOL)checkingForOtherExtendedDrawers { + if (!self.globalLeftPanel) { + return; + } [MVMCoreDispatchUtility performBlockOnMainThread:^{ if (self.mainViewLeading.constant > .1) { if (checkingForOtherExtendedDrawers && self.explictlyShowingPanel == self.leftPanel) { @@ -355,6 +366,9 @@ CGFloat const PanelAnimationDuration = 0.2; } - (void)showLeftPanelAnimated:(BOOL)animated explict:(BOOL)explict { + if (!self.globalLeftPanel) { + return; + } [MVMCoreDispatchUtility performBlockOnMainThread:^{ if (self.mainViewLeading.constant < .1) { BOOL shouldExtendLeftPanel = [self shouldExtendLeftPanel]; @@ -509,6 +523,9 @@ CGFloat const PanelAnimationDuration = 0.2; } - (void)hideRightPanelAnimated:(BOOL)animated checkingForOtherExtendedDrawers:(BOOL)checkingForOtherExtendedDrawers { + if (!self.globalRightPanel) { + return; + } [MVMCoreDispatchUtility performBlockOnMainThread:^{ if (self.mainViewTrailing.constant > .1) { if (checkingForOtherExtendedDrawers && self.explictlyShowingPanel == self.rightPanel) { @@ -548,6 +565,9 @@ CGFloat const PanelAnimationDuration = 0.2; } - (void)showRightPanelAnimated:(BOOL)animated explict:(BOOL)explict { + if (!self.globalRightPanel) { + return; + } [MVMCoreDispatchUtility performBlockOnMainThread:^{ if (self.mainViewTrailing.constant < .1) { BOOL shouldExtendRightPanel = [self shouldExtendRightPanel]; diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUISession.h b/MVMCoreUI/OtherHandlers/MVMCoreUISession.h index ac7b2dbc..ca2db26e 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUISession.h +++ b/MVMCoreUI/OtherHandlers/MVMCoreUISession.h @@ -31,9 +31,6 @@ NS_ASSUME_NONNULL_BEGIN //indicates if the app launched successfully @property (assign, nonatomic) BOOL launchAppLoadedSuccessfully; -//indicates if support is enabled -@property (assign, nonatomic) BOOL disableSupport; - // Allows a global overload of the title view of navigation item. - (nullable UIView *)titleViewForController:(nonnull MFViewController *)controller; From cedcc6b0998bfc94152f6b223708986877c3953d Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 21 Jan 2020 10:24:20 -0500 Subject: [PATCH 03/11] AccessibilityCustomAction requires more than an empty string. --- MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift b/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift index 070cc0f7..c8484829 100644 --- a/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift +++ b/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift @@ -66,7 +66,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt } else { guard let label = label else { return } - let accessibleAction = UIAccessibilityCustomAction(name: actionText ?? "", target: label, selector: #selector(label.accessibilityCustomAction(_:))) + let accessibleAction = UIAccessibilityCustomAction(name: actionText ?? "label", target: label, selector: #selector(label.accessibilityCustomAction(_:))) label.clauses = [Label.ActionableClause(range: actionRange, actionBlock: newActionBlock, accessibilityID: accessibleAction.hash)] label.accessibilityCustomActions = [accessibleAction] From 8816a06fe5c7eea7412cfbf60cdc84a950fb157d Mon Sep 17 00:00:00 2001 From: "Xinlei(Ryan) Pan" Date: Tue, 21 Jan 2020 11:58:08 -0500 Subject: [PATCH 04/11] public globalLeftPanel/globalRightPanel --- .../MVMCoreUISplitViewController.h | 15 +++++---- .../MVMCoreUISplitViewController.m | 33 ++++++------------- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h index 8c1a7715..1a72a190 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h @@ -24,8 +24,12 @@ typedef NS_ENUM(NSInteger, MFNumberOfDrawers) { @interface MVMCoreUISplitViewController : UIViewController // Reference to the panels. -@property (nullable, weak, nonatomic, readonly) UIViewController *leftPanel; -@property (nullable, weak, nonatomic, readonly) UIViewController *rightPanel; +@property (nullable, weak, nonatomic) UIViewController *leftPanel; +@property (nullable, weak, nonatomic) UIViewController *rightPanel; + +// For keeping +@property (nullable, strong, nonatomic) UIViewController *globalLeftPanel; +@property (nullable, strong, nonatomic) UIViewController *globalRightPanel; // Can be of protocol MVMCoreUIPanelButtonProtocol @property (nullable, strong, nonatomic) UIBarButtonItem *leftPanelButton; @@ -79,6 +83,9 @@ typedef NS_ENUM(NSInteger, MFNumberOfDrawers) { // contains speicaly logic to set the icon color - (void)setNavigationIconColor:(nullable UIColor *)color; +///create right and left panel. if left and right panel is already created, will replace them +- (void)createPanels; + /// Updates the panels that are used. - (void)setupPanels; @@ -120,10 +127,6 @@ typedef NS_ENUM(NSInteger, MFNumberOfDrawers) { - (nullable UIViewController *)createLeftPanelViewController; - (nullable UIViewController *)createRightPanelViewController; -//replace gloabl panel -- (void)updateGlobalLeftPanelViewController:(nullable UIViewController *)leftPanelController; -- (void)updateGlobalRightPanelViewController:(nullable UIViewController *)rightPanelController; - // subclass to change image of back button - (nullable UIImage *)imageForBackButton; diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m index 15dfba04..cd36d2a7 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m @@ -44,12 +44,6 @@ typedef NS_OPTIONS(NSInteger, MFExtendedDrawer) { @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) NavigationController *navigationController; // A view that covers the detail view when the master is out. @@ -114,14 +108,6 @@ CGFloat const PanelAnimationDuration = 0.2; return nil; } -- (void)updateGlobalLeftPanelViewController:(nullable UIViewController *)leftPanelController { - self.globalLeftPanel = leftPanelController; -} - -- (void)updateGlobalRightPanelViewController:(nullable UIViewController *)rightPanelController { - self.globalRightPanel = rightPanelController; -} - - (nullable NSArray *)additionalLeftButtons { return nil; } @@ -366,7 +352,7 @@ CGFloat const PanelAnimationDuration = 0.2; } - (void)showLeftPanelAnimated:(BOOL)animated explict:(BOOL)explict { - if (!self.globalLeftPanel) { + if (!self.leftPanel) { return; } [MVMCoreDispatchUtility performBlockOnMainThread:^{ @@ -523,9 +509,6 @@ CGFloat const PanelAnimationDuration = 0.2; } - (void)hideRightPanelAnimated:(BOOL)animated checkingForOtherExtendedDrawers:(BOOL)checkingForOtherExtendedDrawers { - if (!self.globalRightPanel) { - return; - } [MVMCoreDispatchUtility performBlockOnMainThread:^{ if (self.mainViewTrailing.constant > .1) { if (checkingForOtherExtendedDrawers && self.explictlyShowingPanel == self.rightPanel) { @@ -565,7 +548,7 @@ CGFloat const PanelAnimationDuration = 0.2; } - (void)showRightPanelAnimated:(BOOL)animated explict:(BOOL)explict { - if (!self.globalRightPanel) { + if (!self.rightPanel) { return; } [MVMCoreDispatchUtility performBlockOnMainThread:^{ @@ -786,6 +769,13 @@ CGFloat const PanelAnimationDuration = 0.2; } } +- (void)createPanels { + // Create panels + self.globalLeftPanel = [self createLeftPanelViewController]; + self.globalRightPanel = [self createRightPanelViewController]; + [self setupPanels]; +} + - (void)setupPanels { [self forceHideBothDrawers]; [self setupLeftPanel]; @@ -882,10 +872,7 @@ 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; - // Create panels - self.globalLeftPanel = [self createLeftPanelViewController]; - self.globalRightPanel = [self createRightPanelViewController]; - [self setupPanels]; + [self createPanels]; } - (void)viewDidLoad { From 2de914296971535b04922faa30c3401a6199555c Mon Sep 17 00:00:00 2001 From: "Xinlei(Ryan) Pan" Date: Tue, 21 Jan 2020 12:00:28 -0500 Subject: [PATCH 05/11] remove one more line --- .../SplitViewController/MVMCoreUISplitViewController.m | 3 --- 1 file changed, 3 deletions(-) diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m index cd36d2a7..93aeb6fd 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m @@ -310,9 +310,6 @@ CGFloat const PanelAnimationDuration = 0.2; } - (void)hideLeftPanelAnimated:(BOOL)animated checkingForOtherExtendedDrawers:(BOOL)checkingForOtherExtendedDrawers { - if (!self.globalLeftPanel) { - return; - } [MVMCoreDispatchUtility performBlockOnMainThread:^{ if (self.mainViewLeading.constant > .1) { if (checkingForOtherExtendedDrawers && self.explictlyShowingPanel == self.leftPanel) { From 74b09fa51dde634a5fddc7fbff3cf046b5fa29a0 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 21 Jan 2020 15:47:02 -0500 Subject: [PATCH 06/11] name change --- MVMCoreUI/Atoms/Buttons/ButtonModel.swift | 4 ++-- MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift | 4 ++-- MVMCoreUI/Atoms/Buttons/LinkModel.swift | 4 ++-- MVMCoreUI/Atoms/Buttons/MFCustomButton+ActionModel.swift | 2 +- MVMCoreUI/Atoms/Views/Label/LabelAttributeActionModel.swift | 2 +- MVMCoreUI/Atoms/Views/ToggleModel.swift | 2 +- MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift | 4 ++-- MVMCoreUI/Molecules/Items/ListItemModel.swift | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/ButtonModel.swift b/MVMCoreUI/Atoms/Buttons/ButtonModel.swift index 531859c0..c9a7f2f8 100644 --- a/MVMCoreUI/Atoms/Buttons/ButtonModel.swift +++ b/MVMCoreUI/Atoms/Buttons/ButtonModel.swift @@ -22,13 +22,13 @@ public class ButtonModel: MoleculeModelProtocol { public static var identifier: String = "button" public var backgroundColor: Color? public var title: String - public var action: ActionProtocol + public var action: ActionModelProtocol public var style: ButtonStyle? public var size: ButtonSize? = .standard public var required: Bool? public var requiredGroups: [String]? - init(with title: String, action: ActionProtocol) { + init(with title: String, action: ActionModelProtocol) { self.title = title self.action = action } diff --git a/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift b/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift index 3612c1fc..04b5aa07 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift @@ -13,12 +13,12 @@ public class CaretLinkModel: MoleculeModelProtocol { public static var identifier: String = "caretLink" public var backgroundColor: Color? public var title: String - public var action: ActionProtocol + public var action: ActionModelProtocol public var enabledColor: Color = Color(uiColor: .black) public var disabledColor: Color? = Color(uiColor: .mfSilver()) public var enabled: Bool = true - public init(title: String, action: ActionProtocol) { + public init(title: String, action: ActionModelProtocol) { self.title = title self.action = action } diff --git a/MVMCoreUI/Atoms/Buttons/LinkModel.swift b/MVMCoreUI/Atoms/Buttons/LinkModel.swift index 27cbd6c6..0c797b21 100644 --- a/MVMCoreUI/Atoms/Buttons/LinkModel.swift +++ b/MVMCoreUI/Atoms/Buttons/LinkModel.swift @@ -12,11 +12,11 @@ public class LinkModel: MoleculeModelProtocol { public static var identifier: String = "link" public var backgroundColor: Color? public var title: String - public var action: ActionProtocol + public var action: ActionModelProtocol public var enabled = true public var textColor = Color(uiColor: .mfTextButton()) - public init(title: String, action: ActionProtocol) { + public init(title: String, action: ActionModelProtocol) { self.title = title self.action = action } diff --git a/MVMCoreUI/Atoms/Buttons/MFCustomButton+ActionModel.swift b/MVMCoreUI/Atoms/Buttons/MFCustomButton+ActionModel.swift index b967db48..d008a7fb 100644 --- a/MVMCoreUI/Atoms/Buttons/MFCustomButton+ActionModel.swift +++ b/MVMCoreUI/Atoms/Buttons/MFCustomButton+ActionModel.swift @@ -9,7 +9,7 @@ import Foundation public extension MFCustomButton { - func set(with action: ActionProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + func set(with action: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { buttonDelegate = delegateObject?.buttonDelegate add({ [weak self] sender in guard let self = self else { return } diff --git a/MVMCoreUI/Atoms/Views/Label/LabelAttributeActionModel.swift b/MVMCoreUI/Atoms/Views/Label/LabelAttributeActionModel.swift index 8dd5c562..2ebcb4b4 100644 --- a/MVMCoreUI/Atoms/Views/Label/LabelAttributeActionModel.swift +++ b/MVMCoreUI/Atoms/Views/Label/LabelAttributeActionModel.swift @@ -12,7 +12,7 @@ class LabelAttributeActionModel: LabelAttributeModel { override public class var identifier: String { return "action" } - var action: ActionProtocol + var action: ActionModelProtocol required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) diff --git a/MVMCoreUI/Atoms/Views/ToggleModel.swift b/MVMCoreUI/Atoms/Views/ToggleModel.swift index 12706a49..75fddd28 100644 --- a/MVMCoreUI/Atoms/Views/ToggleModel.swift +++ b/MVMCoreUI/Atoms/Views/ToggleModel.swift @@ -13,7 +13,7 @@ public class ToggleModel: MoleculeModelProtocol { public var moleculeName: String? public var backgroundColor: Color? public var state: Bool = true - public var action: ActionProtocol? + public var action: ActionModelProtocol? public var required: Bool? public var fieldKey: String? diff --git a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift index 857bd060..9d424a2b 100644 --- a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift @@ -10,14 +10,14 @@ import Foundation public protocol ListItemModelProtocol: ContainerModelProtocol, MoleculeModelProtocol { var line: LineModel? { get set } - var action: ActionProtocol? { get set } + var action: ActionModelProtocol? { get set } var hideArrow: Bool? { get set } var style: String? { get set } } // Not a strict requirement. extension ListItemModelProtocol { - public var action: ActionProtocol? { + public var action: ActionModelProtocol? { get { return nil } diff --git a/MVMCoreUI/Molecules/Items/ListItemModel.swift b/MVMCoreUI/Molecules/Items/ListItemModel.swift index 97fef586..5356ce25 100644 --- a/MVMCoreUI/Molecules/Items/ListItemModel.swift +++ b/MVMCoreUI/Molecules/Items/ListItemModel.swift @@ -12,7 +12,7 @@ import MVMCore @objcMembers public class ListItemModel: MoleculeContainerModel, ListItemModelProtocol { public static var identifier: String = "listItem" public var backgroundColor: Color? - public var action: ActionProtocol? + public var action: ActionModelProtocol? public var hideArrow: Bool? public var line: LineModel? public var style: String? = "standard" From 117c112b6ba089e77d4a392e8bf73e967bf360c0 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 21 Jan 2020 18:13:42 -0500 Subject: [PATCH 07/11] color --- MVMCoreUI/Atoms/Views/LineModel.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/LineModel.swift b/MVMCoreUI/Atoms/Views/LineModel.swift index 8f16d22e..f481d4d5 100644 --- a/MVMCoreUI/Atoms/Views/LineModel.swift +++ b/MVMCoreUI/Atoms/Views/LineModel.swift @@ -43,6 +43,7 @@ import UIKit public static var identifier: String = "line" public var type: Style = .standard public var frequency: Frequency? = .allExceptTop + public var color: Color? public var backgroundColor: Color? public init(type: Style) { @@ -53,6 +54,7 @@ import UIKit case moleculeName case type case backgroundColor + case color case frequency } @@ -64,7 +66,7 @@ import UIKit if let frequency = try typeContainer.decodeIfPresent(Frequency.self, forKey: .frequency) { self.frequency = frequency } - backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + color = try typeContainer.decodeIfPresent(Color.self, forKey: .color) } public func encode(to encoder: Encoder) throws { @@ -72,6 +74,6 @@ import UIKit try container.encode(moleculeName, forKey: .moleculeName) try container.encode(type, forKey: .type) try container.encodeIfPresent(frequency, forKey: .frequency) - try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(color, forKey: .color) } } From 4d155b9f97aceda27904a1d0a90f20e35948e3cc Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 21 Jan 2020 18:23:32 -0500 Subject: [PATCH 08/11] ActionModelProtocol --- MVMCoreUI/Atoms/Buttons/ButtonModel.swift | 4 ++-- MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift | 4 ++-- MVMCoreUI/Atoms/Buttons/LinkModel.swift | 4 ++-- MVMCoreUI/Atoms/Buttons/MFCustomButton+ActionModel.swift | 2 +- MVMCoreUI/Atoms/Views/Label/LabelAttributeActionModel.swift | 2 +- MVMCoreUI/Atoms/Views/ToggleModel.swift | 2 +- MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift | 4 ++-- MVMCoreUI/Molecules/Items/ListItemModel.swift | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/ButtonModel.swift b/MVMCoreUI/Atoms/Buttons/ButtonModel.swift index 531859c0..c9a7f2f8 100644 --- a/MVMCoreUI/Atoms/Buttons/ButtonModel.swift +++ b/MVMCoreUI/Atoms/Buttons/ButtonModel.swift @@ -22,13 +22,13 @@ public class ButtonModel: MoleculeModelProtocol { public static var identifier: String = "button" public var backgroundColor: Color? public var title: String - public var action: ActionProtocol + public var action: ActionModelProtocol public var style: ButtonStyle? public var size: ButtonSize? = .standard public var required: Bool? public var requiredGroups: [String]? - init(with title: String, action: ActionProtocol) { + init(with title: String, action: ActionModelProtocol) { self.title = title self.action = action } diff --git a/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift b/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift index 3612c1fc..04b5aa07 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift @@ -13,12 +13,12 @@ public class CaretLinkModel: MoleculeModelProtocol { public static var identifier: String = "caretLink" public var backgroundColor: Color? public var title: String - public var action: ActionProtocol + public var action: ActionModelProtocol public var enabledColor: Color = Color(uiColor: .black) public var disabledColor: Color? = Color(uiColor: .mfSilver()) public var enabled: Bool = true - public init(title: String, action: ActionProtocol) { + public init(title: String, action: ActionModelProtocol) { self.title = title self.action = action } diff --git a/MVMCoreUI/Atoms/Buttons/LinkModel.swift b/MVMCoreUI/Atoms/Buttons/LinkModel.swift index 27cbd6c6..0c797b21 100644 --- a/MVMCoreUI/Atoms/Buttons/LinkModel.swift +++ b/MVMCoreUI/Atoms/Buttons/LinkModel.swift @@ -12,11 +12,11 @@ public class LinkModel: MoleculeModelProtocol { public static var identifier: String = "link" public var backgroundColor: Color? public var title: String - public var action: ActionProtocol + public var action: ActionModelProtocol public var enabled = true public var textColor = Color(uiColor: .mfTextButton()) - public init(title: String, action: ActionProtocol) { + public init(title: String, action: ActionModelProtocol) { self.title = title self.action = action } diff --git a/MVMCoreUI/Atoms/Buttons/MFCustomButton+ActionModel.swift b/MVMCoreUI/Atoms/Buttons/MFCustomButton+ActionModel.swift index b967db48..d008a7fb 100644 --- a/MVMCoreUI/Atoms/Buttons/MFCustomButton+ActionModel.swift +++ b/MVMCoreUI/Atoms/Buttons/MFCustomButton+ActionModel.swift @@ -9,7 +9,7 @@ import Foundation public extension MFCustomButton { - func set(with action: ActionProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + func set(with action: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { buttonDelegate = delegateObject?.buttonDelegate add({ [weak self] sender in guard let self = self else { return } diff --git a/MVMCoreUI/Atoms/Views/Label/LabelAttributeActionModel.swift b/MVMCoreUI/Atoms/Views/Label/LabelAttributeActionModel.swift index 8dd5c562..2ebcb4b4 100644 --- a/MVMCoreUI/Atoms/Views/Label/LabelAttributeActionModel.swift +++ b/MVMCoreUI/Atoms/Views/Label/LabelAttributeActionModel.swift @@ -12,7 +12,7 @@ class LabelAttributeActionModel: LabelAttributeModel { override public class var identifier: String { return "action" } - var action: ActionProtocol + var action: ActionModelProtocol required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) diff --git a/MVMCoreUI/Atoms/Views/ToggleModel.swift b/MVMCoreUI/Atoms/Views/ToggleModel.swift index 12706a49..75fddd28 100644 --- a/MVMCoreUI/Atoms/Views/ToggleModel.swift +++ b/MVMCoreUI/Atoms/Views/ToggleModel.swift @@ -13,7 +13,7 @@ public class ToggleModel: MoleculeModelProtocol { public var moleculeName: String? public var backgroundColor: Color? public var state: Bool = true - public var action: ActionProtocol? + public var action: ActionModelProtocol? public var required: Bool? public var fieldKey: String? diff --git a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift index 857bd060..9d424a2b 100644 --- a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift @@ -10,14 +10,14 @@ import Foundation public protocol ListItemModelProtocol: ContainerModelProtocol, MoleculeModelProtocol { var line: LineModel? { get set } - var action: ActionProtocol? { get set } + var action: ActionModelProtocol? { get set } var hideArrow: Bool? { get set } var style: String? { get set } } // Not a strict requirement. extension ListItemModelProtocol { - public var action: ActionProtocol? { + public var action: ActionModelProtocol? { get { return nil } diff --git a/MVMCoreUI/Molecules/Items/ListItemModel.swift b/MVMCoreUI/Molecules/Items/ListItemModel.swift index 97fef586..5356ce25 100644 --- a/MVMCoreUI/Molecules/Items/ListItemModel.swift +++ b/MVMCoreUI/Molecules/Items/ListItemModel.swift @@ -12,7 +12,7 @@ import MVMCore @objcMembers public class ListItemModel: MoleculeContainerModel, ListItemModelProtocol { public static var identifier: String = "listItem" public var backgroundColor: Color? - public var action: ActionProtocol? + public var action: ActionModelProtocol? public var hideArrow: Bool? public var line: LineModel? public var style: String? = "standard" From 943799d462372e20184f07e03150a06c221acab9 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 21 Jan 2020 23:33:24 -0500 Subject: [PATCH 09/11] more models --- MVMCoreUI.xcodeproj/project.pbxproj | 4 ++++ MVMCoreUI/Atoms/Views/ToggleModel.swift | 4 ++++ .../SwitchMolecules/HeadlineBodySwitch.swift | 20 ++++++++++------- .../HeadlineBodyToggleModel.swift | 22 +++++++++++++++++++ .../HeadlineBodyModel.swift | 3 +-- .../OtherHandlers/MoleculeObjectMapping.swift | 1 + 6 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodyToggleModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index d9591c22..65129935 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 01004F3022721C3800991ECC /* RadioButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01004F2F22721C3800991ECC /* RadioButton.swift */; }; + 0103B84E23D7E33A009C315C /* HeadlineBodyToggleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0103B84D23D7E33A009C315C /* HeadlineBodyToggleModel.swift */; }; 0105618D224BBE7700E1557D /* FormValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618A224BBE7700E1557D /* FormValidator.swift */; }; 0105618E224BBE7700E1557D /* FormValidator+TextFields.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */; }; 0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */; }; @@ -310,6 +311,7 @@ /* Begin PBXFileReference section */ 01004F2F22721C3800991ECC /* RadioButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioButton.swift; sourceTree = ""; }; + 0103B84D23D7E33A009C315C /* HeadlineBodyToggleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadlineBodyToggleModel.swift; sourceTree = ""; }; 0105618A224BBE7700E1557D /* FormValidator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidator.swift; sourceTree = ""; }; 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+TextFields.swift"; sourceTree = ""; }; 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+FormParams.swift"; sourceTree = ""; }; @@ -809,6 +811,7 @@ 01C851D223CF9E740021F976 /* LabelToggleModel.swift */, D22479892314445E003FCCF9 /* LabelSwitch.swift */, D224798B231450C8003FCCF9 /* HeadlineBodySwitch.swift */, + 0103B84D23D7E33A009C315C /* HeadlineBodyToggleModel.swift */, ); path = SwitchMolecules; sourceTree = ""; @@ -1540,6 +1543,7 @@ D29DF2A221E7AF4E003B2FB9 /* MVMCoreUIUtility.m in Sources */, D29DF12B21E6851E003B2FB9 /* MVMCoreUITopAlertExpandableView.m in Sources */, 94C2D9A723872DA90006CF46 /* LabelAttributeColorModel.swift in Sources */, + 0103B84E23D7E33A009C315C /* HeadlineBodyToggleModel.swift in Sources */, D2755D7B23689C7500485468 /* TableViewCell.swift in Sources */, 0A21DB85235E06EF00C160A2 /* MFTextField.m in Sources */, 014AA72623C501E2006F3E93 /* ContainerModelProtocol.swift in Sources */, diff --git a/MVMCoreUI/Atoms/Views/ToggleModel.swift b/MVMCoreUI/Atoms/Views/ToggleModel.swift index 75fddd28..9cd96f45 100644 --- a/MVMCoreUI/Atoms/Views/ToggleModel.swift +++ b/MVMCoreUI/Atoms/Views/ToggleModel.swift @@ -14,6 +14,7 @@ public class ToggleModel: MoleculeModelProtocol { public var backgroundColor: Color? public var state: Bool = true public var action: ActionModelProtocol? + public var alternateAction: ActionModelProtocol? public var required: Bool? public var fieldKey: String? @@ -24,6 +25,7 @@ public class ToggleModel: MoleculeModelProtocol { case backgroundColor case required case fieldKey + case alternateAction } public init(_ state: Bool) { @@ -36,6 +38,7 @@ public class ToggleModel: MoleculeModelProtocol { self.state = state } action = try typeContainer.decodeModelIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.actionType) + alternateAction = try typeContainer.decodeModelIfPresent(codingKey: .alternateAction, typeCodingKey: ActionCodingKey.actionType) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) required = try typeContainer.decodeIfPresent(Bool.self, forKey: .required) fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey) @@ -45,6 +48,7 @@ public class ToggleModel: MoleculeModelProtocol { var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeModelIfPresent(action, forKey: .action) + try container.encodeModelIfPresent(alternateAction, forKey: .alternateAction) try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(state, forKey: .state) try container.encodeIfPresent(required, forKey: .required) diff --git a/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift b/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift index 79e2a9ec..09432dce 100644 --- a/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift +++ b/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift @@ -10,18 +10,18 @@ import UIKit @objcMembers open class HeadlineBodySwitch: View { public let headlineBody = HeadlineBody(frame: .zero) - public let mvmSwitch = MVMCoreUISwitch.mvmSwitchDefault() + public let toggle = Toggle() // MARK: - MVMCoreViewProtocol open override func updateView(_ size: CGFloat) { super.updateView(size) headlineBody.updateView(size) - mvmSwitch.updateView(size) + toggle.updateView(size) } open override func setupView() { super.setupView() - guard mvmSwitch.superview == nil else { + guard toggle.superview == nil else { return } headlineBody.styleListItem() @@ -30,8 +30,8 @@ import UIKit NSLayoutConstraint.constraintPinSubview(toSuperview: view) view.addSubview(headlineBody) - view.addSubview(mvmSwitch) - NSLayoutConstraint.pinSubviewsCenter(leftView: headlineBody, rightView: mvmSwitch) + view.addSubview(toggle) + NSLayoutConstraint.pinSubviewsCenter(leftView: headlineBody, rightView: toggle) } @@ -39,6 +39,10 @@ import UIKit open override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.setWithModel(model, delegateObject, additionalData) + guard let headlineBodyToggleModel = model as? HeadlineBodyToggleModel else { + return + } + setWithJSON(headlineBodyToggleModel.toJSON(), delegateObject: delegateObject, additionalData: additionalData) } public class override func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { @@ -50,7 +54,7 @@ import UIKit open override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) headlineBody.setWithJSON(json?.optionalDictionaryForKey("headlineBody"), delegateObject: delegateObject, additionalData: additionalData) - mvmSwitch.setWithJSON(json?.optionalDictionaryForKey("toggle"), delegateObject: delegateObject, additionalData: additionalData) + toggle.setWithJSON(json?.optionalDictionaryForKey("toggle"), delegateObject: delegateObject, additionalData: additionalData) } open class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { @@ -59,14 +63,14 @@ import UIKit open override func setAsMolecule() { headlineBody.setAsMolecule() - (mvmSwitch as MVMCoreUIMoleculeViewProtocol).setAsMolecule?() + (toggle as MVMCoreUIMoleculeViewProtocol).setAsMolecule?() headlineBody.styleListItem() } open override func reset() { super.reset() headlineBody.reset() - (mvmSwitch as MVMCoreUIMoleculeViewProtocol).reset?() + (toggle as MVMCoreUIMoleculeViewProtocol).reset?() headlineBody.styleListItem() } } diff --git a/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodyToggleModel.swift b/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodyToggleModel.swift new file mode 100644 index 00000000..dd7c2b1c --- /dev/null +++ b/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodyToggleModel.swift @@ -0,0 +1,22 @@ +// +// HeadlineBodyToggleModel.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 1/21/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + + +open class HeadlineBodyToggleModel: MoleculeModelProtocol { + public static var identifier: String = "headlineBodyToggle" + open var backgroundColor: Color? + open var headlineBody: HeadlineBodyModel + open var toggle: ToggleModel + + public init(_ headlineBody: HeadlineBodyModel, _ toggle: ToggleModel) { + self.headlineBody = headlineBody + self.toggle = toggle + } +} diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift index 86151cb6..fc22f864 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift @@ -15,9 +15,8 @@ import Foundation public var style: String? public var backgroundColor: Color? - public init(headline: LabelModel, body: LabelModel) { + public init(headline: LabelModel) { self.headline = headline - self.body = body } } diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index b12145f2..2e31a757 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -70,5 +70,6 @@ import Foundation ModelRegistry.register(DoughnutChartModel.self) ModelRegistry.register(NumberedListModel.self) ModelRegistry.register(UnOrderedListModel.self) + ModelRegistry.register(HeadlineBodyToggleModel.self) } } From 00d1bf7be6709adebc3987ea215af2ba96be7dec Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 22 Jan 2020 09:11:56 -0500 Subject: [PATCH 10/11] re-organizing --- MVMCoreUI.xcodeproj/project.pbxproj | 14 ++----- .../Molecules/Items/CarouselItemModel.swift | 6 +-- MVMCoreUI/Molecules/ModuleMoleculeModel.swift | 2 +- MVMCoreUI/Organisms/Carousel.swift | 41 ++++++++----------- MVMCoreUI/Organisms/CarouselModel.swift | 2 +- 5 files changed, 24 insertions(+), 41 deletions(-) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 65129935..3371e6ca 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -658,7 +658,6 @@ children = ( 011B58EE23A2AA850085F53C /* ModelProtocols */, 946EE1B5237B663A0036751F /* Extensions */, - 01EB368723609801006832FA /* Molecules */, ); path = Models; sourceTree = ""; @@ -674,16 +673,6 @@ path = FormUIHelpers; sourceTree = ""; }; - 01EB368723609801006832FA /* Molecules */ = { - isa = PBXGroup; - children = ( - 012A88AE238C626E00FE3DA1 /* CarouselModel.swift */, - 012A88C1238D7BCA00FE3DA1 /* CarouselItemModel.swift */, - 012A88C5238DA34000FE3DA1 /* ModuleMoleculeModel.swift */, - ); - path = Molecules; - sourceTree = ""; - }; 0A5D59C323AD488600EFD9E9 /* Protocols */ = { isa = PBXGroup; children = ( @@ -859,6 +848,7 @@ D260105C23D0BCD400764D80 /* Stack.swift */, 01EB368B23609801006832FA /* MoleculeStackModel.swift */, D2A5145E2211DDC100345BFB /* MoleculeStackView.swift */, + 012A88AE238C626E00FE3DA1 /* CarouselModel.swift */, D2A6390022CBB1820052ED1F /* Carousel.swift */, ); path = Organisms; @@ -870,6 +860,7 @@ D2755D7A23689C7500485468 /* TableViewCell.swift */, 01EB368923609801006832FA /* ListItemModel.swift */, 01509D8E2327EC6F00EF99AA /* MoleculeTableViewCell.swift */, + 012A88C1238D7BCA00FE3DA1 /* CarouselItemModel.swift */, D2A6390422CBCE160052ED1F /* MoleculeCollectionViewCell.swift */, D28A838023CCB0D800DFE4FC /* AccordionListItemModel.swift */, D224799A231965AD003FCCF9 /* AccordionMoleculeTableViewCell.swift */, @@ -998,6 +989,7 @@ 012A88EB238F084D00FE3DA1 /* FooterModel.swift */, D274CA322236A78900B01B62 /* FooterView.swift */, 0116A4E4228B19640094F3ED /* RadioButtonModel.swift */, + 012A88C5238DA34000FE3DA1 /* ModuleMoleculeModel.swift */, D29B770F22C281F400D6ACE0 /* ModuleMolecule.swift */, D28A838423CCCA8900DFE4FC /* ScrollerModel.swift */, D2D6CD3F22E78C1A00D701B8 /* Scroller.swift */, diff --git a/MVMCoreUI/Molecules/Items/CarouselItemModel.swift b/MVMCoreUI/Molecules/Items/CarouselItemModel.swift index a5fc0e85..8f7eea64 100644 --- a/MVMCoreUI/Molecules/Items/CarouselItemModel.swift +++ b/MVMCoreUI/Molecules/Items/CarouselItemModel.swift @@ -15,14 +15,14 @@ import Foundation public var peakingUI: Bool? public var peakingArrowColor: Color? - enum CarouselItemCodingKeys: String, CodingKey { + private enum CodingKeys: String, CodingKey { case backgroundColor case peakingUI case peakingArrowColor } required public init(from decoder: Decoder) throws { - let typeContainer = try decoder.container(keyedBy: CarouselItemCodingKeys.self) + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) peakingUI = try typeContainer.decodeIfPresent(Bool.self, forKey: .peakingUI) peakingArrowColor = try typeContainer.decodeIfPresent(Color.self, forKey: .peakingArrowColor) @@ -31,7 +31,7 @@ import Foundation public override func encode(to encoder: Encoder) throws { try super.encode(to: encoder) - var container = encoder.container(keyedBy: CarouselItemCodingKeys.self) + var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(peakingUI, forKey: .peakingUI) try container.encodeIfPresent(peakingArrowColor, forKey: .peakingArrowColor) diff --git a/MVMCoreUI/Molecules/ModuleMoleculeModel.swift b/MVMCoreUI/Molecules/ModuleMoleculeModel.swift index 02e319e9..931e7c04 100644 --- a/MVMCoreUI/Molecules/ModuleMoleculeModel.swift +++ b/MVMCoreUI/Molecules/ModuleMoleculeModel.swift @@ -13,7 +13,7 @@ open class ModuleMoleculeModel: MoleculeModelProtocol { public static var identifier: String = "moduleMolecule" public var moduleName: String - enum CodingKeys: String, CodingKey { + private enum CodingKeys: String, CodingKey { case moduleName } diff --git a/MVMCoreUI/Organisms/Carousel.swift b/MVMCoreUI/Organisms/Carousel.swift index f1aae075..59911594 100644 --- a/MVMCoreUI/Organisms/Carousel.swift +++ b/MVMCoreUI/Organisms/Carousel.swift @@ -8,7 +8,7 @@ import UIKit -open class Carousel: ViewConstrainingView, ModelMoleculeViewProtocol { +open class Carousel: View { let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()) @@ -47,6 +47,9 @@ open class Carousel: ViewConstrainingView, ModelMoleculeViewProtocol { var loop = false private var dragging = false + // For adding pager + private var bottomPin: NSLayoutConstraint? + // MARK: - MVMCoreViewProtocol open override func setupView() { super.setupView() @@ -60,7 +63,7 @@ open class Carousel: ViewConstrainingView, ModelMoleculeViewProtocol { collectionView.backgroundColor = .clear collectionView.isAccessibilityElement = false addSubview(collectionView) - pinView(toSuperView: collectionView) + bottomPin = NSLayoutConstraint.constraintPinSubview(toSuperview: collectionView)?[ConstraintBot] as? NSLayoutConstraint collectionViewHeight = collectionView.heightAnchor.constraint(equalToConstant: 300) collectionViewHeight?.isActive = false @@ -81,40 +84,28 @@ open class Carousel: ViewConstrainingView, ModelMoleculeViewProtocol { // MARK: - MVMCoreUIMoleculeViewProtocol //TODO: Model, Change to model - public func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { - guard let caroselModel = model as? CarouselModel else { - return - } - - #warning("This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView.") - //TODO: This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView. - setUpDefaultWithModel(model, delegateObject, additionalData) - + public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + super.setWithModel(model, delegateObject, additionalData) + guard let carouselModel = model as? CarouselModel else { return } collectionView.backgroundColor = backgroundColor collectionView.layer.borderColor = backgroundColor?.cgColor - collectionView.layer.borderWidth = (caroselModel.border ?? false) ? 1 : 0 + collectionView.layer.borderWidth = (carouselModel.border ?? false) ? 1 : 0 backgroundColor = .white - registerCells(with: caroselModel, delegateObject: delegateObject) - setupLayout(with: caroselModel) - prepareMolecules(with: caroselModel) - itemWidthPercent = (caroselModel.itemWidthPercent ?? 100) / 100 - setAlignment(with: caroselModel.itemAlignment) + registerCells(with: carouselModel, delegateObject: delegateObject) + setupLayout(with: carouselModel) + prepareMolecules(with: carouselModel) + itemWidthPercent = (carouselModel.itemWidthPercent ?? 100) / 100 + setAlignment(with: carouselModel.itemAlignment) - if let height = caroselModel.height { + if let height = carouselModel.height { collectionViewHeight?.constant = CGFloat(height) collectionViewHeight?.isActive = true } - setupPagingMolecule(caroselModel.pagingMolecule, delegateObject: delegateObject) + setupPagingMolecule(carouselModel.pagingMolecule, delegateObject: delegateObject) collectionView.reloadData() } - - - open override func shouldSetHorizontalMargins(_ shouldSet: Bool) { - super.shouldSetHorizontalMargins(shouldSet) - updateViewHorizontalDefaults = false - } // MARK: - JSON Setters /// Updates the layout being used diff --git a/MVMCoreUI/Organisms/CarouselModel.swift b/MVMCoreUI/Organisms/CarouselModel.swift index fedb5535..e43e6caa 100644 --- a/MVMCoreUI/Organisms/CarouselModel.swift +++ b/MVMCoreUI/Organisms/CarouselModel.swift @@ -25,7 +25,7 @@ import UIKit self.molecules = molecules } - enum CodingKeys: String, CodingKey { + private enum CodingKeys: String, CodingKey { case moleculeName case backgroundColor case molecules From db0cb77756440d32ce06c0878f850f510f4b3cc0 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 22 Jan 2020 09:22:57 -0500 Subject: [PATCH 11/11] Update button to model --- MVMCoreUI/BaseClasses/Button.swift | 40 +++++------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/MVMCoreUI/BaseClasses/Button.swift b/MVMCoreUI/BaseClasses/Button.swift index 1d5d743e..e0f098be 100644 --- a/MVMCoreUI/BaseClasses/Button.swift +++ b/MVMCoreUI/BaseClasses/Button.swift @@ -8,14 +8,11 @@ public typealias ButtonBlock = (Button) -> () - @objcMembers open class Button: UIButton, MFButtonProtocol { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- - - public var json: [AnyHashable: Any]? - public var actionMap: [AnyHashable: Any]? + public var actionModel: ActionModelProtocol? private var initialSetupPerformed = false @@ -71,44 +68,20 @@ public typealias ButtonBlock = (Button) -> () buttonBlock?(self) } - public func setWithActionMap(_ actionMap: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - self.actionMap = actionMap - + public func setWithAction(_ actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + self.actionModel = actionModel buttonDelegate = delegateObject?.buttonDelegate - addBlock(event: .touchUpInside) { [weak self] sender in guard let self = self else { return } - - if self.buttonDelegate?.button?(self, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true { + if let data = try? actionModel.encode(using: JSONEncoder()), + let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any], + delegateObject?.buttonDelegate?.button?(self, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) } } } } -// MARK: - MVMCoreUIMoleculeViewProtocol -extension Button: MVMCoreUIMoleculeViewProtocol { - - public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - self.json = json - - guard let dictionary = json else { return } - - if let backgroundColorString = dictionary[KeyBackgroundColor] as? String { - backgroundColor = UIColor.mfGet(forHex: backgroundColorString) - } - - if let title = dictionary[KeyTitle] as? String { - setTitle(title, for: .normal) - } - } - - public func reset() { - backgroundColor = .clear - } -} - - // MARK: - MVMCoreViewProtocol extension Button: MVMCoreViewProtocol { @@ -116,7 +89,6 @@ extension Button: MVMCoreViewProtocol { /// Will be called only once. public func setupView() { - translatesAutoresizingMaskIntoConstraints = false insetsLayoutMarginsFromSafeArea = false titleLabel?.numberOfLines = 0