UIKit navigation #456
Closed
maximkrouk
started this conversation in
General
Replies: 3 comments 8 replies
-
The first step was to create recursive navigation.
class RecursiveNavigationController<
RootController: UIViewController,
RecursiveController: UIViewController
>: UINavigationController {
var rootController: RootController! { viewControllers.first.as(RootController.self) }
private(set) var recursiveControllers: [RecursiveController] = []
@Handler<Void>
var onRecursiveControllerPop
convenience init(rootController: RootController) {
self.init(rootViewController: rootController)
}
override init(rootViewController: UIViewController) {
precondition(rootViewController is RootController, "Unexpected root viewController type")
super.init(rootViewController: rootViewController)
}
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
open override func pushViewController(_ viewController: UIViewController, animated: Bool) {
if
let controller = viewController as? RecursiveController,
!(viewControllers.isEmpty && RecursiveController.self == RootController.self)
{
recursiveControllers.append(controller)
}
if !viewControllers.isEmpty { viewController.setupBackButton() }
super.pushViewController(viewController, animated: animated)
}
open override func popViewController(animated: Bool) -> UIViewController? {
let controller = super.popViewController(animated: animated)
if controller == recursiveControllers.last {
_ = recursiveControllers.popLast()
if let coordinator = transitionCoordinator, animated {
coordinator.animate(alongsideTransition: nil) { _ in
self._onRecursiveControllerPop()
(controller as? CoreRessetable)?.resetCore()
}
} else {
self._onRecursiveControllerPop()
(controller as? CoreRessetable)?.resetCore()
}
}
return controller
}
override func setViewControllers(_ viewControllers: [UIViewController], animated: Bool) {
self.recursiveControllers = viewControllers.compactMap { $0 as? RecursiveController }
super.setViewControllers(viewControllers, animated: animated)
}
func updateRecursiveControllersCount(to count: Int) {
if recursiveControllers.count < count {
while recursiveControllers.count + 1 < count {
pushViewController(RecursiveController(), animated: false)
}
pushViewController(RecursiveController(), animated: true)
} else if recursiveControllers.count > count {
while recursiveControllers.count - 1 > count {
_ = popViewController(animated: false)
}
_ = popViewController(animated: true)
}
}
} |
Beta Was this translation helpful? Give feedback.
2 replies
-
Second step is to understand how to represent |
Beta Was this translation helpful? Give feedback.
4 replies
-
@maximkrouk this might be interesting for you: I've developed a https://github.com/darrarski/store-navigation-controller You can check out my post about it here: |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'd like to create
ComposableNavigationController
, this discussion is meant to be a place for implementation ideas.Beta Was this translation helpful? Give feedback.
All reactions