Skip to content

Commit

Permalink
Merge pull request #8 from allaboutapps/swi-coordinator
Browse files Browse the repository at this point in the history
Add popToViewController:UIViewController and popToViewControllerOfType:T
  • Loading branch information
aaa-developer authored Nov 5, 2020
2 parents 3690c94 + 6327324 commit 61c41e2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Sources/Toolbox/Coordinators/NavigationCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ open class NavigationCoordinator: Coordinator {
}
}

public func popToViewController(_ viewController: UIViewController, animated: Bool) {
guard let poppedViewControllers = navigationController.popToViewController(viewController, animated: animated) else { return }

for vc in poppedViewControllers {
removePushedViewController(vc)
}
}

public func popToViewControllerOfType<T: UIViewController>(_ type: T.Type, animated: Bool, willPopToViewController: ((T) -> Void)? = nil) {
guard let viewController = pushedViewControllers.first(where: { $0 is T }) as? T else { return }
willPopToViewController?(viewController)
popToViewController(viewController, animated: animated)
}

public func present(_ viewController: UIViewController, animated: Bool, completion: (() -> Void)? = nil) {
navigationController.present(viewController, animated: animated, completion: completion)
}
Expand Down

0 comments on commit 61c41e2

Please sign in to comment.