forked from shadowfacts/Tusker
Fix presenting nested modal view controllers through AppRouter
This commit is contained in:
parent
7e8f22c471
commit
c1bfc6d3d9
|
@ -13,43 +13,44 @@ import SafariServices
|
||||||
class AppRouter {
|
class AppRouter {
|
||||||
|
|
||||||
let rootViewController: UIViewController
|
let rootViewController: UIViewController
|
||||||
var currentViewController: UIViewController {
|
|
||||||
return getContentViewController(from: rootViewController)
|
|
||||||
}
|
|
||||||
|
|
||||||
init(root: UIViewController) {
|
init(root: UIViewController) {
|
||||||
self.rootViewController = root
|
self.rootViewController = root
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getContentViewController(from vc: UIViewController) -> UIViewController {
|
private func getTopViewController(parent vc: UIViewController) -> UIViewController {
|
||||||
if let vc = vc as? UITabBarController,
|
if let vc = vc as? UINavigationController,
|
||||||
let selected = vc.selectedViewController {
|
|
||||||
return getContentViewController(from: selected)
|
|
||||||
} else if let vc = vc as? UINavigationController,
|
|
||||||
let top = vc.topViewController {
|
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 {
|
} else {
|
||||||
return vc
|
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) {
|
func present(_ vc: UIViewController, animated: Bool) {
|
||||||
if currentViewController.presentingViewController != nil {
|
let top = getTopViewController(parent: rootViewController)
|
||||||
currentViewController.dismiss(animated: animated) {
|
top.present(vc, animated: animated)
|
||||||
self.present(vc, animated: animated)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
currentViewController.present(vc, animated: animated)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func push(_ vc: UIViewController, animated: Bool) {
|
func push(_ vc: UIViewController, animated: Bool) {
|
||||||
if currentViewController.presentingViewController != nil {
|
let nav = getNavController(parent: rootViewController)
|
||||||
currentViewController.dismiss(animated: animated) {
|
nav.pushViewController(vc, animated: true)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func profile(for accountID: String) -> ProfileTableViewController {
|
func profile(for accountID: String) -> ProfileTableViewController {
|
||||||
|
|
Loading…
Reference in New Issue