Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question re: nesting push-able Coordinators inside a NavigationCoordinator #207

Open
chefnobody opened this issue May 19, 2021 · 1 comment

Comments

@chefnobody
Copy link

chefnobody commented May 19, 2021

My app's root has a NavigationCoordinator which is fine.

However, one of the Routes it responds to pushes a ViewController that has many possible Routes and is it self fairly complicated. I'd like to hide all of its Routes and complexity inside another Coordinator that also pushes onto the root NavigationCoordinator.

However I haven't sorted out to do this with either a RedirectionRouter or some other type of Coordinator . If I make my sub Coordinator a NavigationCoordinator and then in response to a Route transition on the root-level NavigationCoordinator return .push(subCoordinator) I get the following UIKit exception for obvious reasons:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'

What's the right/idimoatic way to do this with XCoordinator? I can't find a precise example either in the sample project or the documentation.

Update:

If I do something like this my SubCoordinator's root screen is suddenly visible but w/o the push animation I'd expect. How might I ensure that push animation happens correctly? When I'm pushing a NavigationCoordinator from inside a route handled by different NavigationCoordinator?

case .subRoute: 
   addChild(SubCoordinator(rootViewController: rootViewController))
   return .none()
}
@chefnobody chefnobody changed the title Nesting push-able Coordinators inside a NavigationCoordinator Question re: nesting push-able Coordinators inside a NavigationCoordinator May 19, 2021
@chefnobody
Copy link
Author

chefnobody commented May 19, 2021

Well, I've just discovered that if in my SubCoordinator: NavigationCoordinator<SubRoute> initializer I change the super.init call from this:

super.init(
   rootViewController: rootViewController,
   initialRoute: .someRoute
)

To this:

super.init(
   rootViewController: rootViewController,
   initialRoute: nil
)
trigger(.someRoute)

Everything works as expected. It's not yet clear to me why. Perhaps providing an initialRoute does not explicitly perform the animation and the trigger ensures that it does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant