Skip to content

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

Open
@chefnobody

Description

@chefnobody

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()
}

Activity

changed the title [-]Nesting push-able `Coordinators` inside a `NavigationCoordinator`[/-] [+] Question re: nesting push-able `Coordinators` inside a `NavigationCoordinator`[/+] on May 19, 2021
chefnobody

chefnobody commented on May 19, 2021

@chefnobody
Author

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Question re: nesting push-able `Coordinators` inside a `NavigationCoordinator` · Issue #207 · QuickBirdEng/XCoordinator