Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public extension UIViewController {
var modalFlow: Flow {
return ModalFlow(self)
}
var navigationFlow: Flow {
guard let navigationController = self.navigationController else { return modalFlow }
return NavigationFlow(navigationController)
}
}
public protocol Flow {
func present(_ viewController: UIViewController, animated: Bool)
func dismiss(_ animated: Bool)
}
private struct ModalFlow: Flow {
private let origin: UIViewController
init(_ viewController: UIViewController) {
self.origin = viewController
}
func present(_ viewController: UIViewController, animated: Bool) {
origin.present(viewController, animated: animated, completion: nil)
}
func dismiss(_ animated: Bool) {
origin.dismiss(animated: animated, completion: nil)
}
}
private struct NavigationFlow: Flow {
private let origin: UINavigationController
init(_ viewController: UINavigationController) {
self.origin = viewController
}
func present(_ viewController: UIViewController, animated: Bool) {
origin.pushViewController(viewController, animated: animated)
}
func dismiss(_ animated: Bool) {
origin.popViewController(animated: animated)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.