How to make custom transitions using flow coordinator pattern
A while ago my colleagues and I decided to run away from MVC and start using other architectures like VIPER and MVVM. Eventually, we’ve settled with MVVM + Coordinator pattern.
Coordinators got my attention while I was watching Krzysztof Zabtocki’s lecture about Good iOS Application Architecture. It got me interested, so I’ve started researching more about the pattern. I’ve found Andrey Panov’s Coordinator Essential Tutorial, and it gave me good practical examples. If you are not familiar with coordinators, I highly recommend to watch the video and to read the tutorial. We will not talk about this idea in general; we are going to look a few concepts that my colleagues and I found helpful.
Adding custom transitions
The first problem that we’ve encountered was how to perform custom transitions from one view controller to another. We used to work with custom UIStoryboardSegue, but now we can’t. So we’ve changed Router a bit. We’ve added new property transition and extended class with UINavigationControllerDelegate protocol.
Now Router is rootController’s delegate. The basic idea is to set a transition variable whenever we need to perform any transition (push, pop, present, dismiss). We’ve changed RooterProtocol’s methods, and now they are always setting the transition we need. You can also change methods for presenting and dismissing modules.
In the example, you’ll see how fade transition works.
Conclusion
The result of these changes is clean architecture, transitions with animations and code that is easy to use. If you want to find out more about coordinator pattern here is a complete implementation.
Thanks for reading :)
If this article was helpful and you want to hear more about similar topics, please clap, share, follow or comment.