Skip to content

Adds BottomNavigationController to the demo app#1

Open
chris6647 wants to merge 6 commits intodevelopfrom
feature/bottom-navigation-view-controller
Open

Adds BottomNavigationController to the demo app#1
chris6647 wants to merge 6 commits intodevelopfrom
feature/bottom-navigation-view-controller

Conversation

@chris6647
Copy link
Owner

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

Showcasing a BottomNavigationView implementation with separate,
retained backstacks for each MenuItem.
@chris6647 chris6647 self-assigned this Jun 19, 2017
@chris6647
Copy link
Owner Author

@Wrywulf have a look

@mario
Copy link

mario commented Dec 13, 2017

@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.
@chris6647
Copy link
Owner Author

@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.
If you find any issues in the new code, please do let me know how to reproduce it and I will take a look at it.
FYI @Wrywulf

@mario
Copy link

mario commented Dec 13, 2017

Awesome @chris6647 - will take a look in the coming days, thank you very very much!

@mario
Copy link

mario commented Dec 29, 2017

@chris6647 found a bug :P Where do you want me to push the changes?

@chris6647
Copy link
Owner Author

@mario Sounds good! Perhaps fork my code, and make a PR towards my branch here on this fork :)

mario and others added 2 commits January 2, 2018 13:52
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 :)
@mario
Copy link

mario commented Jan 11, 2018

@chris6647 more bugs :-/

screen shot 2018-01-12 at 00 02 10

@chris6647
Copy link
Owner Author

@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)

@mario
Copy link

mario commented Jan 12, 2018

@chris6647 push. That's the only way afaik.

@mario
Copy link

mario commented Jan 12, 2018

The real question is: when/how can it be null?

@chris6647
Copy link
Owner Author

I encountered this issue (along with another that I've also fixed), when the backstack looked like this:
In BottomNavigationController navigate 1 or more steps into a childRouter. Then navigate to a Controller on the same Router that hosts the BottomNavigationController, then rotate the device, press back, rotate it back again.
Then the BottomNavigationController would have called saveInstance, but never restore (as it is in the backstack), and it would have nulled out the lastActiveChildRouter. So if one presses back to the BottomNavigationController, it would first of all fail due to not having a cachedSavedInstanceState, but in my case i was able to press back as well, when the lastActiveChildRouter was still null, causing another crash.

@mario
Copy link

mario commented Feb 27, 2018

@chris6647 more bugs 🗡

  • have a bottom navigation view and some history in it
  • start another activity
  • finish activity
  • watch history gone :(

@chris6647
Copy link
Owner Author

@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 :)

@mario
Copy link

mario commented Mar 1, 2018

@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.
@chris6647
Copy link
Owner Author

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 :)

@mario
Copy link

mario commented Apr 18, 2018

@chris6647 well, let's see! :)

@mario
Copy link

mario commented Apr 18, 2018

Btw. thanks for the awesome work once again!

@mradzinski
Copy link

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.
@chris6647
Copy link
Owner Author

@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:
Override navigateTo and keep track of the order in which the user switches tabs (also saving and restoring it with the instance state)
Override handleBack, if super.handleBack() returns false, then restore the previous tab you're tracking instead and return true if you've handled it

Hope this helps! :)

@mradzinski
Copy link

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants