Merge branch 'feature/cs_hideMdnLeak' into 'develop'

Add navigation bar model tracking to PageMoleculeTransformationBehavior.

### Summary

Open up navigation bar behavior hooks for molecule transformations.

### JIRA Ticket

https://onejira.verizon.com/browse/ACT59-72 https://onejira.verizon.com/browse/VCGEN-151 https://onejira.verizon.com/browse/ACT59-193

Co-authored-by: teegsh2 <Suramba@77>

See merge request https://gitlab.verizon.com/BPHV_MIPS/mvm_core_ui/-/merge_requests/919
This commit is contained in:
Hedden, Kyle Matthew 2023-01-17 20:49:38 +00:00
commit b6bd1b9407
3 changed files with 45 additions and 19 deletions

View File

@ -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, with model: 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, with model: NavigationItemModelProtocol) {}
}
public protocol PageVisibilityBehavior: PageBehaviorProtocol {

View File

@ -70,30 +70,30 @@ 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 }
setNavigationItem(with: model, for: topViewController, coordinatingWith: viewController as? PageBehaviorHandlerProtocol)
setNavigationBarUI(with: model)
navigationBar.setNeedsLayout()
navigationBar.layoutIfNeeded()
}
public func displayedViewController(_ viewController: UIViewController) {
manager?.displayedViewController?(viewController)
}

View File

@ -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)
}
}