// // BaseNavigationRouter.swift // ReviewsCoordinationKit // // Created by Javier Cicchelli on 21/03/2024. // Copyright © 2024 Röck+Cöde. All rights reserved. // import UIKit open class BaseNavigationRouter: NSObject { // MARK: Properties var navigationController: UINavigationController var onDismissForViewController: [UIViewController: Router.OnDismissClosure] = [:] // MARK: Initialisers public init(navigationController: UINavigationController) { self.navigationController = navigationController super.init() self.navigationController.delegate = self } // MARK: Functions func performOnDismiss(for viewController: UIViewController) { guard let onDismiss = onDismissForViewController[viewController] else { return } onDismiss() onDismissForViewController[viewController] = nil } } // MARK: - UINavigationControllerDelegate extension BaseNavigationRouter: UINavigationControllerDelegate { // MARK: Functions public func navigationController( _ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool ) { guard let viewControllerToDismiss = navigationController.transitionCoordinator?.viewController(forKey: .from) else { return } performOnDismiss(for: viewControllerToDismiss) } }