From 3eb6f6c6901df7df4f3792167fe1568e32863605 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Fri, 26 Jun 2020 08:57:42 -0400 Subject: [PATCH 01/11] open list page template model for outside extension. --- MVMCoreUI/Atomic/Templates/ListPageTemplateModel.swift | 6 +++--- MVMCoreUI/Atomic/Templates/TemplateModel.swift | 3 ++- MVMCoreUI/Atomic/Templates/ThreeLayerModelBase.swift | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/MVMCoreUI/Atomic/Templates/ListPageTemplateModel.swift b/MVMCoreUI/Atomic/Templates/ListPageTemplateModel.swift index b239bd81..b2b52573 100644 --- a/MVMCoreUI/Atomic/Templates/ListPageTemplateModel.swift +++ b/MVMCoreUI/Atomic/Templates/ListPageTemplateModel.swift @@ -8,12 +8,12 @@ import Foundation -@objcMembers public class ListPageTemplateModel: ThreeLayerModelBase { +@objcMembers open class ListPageTemplateModel: ThreeLayerModelBase { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- - public override class var identifier: String { + open override class var identifier: String { return "list" } public var molecules: [ListItemModelProtocol & MoleculeModelProtocol]? @@ -49,7 +49,7 @@ import Foundation try super.init(from: decoder) } - public override func encode(to encoder: Encoder) throws { + open override func encode(to encoder: Encoder) throws { try super.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeModelsIfPresent(molecules, forKey: .molecules) diff --git a/MVMCoreUI/Atomic/Templates/TemplateModel.swift b/MVMCoreUI/Atomic/Templates/TemplateModel.swift index 01753414..bb8bb104 100644 --- a/MVMCoreUI/Atomic/Templates/TemplateModel.swift +++ b/MVMCoreUI/Atomic/Templates/TemplateModel.swift @@ -9,7 +9,8 @@ import Foundation -@objcMembers public class TemplateModel: MVMControllerModelProtocol, TabPageModelProtocol { +@objcMembers open class TemplateModel: MVMControllerModelProtocol, TabPageModelProtocol { + //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- diff --git a/MVMCoreUI/Atomic/Templates/ThreeLayerModelBase.swift b/MVMCoreUI/Atomic/Templates/ThreeLayerModelBase.swift index f0276979..1120b0e7 100644 --- a/MVMCoreUI/Atomic/Templates/ThreeLayerModelBase.swift +++ b/MVMCoreUI/Atomic/Templates/ThreeLayerModelBase.swift @@ -8,7 +8,7 @@ import Foundation -@objcMembers public class ThreeLayerModelBase: TemplateModel, ThreeLayerTemplateModelProtocol { +@objcMembers open class ThreeLayerModelBase: TemplateModel, ThreeLayerTemplateModelProtocol { public var anchorHeader: Bool = false public var header: MoleculeModelProtocol? public var anchorFooter: Bool = false From 3edb3dcfe246ee7b19019f03c639b0b272fe9b65 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Fri, 26 Jun 2020 08:58:11 -0400 Subject: [PATCH 02/11] toggle alternateAction handling. --- MVMCoreUI/Atomic/Atoms/Views/Toggle.swift | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Toggle.swift b/MVMCoreUI/Atomic/Atoms/Views/Toggle.swift index 2e50dfca..87373ff4 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Toggle.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Toggle.swift @@ -392,8 +392,23 @@ public typealias ActionBlockConfirmation = () -> (Bool) accessibilityLabel = accessibileString } - if let actionMap = model.action?.toJSON() { - didToggleAction = { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) } + let actionMap = model.action?.toJSON() + let alternateActionMap = model.alternateAction?.toJSON() + if actionMap != nil || alternateActionMap != nil { + didToggleAction = { [weak self] in + guard let strongSelf = self else { return } + if strongSelf.isOn { + if actionMap != nil { + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) + } + } else { + if alternateActionMap != nil { + MVMCoreActionHandler.shared()?.handleAction(with: alternateActionMap, additionalData: additionalData, delegateObject: delegateObject) + } else if actionMap != nil { + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) + } + } + } } } From 1337e87c3de64703292e057a7033f6e0bf4bd65d Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Fri, 26 Jun 2020 08:59:01 -0400 Subject: [PATCH 03/11] move decoding logic to ViewController for overrides. --- MVMCoreUI/Atomic/Protocols/TemplateProtocol.swift | 6 ++++-- MVMCoreUI/BaseControllers/ViewController.swift | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atomic/Protocols/TemplateProtocol.swift b/MVMCoreUI/Atomic/Protocols/TemplateProtocol.swift index 04280042..4e6d5d32 100644 --- a/MVMCoreUI/Atomic/Protocols/TemplateProtocol.swift +++ b/MVMCoreUI/Atomic/Protocols/TemplateProtocol.swift @@ -14,13 +14,15 @@ public protocol TemplateProtocol: AnyObject { } public extension TemplateProtocol where Self: ViewController { + func parseTemplate(json: [AnyHashable: Any]?) throws { guard let pageJSON = json else { return } let data = try JSONSerialization.data(withJSONObject: pageJSON) let decoder = JSONDecoder() try decoder.add(delegateObject: delegateObjectIVar) - let templateModel = try decoder.decode(TemplateModel.self, from: data) - self.templateModel = templateModel + let templateModel = try decodeTemplate(using: decoder, from: data) + self.templateModel = templateModel as? TemplateModel self.pageModel = templateModel as? MVMControllerModelProtocol } + } diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index 6e1b35ff..df604d82 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -130,6 +130,10 @@ import UIKit open func parsePageJSON() throws { } + open func decodeTemplate(using decoder: JSONDecoder, from data: Data) throws -> TemplateModel { + return try decoder.decode(TemplateModel.self, from: data) + } + open class func verifyRequiredModulesLoaded(for loadObject: MVMCoreLoadObject?, error: AutoreleasingUnsafeMutablePointer) -> Bool { guard let pageType = loadObject?.pageType, var modulesRequired = MVMCoreUIViewControllerMappingObject.shared()?.modulesRequired(forPageType: pageType), !modulesRequired.isEmpty else { return true } From 0cb184a41b187876e3468193a37bc91be7ac56bb Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Fri, 26 Jun 2020 20:00:54 -0400 Subject: [PATCH 04/11] Fix methodology of template model subclassing. --- MVMCoreUI/Atomic/Protocols/TemplateProtocol.swift | 13 +++++++++++-- MVMCoreUI/BaseControllers/ViewController.swift | 4 ---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/MVMCoreUI/Atomic/Protocols/TemplateProtocol.swift b/MVMCoreUI/Atomic/Protocols/TemplateProtocol.swift index 4e6d5d32..699c217c 100644 --- a/MVMCoreUI/Atomic/Protocols/TemplateProtocol.swift +++ b/MVMCoreUI/Atomic/Protocols/TemplateProtocol.swift @@ -13,6 +13,10 @@ public protocol TemplateProtocol: AnyObject { var templateModel: TemplateModel? { get set } } +public protocol CustomTemplateDecoder { + func decodeTemplate(using decoder: JSONDecoder, from data: Data) throws -> TemplateModelProtocol +} + public extension TemplateProtocol where Self: ViewController { func parseTemplate(json: [AnyHashable: Any]?) throws { @@ -20,8 +24,13 @@ public extension TemplateProtocol where Self: ViewController { let data = try JSONSerialization.data(withJSONObject: pageJSON) let decoder = JSONDecoder() try decoder.add(delegateObject: delegateObjectIVar) - let templateModel = try decodeTemplate(using: decoder, from: data) - self.templateModel = templateModel as? TemplateModel + let templateModel: TemplateModel + if let customDecoder = self as? CustomTemplateDecoder { + templateModel = try customDecoder.decodeTemplate(using: decoder, from: data) as! Self.TemplateModel + } else { + templateModel = try decoder.decode(TemplateModel.self, from: data) + } + self.templateModel = templateModel self.pageModel = templateModel as? MVMControllerModelProtocol } diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index df604d82..bd8c66f9 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -129,10 +129,6 @@ import UIKit open func parsePageJSON() throws { } - - open func decodeTemplate(using decoder: JSONDecoder, from data: Data) throws -> TemplateModel { - return try decoder.decode(TemplateModel.self, from: data) - } open class func verifyRequiredModulesLoaded(for loadObject: MVMCoreLoadObject?, error: AutoreleasingUnsafeMutablePointer) -> Bool { guard let pageType = loadObject?.pageType, var modulesRequired = MVMCoreUIViewControllerMappingObject.shared()?.modulesRequired(forPageType: pageType), From e7c7351840b3e952ded3a2b9b6d993f61cb103e6 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 29 Jun 2020 11:01:17 -0400 Subject: [PATCH 05/11] separating navigation item setters --- .../BaseControllers/ViewController.swift | 50 +++++++++++++------ .../Containers/NavigationController.swift | 32 +++++++----- ...MCoreUISplitViewController+Extension.swift | 6 +-- 3 files changed, 56 insertions(+), 32 deletions(-) diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index 6e1b35ff..6a585dab 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -94,9 +94,10 @@ import UIKit try parsePageJSON() MVMCoreDispatchUtility.performBlock(onMainThread: { self.handleNewDataAndUpdateUI() - // If the screen is showing, can update the navigation controller. - if MVMCoreUIUtility.getCurrentVisibleController() == self.manager ?? self { - self.setNavigationController() + + // Update navigation bar if showing. + if MVMCoreUIUtility.getCurrentVisibleController() == self { + self.setNavigationBar() } }) } catch { @@ -168,12 +169,6 @@ import UIKit /// Processes any new data. Called after the page is loaded the first time and on response updates for this page, open func handleNewData() { - // TODO: remove legacy. Temporary, convert legacy to navigation model. - if pageModel?.navigationBar == nil { - let navigationItem = createDefaultLegacyNavigationModel() - pageModel?.navigationBar = navigationItem - } - if formValidator == nil { let rules = pageModel?.formRules formValidator = FormValidator(rules) @@ -182,20 +177,43 @@ import UIKit if let backgroundColor = pageModel?.backgroundColor { view.backgroundColor = backgroundColor.uiColor } + + // Sets up the navigation item based on the data. + setNavigationItem() } // MARK: - Navigation Item (Move to model base) - open func setNavigationController() { + + open func getNavigationModel() -> NavigationItemModelProtocol? { + // TODO: remove legacy. Temporary, convert legacy to navigation model. + if pageModel?.navigationBar == nil { + let navigationItem = createDefaultLegacyNavigationModel() + pageModel?.navigationBar = navigationItem + } + return pageModel?.navigationBar + } + + /// Sets the navigation item for this view controller. + open func setNavigationItem() { + guard let navigationItemModel = getNavigationModel(), + let navigationController = navigationController else { return } + + // We additionally want our left items + navigationItem.leftItemsSupplementBackButton = true + + // Utilize helper function to set the navigation item state. + NavigationController.setNavigationItem(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: self) + } + + /// Sets the appearance of the navigation bar based on the model. + open func setNavigationBar() { let viewController = manager ?? self - guard let navigationItemModel = pageModel?.navigationBar, + guard let navigationItemModel = getNavigationModel(), let navigationController = viewController.navigationController else { MVMCoreUISession.sharedGlobal()?.splitViewController?.parent?.setNeedsStatusBarAppearanceUpdate() return } - // We additionally want our left items - navigationItem.leftItemsSupplementBackButton = true - // Utilize helper function to set the split view and navigation item state. MVMCoreUISplitViewController.setSplitViewController(for: viewController, navigationController: navigationController, navigationItemModel: navigationItemModel, leftPanelAccessible: isMasterInitiallyAccessible(), rightPanelAccessible: isSupportInitiallyAccessible(), progress: bottomProgress() ?? 0) } @@ -308,7 +326,7 @@ import UIKit open func pageShown() { // Update the navigation bar ui when view is appearing. - setNavigationController() + setNavigationBar() // Update tab if needed. updateTabBar() @@ -425,7 +443,7 @@ import UIKit // Reset the navigation state. public func splitViewDidReset() { - setNavigationController() + setNavigationBar() } // MARK: - UITextFieldDelegate (Check if this is still needed) diff --git a/MVMCoreUI/Containers/NavigationController.swift b/MVMCoreUI/Containers/NavigationController.swift index 12d70634..a412728b 100644 --- a/MVMCoreUI/Containers/NavigationController.swift +++ b/MVMCoreUI/Containers/NavigationController.swift @@ -43,6 +43,14 @@ import UIKit return navigationController } + /// Convenience function for setting the navigation item. + public static func setNavigationItem(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol, viewController: UIViewController) { + viewController.navigationItem.title = navigationItemModel.title + viewController.navigationItem.accessibilityLabel = navigationItemModel.title + viewController.navigationItem.hidesBackButton = (navigationItemModel.backButton != nil) + setNavigationButtons(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController) + } + /// Convenience function for setting the navigation buttons. public static func setNavigationButtons(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol, viewController: UIViewController) { let delegate = (viewController as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject @@ -68,11 +76,7 @@ import UIKit } /// Convenience function for setting the navigation bar ui, except for the buttons. - public static func setNavigationUI(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol, viewController: UIViewController) { - viewController.navigationItem.title = navigationItemModel.title - viewController.navigationItem.accessibilityLabel = navigationItemModel.title - viewController.navigationItem.hidesBackButton = (navigationItemModel.backButton != nil) - + public static func setNavigationBarUI(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol, viewController: UIViewController) { navigationController.setNavigationBarHidden(navigationItemModel.hidden, animated: true) navigationController.navigationBar.barTintColor = navigationItemModel.backgroundColor?.uiColor ?? .white @@ -88,17 +92,19 @@ import UIKit } } - /// Convenience function for setting navigation bar with model. - public static func set(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol, viewController: UIViewController) { - setNavigationUI(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController) - setNavigationButtons(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController) - } - /// Convenience setter for legacy files - public static func set(navigationController: UINavigationController, navigationJSON: [String: Any], viewController: UIViewController) throws { + public static func setNavigationItem(navigationController: UINavigationController, navigationJSON: [String: Any], viewController: UIViewController) throws { guard let barModel = try MoleculeObjectMapping.shared()?.getMoleculeModelForJSON(navigationJSON) as? (MoleculeModelProtocol & NavigationItemModelProtocol) else { throw ModelRegistry.Error.decoderOther(message: "Model not a bar model") } - set(navigationController: navigationController, navigationItemModel: barModel, viewController: viewController) + setNavigationItem(navigationController: navigationController, navigationItemModel: barModel, viewController: viewController) + } + + /// Convenience setter for legacy files + public static func setNavigationBarUI(navigationController: UINavigationController, navigationJSON: [String: Any], viewController: UIViewController) throws { + guard let barModel = try MoleculeObjectMapping.shared()?.getMoleculeModelForJSON(navigationJSON) as? (MoleculeModelProtocol & NavigationItemModelProtocol) else { + throw ModelRegistry.Error.decoderOther(message: "Model not a bar model") + } + setNavigationBarUI(navigationController: navigationController, navigationItemModel: barModel, viewController: viewController) } } diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController+Extension.swift b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController+Extension.swift index bfbe19ac..059723a6 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController+Extension.swift +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController+Extension.swift @@ -15,7 +15,7 @@ public extension MVMCoreUISplitViewController { guard let splitView = MVMCoreUISplitViewController.main(), navigationController == splitView.navigationController, navigationController.topViewController == viewController else { - NavigationController.set(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController) + NavigationController.setNavigationBarUI(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController) return } splitView.set(for: viewController, navigationController: navigationController, navigationItemModel: navigationItemModel, leftPanelAccessible: leftPanelAccessible, rightPanelAccessible: rightPanelAccessible, progress: progress) @@ -27,7 +27,7 @@ public extension MVMCoreUISplitViewController { // Setup the panels. setupPanels() - NavigationController.setNavigationUI(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController) + NavigationController.setNavigationBarUI(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController) setLeftPanelIsAccessible(leftPanelAccessible ?? leftPanelIsAccessible, for: viewController, updateNavigationButtons: false) setRightPanelIsAccessible(rightPanelAccessible ?? rightPanelIsAccessible, for: viewController, updateNavigationButtons: false) @@ -115,7 +115,7 @@ public extension MVMCoreUISplitViewController { guard let splitView = MVMCoreUISplitViewController.main(), navigationController == splitView.navigationController, navigationController.topViewController == viewController else { - NavigationController.set(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController) + NavigationController.setNavigationBarUI(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController) return } let progress = progress?.floatValue From d1df1e2944696e6c88eee0c90cbff2645ac89c9a Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 29 Jun 2020 19:54:00 -0400 Subject: [PATCH 06/11] feedback --- .../MVMCoreUISplitViewController+Extension.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController+Extension.swift b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController+Extension.swift index 963834ff..e9d0eb65 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController+Extension.swift +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController+Extension.swift @@ -43,14 +43,14 @@ public extension MVMCoreUISplitViewController { } /// Sets the left navigation items for the view controller based on model and splitview. - func setLeftNavigationButtons(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol?, viewController: UIViewController) { + func setLeftNavigationButtons(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol, viewController: UIViewController) { var leftItems: [UIBarButtonItem] = [] let delegate = (viewController as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject // Add back button first. - if navigationItemModel?.alwaysShowBackButton != false { - if let backButtonModel = navigationItemModel?.backButton { - if navigationController.viewControllers.count > 1 || navigationItemModel!.alwaysShowBackButton ?? false { + if navigationItemModel.alwaysShowBackButton ?? false != false { + if let backButtonModel = navigationItemModel.backButton { + if navigationController.viewControllers.count > 1 || navigationItemModel.alwaysShowBackButton ?? false { leftItems.append(backButtonModel.createNavigationItemButton(delegateObject: delegate, additionalData: nil)) } } else if let backButton = backButton, @@ -67,7 +67,7 @@ public extension MVMCoreUISplitViewController { } // Add other model buttons - if let leftItemModels = navigationItemModel?.additionalLeftButtons { + if let leftItemModels = navigationItemModel.additionalLeftButtons { for item in leftItemModels { leftItems.append(item.createNavigationItemButton(delegateObject: delegate, additionalData: nil)) } @@ -82,7 +82,7 @@ public extension MVMCoreUISplitViewController { } /// Sets the right navigation items for the view controller based on model and splitview. - func setRightNavigationButtons(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol?, viewController: UIViewController) { + func setRightNavigationButtons(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol, viewController: UIViewController) { let delegate = (viewController as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject var rightItems: [UIBarButtonItem] = [] @@ -94,7 +94,7 @@ public extension MVMCoreUISplitViewController { } // Add other model buttons - if let rightItemModels = navigationItemModel?.additionalRightButtons { + if let rightItemModels = navigationItemModel.additionalRightButtons { for item in rightItemModels { rightItems.append(item.createNavigationItemButton(delegateObject: delegate, additionalData: nil)) } From c599f314c39580895a6f2f3ea68a52126eaf9984 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 29 Jun 2020 19:58:34 -0400 Subject: [PATCH 07/11] undo changes --- .../MVMCoreUISplitViewController+Extension.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController+Extension.swift b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController+Extension.swift index e9d0eb65..963834ff 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController+Extension.swift +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController+Extension.swift @@ -43,14 +43,14 @@ public extension MVMCoreUISplitViewController { } /// Sets the left navigation items for the view controller based on model and splitview. - func setLeftNavigationButtons(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol, viewController: UIViewController) { + func setLeftNavigationButtons(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol?, viewController: UIViewController) { var leftItems: [UIBarButtonItem] = [] let delegate = (viewController as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject // Add back button first. - if navigationItemModel.alwaysShowBackButton ?? false != false { - if let backButtonModel = navigationItemModel.backButton { - if navigationController.viewControllers.count > 1 || navigationItemModel.alwaysShowBackButton ?? false { + if navigationItemModel?.alwaysShowBackButton != false { + if let backButtonModel = navigationItemModel?.backButton { + if navigationController.viewControllers.count > 1 || navigationItemModel!.alwaysShowBackButton ?? false { leftItems.append(backButtonModel.createNavigationItemButton(delegateObject: delegate, additionalData: nil)) } } else if let backButton = backButton, @@ -67,7 +67,7 @@ public extension MVMCoreUISplitViewController { } // Add other model buttons - if let leftItemModels = navigationItemModel.additionalLeftButtons { + if let leftItemModels = navigationItemModel?.additionalLeftButtons { for item in leftItemModels { leftItems.append(item.createNavigationItemButton(delegateObject: delegate, additionalData: nil)) } @@ -82,7 +82,7 @@ public extension MVMCoreUISplitViewController { } /// Sets the right navigation items for the view controller based on model and splitview. - func setRightNavigationButtons(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol, viewController: UIViewController) { + func setRightNavigationButtons(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol?, viewController: UIViewController) { let delegate = (viewController as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject var rightItems: [UIBarButtonItem] = [] @@ -94,7 +94,7 @@ public extension MVMCoreUISplitViewController { } // Add other model buttons - if let rightItemModels = navigationItemModel.additionalRightButtons { + if let rightItemModels = navigationItemModel?.additionalRightButtons { for item in rightItemModels { rightItems.append(item.createNavigationItemButton(delegateObject: delegate, additionalData: nil)) } From 616c242b29fb4786147b5f3546774ae3cef8ef9b Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Wed, 1 Jul 2020 11:26:52 -0400 Subject: [PATCH 08/11] remove extra custom protocol --- .../Atomic/Protocols/TemplateProtocol.swift | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/MVMCoreUI/Atomic/Protocols/TemplateProtocol.swift b/MVMCoreUI/Atomic/Protocols/TemplateProtocol.swift index 699c217c..4696ce38 100644 --- a/MVMCoreUI/Atomic/Protocols/TemplateProtocol.swift +++ b/MVMCoreUI/Atomic/Protocols/TemplateProtocol.swift @@ -11,10 +11,8 @@ import Foundation public protocol TemplateProtocol: AnyObject { associatedtype TemplateModel: TemplateModelProtocol var templateModel: TemplateModel? { get set } -} - -public protocol CustomTemplateDecoder { - func decodeTemplate(using decoder: JSONDecoder, from data: Data) throws -> TemplateModelProtocol + + func decodeTemplate(using decoder: JSONDecoder, from data: Data) throws -> TemplateModel } public extension TemplateProtocol where Self: ViewController { @@ -24,14 +22,12 @@ public extension TemplateProtocol where Self: ViewController { let data = try JSONSerialization.data(withJSONObject: pageJSON) let decoder = JSONDecoder() try decoder.add(delegateObject: delegateObjectIVar) - let templateModel: TemplateModel - if let customDecoder = self as? CustomTemplateDecoder { - templateModel = try customDecoder.decodeTemplate(using: decoder, from: data) as! Self.TemplateModel - } else { - templateModel = try decoder.decode(TemplateModel.self, from: data) - } - self.templateModel = templateModel + self.templateModel = try decodeTemplate(using: decoder, from: data) self.pageModel = templateModel as? MVMControllerModelProtocol } + func decodeTemplate(using decoder: JSONDecoder, from data: Data) throws -> TemplateModel { + return try decoder.decode(TemplateModel.self, from: data) + } + } From 50888916cbad468ccb9223e3dcb4b963f0744c4b Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Wed, 1 Jul 2020 14:55:04 -0400 Subject: [PATCH 09/11] open list template model subclassing --- MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift index 4be4e025..372ae778 100644 --- a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift @@ -28,6 +28,11 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol try super.parsePageJSON() } + // For subclassing the model. + open func decodeTemplate(using decoder: JSONDecoder, from data: Data) throws -> ListPageTemplateModel { + return try decoder.decode(ListPageTemplateModel.self, from: data) + } + open override var loadObject: MVMCoreLoadObject? { didSet { guard loadObject != oldValue else { return } From 012d16ed09893d7722fa123e1cef4ee4210c1c6f Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Wed, 1 Jul 2020 14:55:21 -0400 Subject: [PATCH 10/11] code review --- MVMCoreUI/Atomic/Atoms/Views/Toggle.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Toggle.swift b/MVMCoreUI/Atomic/Atoms/Views/Toggle.swift index bb75d963..dfffcded 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Toggle.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Toggle.swift @@ -396,8 +396,8 @@ public typealias ActionBlockConfirmation = () -> (Bool) let alternateActionMap = model.alternateAction?.toJSON() if actionMap != nil || alternateActionMap != nil { didToggleAction = { [weak self] in - guard let strongSelf = self else { return } - if strongSelf.isOn { + guard let self = self else { return } + if self.isOn { if actionMap != nil { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) } From 4f013bec6f6f3c7171db6cbfd71c13f378cc0a3d Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 2 Jul 2020 16:29:17 -0400 Subject: [PATCH 11/11] action fix for tab bar --- MVMCoreUI/Atomic/Protocols/TabBarProtocol.swift | 3 +++ MVMCoreUI/BaseControllers/ViewController.swift | 1 + MVMCoreUI/OtherHandlers/MVMCoreUILoggingHandler.h | 4 ++-- MVMCoreUI/OtherHandlers/MVMCoreUILoggingHandler.m | 4 ++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atomic/Protocols/TabBarProtocol.swift b/MVMCoreUI/Atomic/Protocols/TabBarProtocol.swift index 1bf79795..19c7e107 100644 --- a/MVMCoreUI/Atomic/Protocols/TabBarProtocol.swift +++ b/MVMCoreUI/Atomic/Protocols/TabBarProtocol.swift @@ -9,6 +9,9 @@ import Foundation @objc public protocol TabBarProtocol { + + var delegateObject: MVMCoreUIDelegateObject? { get set } + /// Should visually select the given tab index. @objc func highlightTab(at index: Int) diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index 6a585dab..b6bdc1ca 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -267,6 +267,7 @@ import UIKit open func updateTabBar() { guard MVMCoreUISplitViewController.main()?.getCurrentDetailViewController() == self, let tabModel = pageModel as? TabPageModelProtocol else { return } + MVMCoreUISplitViewController.main()?.tabBar?.delegateObject = delegateObjectIVar if let index = tabModel.tabBarIndex { MVMCoreUISplitViewController.main()?.tabBar?.highlightTab(at: index) } diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUILoggingHandler.h b/MVMCoreUI/OtherHandlers/MVMCoreUILoggingHandler.h index 9fec90f5..14da21ad 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUILoggingHandler.h +++ b/MVMCoreUI/OtherHandlers/MVMCoreUILoggingHandler.h @@ -17,8 +17,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)defaultLogPageStateForController:(nonnull id )controller; // Action Logging -- (void)defaultLogActionForController:(nonnull id )controller actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData; -- (nullable NSDictionary *)defaultGetActionTrackDataDictionaryForController:(nonnull id )controller actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData; +- (void)defaultLogActionForController:(nullable id )controller actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData; +- (nullable NSDictionary *)defaultGetActionTrackDataDictionaryForController:(nullable id )controller actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData; @end diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUILoggingHandler.m b/MVMCoreUI/OtherHandlers/MVMCoreUILoggingHandler.m index 0c694cce..45a13acf 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUILoggingHandler.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUILoggingHandler.m @@ -13,10 +13,10 @@ - (void)defaultLogPageStateForController:(nonnull id )controller { } -- (void)defaultLogActionForController:(nonnull id )controller actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData { +- (void)defaultLogActionForController:(nullable id )controller actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData { } -- (nullable NSDictionary *)defaultGetActionTrackDataDictionaryForController:(nonnull id )controller actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData { +- (nullable NSDictionary *)defaultGetActionTrackDataDictionaryForController:(nullable id )controller actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData { return nil; }