Last active
May 8, 2019 08:15
-
-
Save hlung/a2bfcb5fc0194e983d2e8cf61d9292b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@discardableResult func perform(_ navigation: Navigation) -> Bool { | |
guard let navigationController = currentNavigationController() else { return false } | |
// Check first if we can perform the navigation. | |
let currentNavigation = (navigationController.visibleViewController as? NavigationSource)?.sourceNavigation | |
let nextNavigation = navigation.redirectIfNeeded(from: currentNavigation) | |
switch nextNavigation { | |
case .tab(let tabType): | |
for viewController in tabBarController.viewControllers ?? [] { | |
if let tabTypeProvidable = viewController as? TabTypeProvidable, tabTypeProvidable.tabType == tabType { | |
tabBarController.selectedViewController = viewController | |
} | |
} | |
case .post(let id, let partialPost, let fetcher): | |
let viewController = ArticleViewController(appCoordinator: self, id: id, partialPost: partialPost, fetcher: fetcher) | |
navigationController.pushViewController(viewController, animated: true) | |
case .feed(let parameter): | |
let viewController = FeedViewController(appCoordinator: self, | |
loader: apiClient.getFeed(parameter:), | |
parameter: parameter, | |
sourceNavigation: navigation) | |
navigationController.pushViewController(viewController, animated: true) | |
case .search: | |
let viewController = SearchViewController(appCoordinator: self) | |
navigationController.pushViewController(viewController, animated: true) | |
case .safari(let url): | |
let viewController = SFSafariViewController(url: url) | |
navigationController.present(viewController, animated: true, completion: nil) | |
case .applicationOpen(let url): | |
UIApplication.shared.open(url, options: [:], completionHandler: nil) | |
//... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment