shifted behavior calls to extension for better support. added molecular setup callback for navigation titleView.
This commit is contained in:
parent
0f8c21025d
commit
b7413d536b
@ -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 {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user