Adds BottomNavigationController to the demo app#1
Conversation
Showcasing a BottomNavigationView implementation with separate, retained backstacks for each MenuItem.
|
@Wrywulf have a look |
|
@chris6647 sometimes when I switch to another tab/controller, the last one stays there and they overlap. Any ideas? |
Provides concrete implementation example, using enums to map between MenuItem IDs and Controllers, together with the same reflection Controllers use internally, when restoring themselves. Fixes issue where Controllers in the childRouter, would get incorrect lifecycle callbacks: Previously, upon clearing the child Router, if that Router had > 1 backstack entries, the root Controller would get an onAttach/onCreateView callback, and then immediately get torn down. This caused issues when that Controller manipulated something beyond its own scope (i.e. showing a dialog), as that change would not be cleaned up. Now the Routers are properly torn down and restored, without any premature lifecycle callbacks. This is done in a manner similar to how RouterPagerAdapter, works. Upon clicking the same menu item, as the user is already on, it resets the backstack to the initial controller. Fixes issue with restoration when BottomNavigationController itself is in the backstack.
|
@mario I have been using this myself over the past months, encountered various bugs and have improved upon the initial version. Take a look at the new commit I made, and see if that version doesn't solve your issues :) Read the commit message for details. |
|
Awesome @chris6647 - will take a look in the coming days, thank you very very much! |
|
@chris6647 found a bug :P Where do you want me to push the changes? |
|
@mario Sounds good! Perhaps fork my code, and make a PR towards my branch here on this fork :) |
Signed-off-by: Mario Danic <mario@lovelyhq.com>
…oller Fixes issue where lastActiveChildRouter was null when it neednt steps to reproduce issue prior to fix: start another activity go back lastActiveChildRouter will be null therefore new controller would be created causing UI overlap (one controller on top of another) also clicking back button would crash hard since lastActiveChildRouter doesn't exist :)
|
@chris6647 more bugs :-/ |
|
@mario I've already encountered and fixed that locally :) but wanted to let it mature a bit before pushing because I'm unsure if my fix is the right one. In the scenario in which I encountered the issue, I would only let lastActiveChildRouter handleBack if not null, otherwise return false (i.e. not let it handle the back click) |
|
@chris6647 push. That's the only way afaik. |
|
The real question is: when/how can it be null? |
|
I encountered this issue (along with another that I've also fixed), when the backstack looked like this: |
|
@chris6647 more bugs 🗡
|
|
@mario Thanks for reporting. I've made several changes to the history retention on the app I'm working on currently, and once we've made it through some good QA sessions without new issues, I will update this PR and hopefully that will fix your issues too :) |
|
@chris6647 can you push so I can help testing? Need this relatively quickly :P |
…ly to need re-attach, which would cause old views to be present still (or all together gone) i.e. tapping quickly between menu items. This removes the need for manual tracking of lastActiveRouter and the cachedInstanceStates.
|
Havn't seen any new issues with the BottomNavigationController for a while now, so here is the latest. Hope it fixes your issues as well @mario :) |
|
@chris6647 well, let's see! :) |
|
Btw. thanks for the awesome work once again! |
|
Hey @chris6647, good work so far. Sadly this isn't fully complete (but its a good start). Internal child backstack seems legit (depth), but there should also be another backstack/queue watching out for the "external" navigation (items). So if I go from "Home" to "Friends" and press the back button I expect to go back to "Home", not to close the demo. Same idea: if I navigate from "Home" to "Friends" and then to "Planner", should I press the back button I should navigate backwards ("Friends" and then "Home") until exhausting the external navigation history and only then I should be able to leave the demo. |
…with Bundle args, as well as to a tab with a backstack Refactors to use the same navigateTo method internally, as can be called externally.
|
@mradzinski thanks for your feedback :) That doesn't seem like a normal use case to me, and it goes against how I expect a bottom navigation view to act. But it shouldn't be too hard to extend what I've made and have it handle this use case. If the user has browsed around between items a lot, the back stack will also be very long, which seems counterintuitive. But you could probably do something along the lines of: Hope this helps! :) |
|
@chris6647 Believe it or not, from a users' perspective It's actually the expected behavior. Check YouTube or Instagram for example. Both their apps keep a backstack of the navigated items and begin navigating backwards (popping) each time the users presses the back button. Agreed its fairly easy to implement though. Should I come with an implementation myself I'll share it on this PR. Cheers and thanks! |

Showcasing a BottomNavigationView implementation with separate,
retained backstacks for each MenuItem.