![]() And now we’ll start to implement all theirs concrete types so don’t worry I won’t let you hanging there alone with a bunch of protocols. This finishes all the protocols we need to work as protocol oriented as we can with this coordination approach. Var parentCoordinator: MainBaseCoordinator? The first piece of our *Coordinators Fiesta* is the Coordinator itself: We will have in the main coordinator a func that will be responsible to change the flow so we can navigate easily between tabs. By the way, the concept of app flow is important here. ![]() This is important because we need the capability to navigate between app flows. Our parent and child coordinator will look like this:Įvery child will have a reference to the parent coordinator and the parent has a reference to the child. The Architecture – Coordinators and Tab Bars But how they look like? Our version is a very very simplified one but you can go full complex on coordinators adding the router pattern to it to like this lib. It’s easy to buy into the idea of using coordinator in your app. The advantages of this approach are: reusable view controllers because with coordinators there’s no link between view controllers anymore, isolated view controllers that gives you more freedom to rearrange them in your app’s flow, and you are in full control of your app’s flow this means that you can easily plug-and-play view controllers to build new flows easily. And you can imagine them as glorified delegates that the view controller use to delegate its navigation flow. An important disclaimer is that we won’t be implementing the full strict sense of coordinators, if you want a deep dive into them just check this awesome blog post from the coordinator inventor and you will understand where we found inspiration to do our coordinators.Ĭoordinators were idealised back in 2015 and it’s a brilliant idea. To solve this problem we will use coordinators with child coordinators. The problem is to navigate from the second level deep view controller of home Tab to the 3 level deep Orders tab maintaining the hierarchical sequence of orders tab, this means that the return button should return to level 2 of level tab and so on.įirst of all, to visualize better the problem we are trying to solve look at the picture below: The Home Tab has 2 levels deep and the Orders Tab has 3 levels deep. Imagine that you have a tab bar with two tabs and each tab is a navigation controller. Problem – Coordinators and Tab Bars: A Love Story Your ViewControllers never know what coordinators do behind the scenes, don’t they? This painting represents two things, the lovers on the left kissing in the backstage and the public social party on the right. The painting chosen to be represent this is The Stole Kiss (1788) from Jean-Honore Fragonard. Use this post as inspiration for your future architectures and it’s ALL open to debate. And a little disclaimer is needed: this isn’t intended to be a final solution or the best/most abstraction of this pattern, this is only something that solved a problem we had, and it will always be working in progress like everything in programming (well at least not the swift’s APIs ones). The problem involves tab bars, coordinators, and deep navigation between those. This article will solve a very very specific problem that we had and maybe this could be used by others. you have a Home screen that needs to go to the Cart screen this way the Home screen needs to know what to call but it doesn’t need to know HOW to call, and there is when the coordinator comes handy. This seems awkward at first because the view controller needs to how what to call, e.g. The coordinator pattern comes to help the situation where you need to decouple the flow of your app from your view controllers. This will be a very long and interesting(I hope) post because the subject today is… Architecture, more specifically coordinator pattern. The day has come and we will talk about Coordinators and Tab Bars in Swift and how they can greatly work together.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |