Fix presenting nested modal view controllers through AppRouter

This commit is contained in:
Shadowfacts 2018-10-22 20:37:12 -04:00
parent 7e8f22c471
commit c1bfc6d3d9
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 23 additions and 22 deletions

View File

@ -13,43 +13,44 @@ import SafariServices
class AppRouter {
let rootViewController: UIViewController
var currentViewController: UIViewController {
return getContentViewController(from: rootViewController)
}
init(root: UIViewController) {
self.rootViewController = root
}
private func getContentViewController(from vc: UIViewController) -> UIViewController {
if let vc = vc as? UITabBarController,
let selected = vc.selectedViewController {
return getContentViewController(from: selected)
} else if let vc = vc as? UINavigationController,
private func getTopViewController(parent vc: UIViewController) -> UIViewController {
if let vc = vc as? UINavigationController,
let top = vc.topViewController {
return getContentViewController(from: top)
return getTopViewController(parent: top)
} else if let vc = vc as? UITabBarController,
let selected = vc.selectedViewController {
return getTopViewController(parent: selected)
} else if let presented = vc.presentedViewController {
return getTopViewController(parent: presented)
} else {
return vc
}
}
private func getNavController(parent vc: UIViewController) -> UINavigationController {
if let vc = vc as? UINavigationController {
return vc
} else if let vc = vc as? UITabBarController,
let selected = vc.selectedViewController {
return getNavController(parent: selected)
} else {
fatalError()
}
}
func present(_ vc: UIViewController, animated: Bool) {
if currentViewController.presentingViewController != nil {
currentViewController.dismiss(animated: animated) {
self.present(vc, animated: animated)
}
}
currentViewController.present(vc, animated: animated)
let top = getTopViewController(parent: rootViewController)
top.present(vc, animated: animated)
}
func push(_ vc: UIViewController, animated: Bool) {
if currentViewController.presentingViewController != nil {
currentViewController.dismiss(animated: animated) {
self.push(vc, animated: animated)
}
}
guard let nav = currentViewController.navigationController else { fatalError("Can't push view controller while not in navigation controller") }
nav.pushViewController(vc, animated: animated)
let nav = getNavController(parent: rootViewController)
nav.pushViewController(vc, animated: true)
}
func profile(for accountID: String) -> ProfileTableViewController {