Implemented the PushRouter router in the Coordination library.
This commit is contained in:
parent
09cd434237
commit
bc8210e548
56
Libraries/Coordination/Kit/Sources/Routers/PushRouter.swift
Normal file
56
Libraries/Coordination/Kit/Sources/Routers/PushRouter.swift
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
//
|
||||||
|
// File.swift
|
||||||
|
// ReviewsCoordinationKit
|
||||||
|
//
|
||||||
|
// Created by Javier Cicchelli on 21/03/2024.
|
||||||
|
// Copyright © 2024 Röck+Cöde. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
public class PushRouter: NavigationRouter {
|
||||||
|
|
||||||
|
// MARK: Constants
|
||||||
|
private let rootViewController: UIViewController?
|
||||||
|
|
||||||
|
// MARK: Initialisers
|
||||||
|
public init(
|
||||||
|
navigationController: UINavigationController,
|
||||||
|
rootViewController: UIViewController? = nil
|
||||||
|
) {
|
||||||
|
self.rootViewController = navigationController.viewControllers.first ?? rootViewController
|
||||||
|
|
||||||
|
super.init(navigationController: navigationController)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Router
|
||||||
|
extension PushRouter: Router {
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
public func present(
|
||||||
|
_ viewController: UIViewController,
|
||||||
|
animated: Bool,
|
||||||
|
onDismiss: OnDismissClosure?
|
||||||
|
) {
|
||||||
|
onDismissForViewController[viewController] = onDismiss
|
||||||
|
|
||||||
|
navigationController.pushViewController(viewController, animated: animated)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func dismiss(animated: Bool) {
|
||||||
|
guard let rootViewController else {
|
||||||
|
navigationController.popViewController(animated: animated)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
performOnDismiss(for: rootViewController)
|
||||||
|
|
||||||
|
navigationController.popToViewController(
|
||||||
|
rootViewController,
|
||||||
|
animated: animated
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user