XCoordinator: Is it OK to call trigger inside a coordinator?
Hello,
I don’t know how to solve this problem.
I have 3 coordinators: AppCoordinator LoginCoordinator DashboardCoordinator
The AppCoordinator is run by the app delegate When running the app, if we have a user in userdefaults (or whatever), we present the dashboard coordinator, otherwise, we present the login coordinator.
Problem I have is this one: In the login screen, I want to press a button and then that view controller and login coordinator are dismissed, at the same time, I want that the dashboard coordinator is presented. Ideally, I would like to present the dashboard coordinator, and behind that, I would like to dismiss the login controller and release the login coordinator.
How should I do that? My idea is this:
enum LoginRoute: Route {
case login
case dismiss
}
final class LoginCoordinator: NavigationCoordinator<LoginRoute> {
weak var appCoordinator: AppCoordinator?
init(appCoordinator: AppCoordinator, initialRoute: RouteType? = nil) {
self.appCoordinator = appCoordinator
super.init(initialRoute: initialRoute)
}
override func prepareTransition(for route: LoginRoute) -> NavigationTransition {
switch route {
case.login:
var vc = LoginViewController.instantiateController()
let model = LoginViewModel(coordinator: anyRouter)
vc.bind(to: model)
return .push(vc)
case .dismiss:
self.appCoordinator.trigger(.dashboard) // This is not working
return .dismiss()
}
}
}
But it is not working. What is the proper way to do this? Thanks a lot.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 17
Yes, thanks a lot for your time. I am going to try what you said. Thanks!
I am creating another example, I upload it as soon as I have it!