QuickBirdEng / XCoordinator

🎌 Powerful navigation library for iOS based on the coordinator pattern
MIT License
2.27k stars 179 forks source link

How to chaining coordinators #67

Closed rapid-fyre closed 5 years ago

rapid-fyre commented 5 years ago

Hey how is it to make route from a parent coordinator to child coordinator’s route?

Can not seem to find in doc -Thanks!

pauljohanneskraft commented 5 years ago

There are multiple options to do so:

  1. Deep Linking: With deep linking, you can trigger route chains of different types, although you would have to present the child coordinator in the chain. So, in case you want to trigger the route at any time after the child coordinator was/is shown to the user, this might not be the right option.

  2. RedirectionRouter / RedirectionCoordinator: Maybe your child coordinator does not need to be its own "proper" coordinator. Take a look at the section about Redirection in the Readme, if this suits you better. It might not be the right option, if you have a viewController in between that offers special transitions (e.g. if there is a UINavigationController in between and you want to use push/pop transitions).

  3. Hold a reference to the child coordinator (e.g. by using its anyRouter type-erased version). Except for when using RedirectionRouter/RedirectionCoordinators, there is no direct reference between child and parent coordinator made by XCoordinator, so you can create that yourself - it is for example used in the Example app for the HomeCoordinator. You can then trigger routes on the child coordinator using the trigger or route transitions available to all BaseCoordinator subclasses.

I hope this helps. What you can also keep in mind is, that present and dismiss should also work across coordinator, as the appropriate method is not called on the rootViewController (that's what presentOnRoot and dismissToRoot are for) but on its presentedViewController (if that exists, otherwise the rootViewController). So calling present from any Coordinator with its rootViewController in the view hierarchy should present on top of everything.