Hi,
I am just wondering what is your opinion on handling bottom navigation with Conductor?
I am aware that I should have one container ViewGroup which would, per say hold the bottom navigation, but each tab click should open some sub screen that would overlay the bottom navigation.
I saw the demo example for MultipleChildRouters, but I notice that clicking on the next button replaces the parent container altogether with the navigation itself, instead of just filling the sub screen with the new Controller's view.
Is it possible to have multiple childRouters with the same root ( that being the navigation container )? If it is, who will handle the navigation clicks? Parent Controller?
Thanks!
Given three controllers named MainController, HomeChildController and ProfileChildController, I would architect the navigation in the following way:
MainController has both, a container view (FrameLayout for example) and the bottom navigation view. I would get the child router of MainController using getChildRouter(container) and attach HomeChildController to that child router root controller (you can do this on onCreateView for example of the MainController). The rest is just invoking the child router pop and push methods from setOnNavigationItemSelectedListener of the bottom navigation view, so, if I wanted to show the ProfileChildController I would push it, and if I wanted to go back to the HomeChildController I would just pop to root.
Doing it this way you are still attaching to the single responsibility principle because MainController will only be used to navigate between child controllers, which in turn will be responsible of their own use case logic.
Yes, but what happens if i have let's say 5 items in the navigation tab? Pop to root doesn't make sense, since I would always get back to the same screen no matter what I chose. I can use pop to tag, but that clears up the stack up to the Controller with the given tag, so I would be recreating the views. This is not something I want to achieve.
Can you describe the navigation behavior you are trying to achieve? I don't think I'm getting it right
Take a look click
Alright, so you are trying to achieve a basic navigation. I believe you can prevent the views from being recreated by configuring the retain mode of the controllers (setRetainMode), but @EricKuck will probably be able to answer this in a better way.
Let me explain my implementation in details.
I have one BaseController, from which I push the rest of the Controllers. All of the controllers are handled by the same Router. When a user clicks on a particular item, I check if the Router has the Controller with the given tag, if it doesn't, I push the Controller and set the tag. So the next time the user clicks on the same item, I expect to be able to get the Controller from the backstack.
Instead, I can use popToTag which gets me the wanted Controller, but it also clears the stack all the way to the Controller with the given tag. So clicking on the other items means recreating the Controller and it's contents all over again. This I want to avoid.
Btw I am setting the retainMode on DETACH, but still the views get recreated after popToTag, which is reasonable.
@EricKuck I would appreciate if you can give me your opinion on this matter.
I guess you need to take a look at Router.setBackstack().
Basic idea is to
I sketched an old approach of my so called SwitchController here (could be done much cleaner):
https://github.com/bluelinelabs/Conductor/issues/156#issuecomment-259252795
Hope this helps.
@stephanschuster Works like a charm :)
This is fairly simple:
private void resetStack(int position) {
Router router = routerPagerAdapter.getRouter(position);
if (router != null) {
List<RouterTransaction> backstack = router.getBackstack();
if (backstack.size() > 1) {
backstack = backstack.subList(0, 1);
router.setBackstack(backstack, new SimpleSwapChangeHandler());
}
}
}
Most helpful comment
This is fairly simple: