Coordinator Pattern (c. 23): Multiple styles of navigation within a coordinator

In the Coordinator Pattern introduced in Chapter 23 of Design Patterns by Tutorials we specify that the specific Coordinator only knows the order of view controllers but not how to present them, and vice versa for the specific Router.

However you can imagine a scenario in which a Coordinator flow needs multiple types of navigation – there may be a “push”-based flow throughout, but that occasional view controllers need to be presented modally as an “interruption”.

For example in a freemium application there may be an “Upgrade flow” that lays out a series of view controllers to convince the user to upgrade, but that the “terms of service” view controller the user can click to see is actually presented modally.

How do we go about organizing this considering the coordinator should not know about the presentation and the router should not depend on any particular coordinator/ view controllers?

@jrg.developer Can you please help with this when you get a chance? Thank you - much appreciated! :]

There’s likely many ways to solve this, but here’s a couple for your consideration. :blush:

  1. In cases where a different “flow” is started, you can create a child coordinator.

It’s okay for a parent coordinator to know how and when to instantiate a child coordinator.

In doing so, the parent doesn’t know about it’s own router’s type still, but it does know about it’s children’s routers (as it would have to instantiate them).

  1. You can have multiple “push” methods on a router, such as “normal” push and an “interruption” push methods.

This may be tempting from a “it’s a one off view controller” standpoint, but be careful if you then have additional view controllers that need to be pushed as part of the “interruption” — at some point, it’s worthwhile to pull out a new child coordinator.

I hope this gives you ideas for how to handle this situation in your own app!

Good luck. :smile: