Skip to content

Instantly share code, notes, and snippets.

@hlung
Last active May 8, 2019 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hlung/a2bfcb5fc0194e983d2e8cf61d9292b0 to your computer and use it in GitHub Desktop.
Save hlung/a2bfcb5fc0194e983d2e8cf61d9292b0 to your computer and use it in GitHub Desktop.
@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