From 0f8c21025d04290834ec794487a092010b2459c5 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Fri, 2 Dec 2022 18:44:59 -0500 Subject: [PATCH 1/4] Add navigation bar model tracking to PageMoleculeTransformationBehavior. Update ScreenRecordingMaskingBehavior to consume. Enhance MDN regex. --- .../Protocols/PageBehaviorProtocol.swift | 4 ++ .../NavigationController.swift | 38 ++++++++++++------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift b/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift index 3420299d..10dc3020 100644 --- a/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift +++ b/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift @@ -30,6 +30,8 @@ public protocol PageMoleculeTransformationBehavior: PageBehaviorProtocol { func onPageNew(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject?) func willSetupMolecule(with model: MoleculeModelProtocol, updating view: MoleculeViewProtocol?) func didSetupMolecule(view: MoleculeViewProtocol, withModel: MoleculeModelProtocol) + func willSetupNavigationBar(with model: NavigationItemModelProtocol, updating view: UINavigationBar) + func didSetupNavigationBar(view: UINavigationBar, withModel: NavigationItemModelProtocol) } public extension PageMoleculeTransformationBehavior { @@ -37,6 +39,8 @@ public extension PageMoleculeTransformationBehavior { func onPageNew(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject?) {} func willSetupMolecule(with model: MoleculeModelProtocol, updating view: MoleculeViewProtocol?) {} func didSetupMolecule(view: MoleculeViewProtocol, withModel: MoleculeModelProtocol) {} + func willSetupNavigationBar(with model: NavigationItemModelProtocol, updating view: UINavigationBar) {} + func didSetupNavigationBar(view: UINavigationBar, withModel: NavigationItemModelProtocol) {} } public protocol PageVisibilityBehavior: PageBehaviorProtocol { diff --git a/MVMCoreUI/Containers/NavigationController/NavigationController.swift b/MVMCoreUI/Containers/NavigationController/NavigationController.swift index 9b4b332a..329ff423 100644 --- a/MVMCoreUI/Containers/NavigationController/NavigationController.swift +++ b/MVMCoreUI/Containers/NavigationController/NavigationController.swift @@ -70,30 +70,42 @@ extension NavigationController: MVMCoreViewManagerProtocol { public func newDataReceived(in viewController: UIViewController) { if isDisplayed(viewController: viewController), - let topViewController = topViewController, let model = getNavigationModel(from: viewController) { - setNavigationItem(with: model, for: topViewController) - setNavigationBarUI(with: model) - - navigationBar.setNeedsLayout() - navigationBar.layoutIfNeeded() + updateNavigationView(with: model, for: viewController) } manager?.newDataReceived?(in: viewController) } public func willDisplay(_ viewController: UIViewController) { - if let topViewController = topViewController, - isDisplayed(viewController: viewController), + if isDisplayed(viewController: viewController), let model = getNavigationModel(from: viewController) { - setNavigationItem(with: model, for: topViewController) - setNavigationBarUI(with: model) - - navigationBar.setNeedsLayout() - navigationBar.layoutIfNeeded() + updateNavigationView(with: model, for: viewController) } manager?.willDisplay?(viewController) } + private func updateNavigationView(with model: NavigationItemModelProtocol, for viewController: UIViewController) { + guard let topViewController = topViewController else { return } + + if let pageBehaviorController = viewController as? PageBehaviorHandlerProtocol { + pageBehaviorController.executeBehaviors { (behavior: PageMoleculeTransformationBehavior) in + behavior.willSetupNavigationBar(with: model, updating: navigationBar) + } + } + + setNavigationItem(with: model, for: topViewController) + setNavigationBarUI(with: model) + + navigationBar.setNeedsLayout() + navigationBar.layoutIfNeeded() + + if let pageBehaviorController = viewController as? PageBehaviorHandlerProtocol { + pageBehaviorController.executeBehaviors { (behavior: PageMoleculeTransformationBehavior) in + behavior.didSetupNavigationBar(view: navigationBar, withModel: model) + } + } + } + public func displayedViewController(_ viewController: UIViewController) { manager?.displayedViewController?(viewController) } From b7413d536bda45ab3be72f65aec5b32ae13c68bb Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Mon, 5 Dec 2022 19:58:38 -0500 Subject: [PATCH 2/4] shifted behavior calls to extension for better support. added molecular setup callback for navigation titleView. --- .../Protocols/PageBehaviorProtocol.swift | 4 +-- .../NavigationController.swift | 14 +------- .../UINavigationController+Extension.swift | 34 +++++++++++++++---- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift b/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift index 10dc3020..d5f65323 100644 --- a/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift +++ b/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift @@ -31,7 +31,7 @@ public protocol PageMoleculeTransformationBehavior: PageBehaviorProtocol { func willSetupMolecule(with model: MoleculeModelProtocol, updating view: MoleculeViewProtocol?) func didSetupMolecule(view: MoleculeViewProtocol, withModel: MoleculeModelProtocol) func willSetupNavigationBar(with model: NavigationItemModelProtocol, updating view: UINavigationBar) - func didSetupNavigationBar(view: UINavigationBar, withModel: NavigationItemModelProtocol) + func didSetupNavigationBar(view: UINavigationBar, with model: NavigationItemModelProtocol) } public extension PageMoleculeTransformationBehavior { @@ -40,7 +40,7 @@ public extension PageMoleculeTransformationBehavior { func willSetupMolecule(with model: MoleculeModelProtocol, updating view: MoleculeViewProtocol?) {} func didSetupMolecule(view: MoleculeViewProtocol, withModel: MoleculeModelProtocol) {} func willSetupNavigationBar(with model: NavigationItemModelProtocol, updating view: UINavigationBar) {} - func didSetupNavigationBar(view: UINavigationBar, withModel: NavigationItemModelProtocol) {} + func didSetupNavigationBar(view: UINavigationBar, with model: NavigationItemModelProtocol) {} } public protocol PageVisibilityBehavior: PageBehaviorProtocol { diff --git a/MVMCoreUI/Containers/NavigationController/NavigationController.swift b/MVMCoreUI/Containers/NavigationController/NavigationController.swift index 329ff423..eb43201a 100644 --- a/MVMCoreUI/Containers/NavigationController/NavigationController.swift +++ b/MVMCoreUI/Containers/NavigationController/NavigationController.swift @@ -87,23 +87,11 @@ extension NavigationController: MVMCoreViewManagerProtocol { private func updateNavigationView(with model: NavigationItemModelProtocol, for viewController: UIViewController) { guard let topViewController = topViewController else { return } - if let pageBehaviorController = viewController as? PageBehaviorHandlerProtocol { - pageBehaviorController.executeBehaviors { (behavior: PageMoleculeTransformationBehavior) in - behavior.willSetupNavigationBar(with: model, updating: navigationBar) - } - } - - setNavigationItem(with: model, for: topViewController) + setNavigationItem(with: model, for: topViewController, coordinatingWith: viewController as? PageBehaviorHandlerProtocol) setNavigationBarUI(with: model) navigationBar.setNeedsLayout() navigationBar.layoutIfNeeded() - - if let pageBehaviorController = viewController as? PageBehaviorHandlerProtocol { - pageBehaviorController.executeBehaviors { (behavior: PageMoleculeTransformationBehavior) in - behavior.didSetupNavigationBar(view: navigationBar, withModel: model) - } - } } public func displayedViewController(_ viewController: UIViewController) { diff --git a/MVMCoreUI/Containers/NavigationController/UINavigationController+Extension.swift b/MVMCoreUI/Containers/NavigationController/UINavigationController+Extension.swift index e63028d4..9a0665b9 100644 --- a/MVMCoreUI/Containers/NavigationController/UINavigationController+Extension.swift +++ b/MVMCoreUI/Containers/NavigationController/UINavigationController+Extension.swift @@ -11,13 +11,24 @@ import Foundation public extension UINavigationController { /// Convenience function for setting the navigation item. - func setNavigationItem(with model: NavigationItemModelProtocol, for viewController: UIViewController) { + func setNavigationItem(with model: NavigationItemModelProtocol, for viewController: UIViewController, coordinatingWith pageBehaviorController: PageBehaviorHandlerProtocol? = nil) { + + let behaviorHandler = pageBehaviorController ?? viewController as? PageBehaviorHandlerProtocol; + + behaviorHandler?.executeBehaviors { (behavior: PageMoleculeTransformationBehavior) in + behavior.willSetupNavigationBar(with: model, updating: navigationBar) + } + viewController.navigationItem.title = model.title viewController.navigationItem.accessibilityLabel = model.title viewController.navigationItem.hidesBackButton = model.hidesSystemBackButton viewController.navigationItem.leftItemsSupplementBackButton = !model.hidesSystemBackButton setNavigationButtons(with: model, for: viewController) - setNavigationTitleView(with: model, for: viewController) + setNavigationTitleView(with: model, for: viewController, coordinatingWith: pageBehaviorController) + + behaviorHandler?.executeBehaviors { (behavior: PageMoleculeTransformationBehavior) in + behavior.didSetupNavigationBar(view: navigationBar, with: model) + } } /// Convenience function for setting the navigation buttons. @@ -48,11 +59,22 @@ public extension UINavigationController { } /// Convenience function for setting the navigation titleView. - func setNavigationTitleView(with model: NavigationItemModelProtocol, for viewController: UIViewController) { + func setNavigationTitleView(with model: NavigationItemModelProtocol, for viewController: UIViewController, coordinatingWith pageBehaviorController: PageBehaviorHandlerProtocol? = nil) { + guard let titleViewModel = model.titleView else { return } + let delegate = (viewController as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject - if let titleViewModel = model.titleView, - let molecule = ModelRegistry.createMolecule(titleViewModel, delegateObject: delegate, additionalData: nil) { - viewController.navigationItem.titleView = molecule + + let behaviorHandler = pageBehaviorController ?? viewController as? PageBehaviorHandlerProtocol; + behaviorHandler?.executeBehaviors { (behavior: PageMoleculeTransformationBehavior) in + behavior.willSetupMolecule(with: titleViewModel, updating: nil) + } + + guard let molecule = ModelRegistry.createMolecule(titleViewModel, delegateObject: delegate, additionalData: nil) else { return } + + viewController.navigationItem.titleView = molecule + + behaviorHandler?.executeBehaviors { (behavior: PageMoleculeTransformationBehavior) in + behavior.didSetupMolecule(view: molecule, withModel: titleViewModel) } } From 7ae5cbfc8a028251bebe7de0727ee571cedba2ac Mon Sep 17 00:00:00 2001 From: teegsh2 Date: Tue, 13 Dec 2022 09:52:47 +0530 Subject: [PATCH 3/4] unmask NavBar SR --- MVMCoreUI/BaseControllers/ViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index c6c64f3a..d9c606e4 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -363,7 +363,7 @@ import MVMCore super.viewWillDisappear(animated) executeBehaviors { [weak self] (behavior: PageVisibilityBehavior) in - behavior.willHidePage(self?.delegateObjectIVar) + behavior.willShowPage(self?.delegateObjectIVar) } } From 04acb80fd58b542b93a1a2bbbb568f2215183eae Mon Sep 17 00:00:00 2001 From: teegsh2 Date: Wed, 21 Dec 2022 20:25:03 +0530 Subject: [PATCH 4/4] Revert "unmask NavBar SR" This reverts commit 7ae5cbfc8a028251bebe7de0727ee571cedba2ac. --- MVMCoreUI/BaseControllers/ViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index d9c606e4..c6c64f3a 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -363,7 +363,7 @@ import MVMCore super.viewWillDisappear(animated) executeBehaviors { [weak self] (behavior: PageVisibilityBehavior) in - behavior.willShowPage(self?.delegateObjectIVar) + behavior.willHidePage(self?.delegateObjectIVar) } }