Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Remember route history #9

Closed
maheshj01 opened this issue Aug 7, 2022 · 3 comments · Fixed by #10
Closed

[Android] Remember route history #9

maheshj01 opened this issue Aug 7, 2022 · 3 comments · Fixed by #10
Labels
Feature Request New feature or request fixed A related PR has been merged which will close this issue

Comments

@maheshj01
Copy link
Owner

copied from #8

For a better navigation/experience you might wanna consider adding some sort of visited tabs history in order to manage back button navigation for Android, apps like instagram,netflix ... handle the navigation history by keeping track of the order in which the user visits different tabs such a feature would be a perfect addition to your package, for inspiration take a look at the solution implemented in this one : ttps://pub.dev/packages/bottom_nav_layout#page-back-stack

@maheshj01
Copy link
Owner Author

maheshj01 commented Aug 7, 2022

@mohamoha6200 this is fixed in v0.3.0, Please check and let me know if the bug exists.

@maheshj01
Copy link
Owner Author

Pages should be popped in the order they were pushed regardless of which tab user is on.

Test
if there are three nested tabs

  1. user pushes a route on tab1
  2. switches to tab2 pushes a route
  3. switches to tab3 pushes a route

then

  1. pressing a back button user should be on root of tab3
  2. pressing back button again user should be on 2nd route of tab2
  3. pressing back button again user should be root of tab2
  4. pressing back twice user should be root of tab1

@maheshj01
Copy link
Owner Author

This feature is similar to instagram where on pressing the backbutton on Android either a page must be popped from a Tab or the tab must switch to its previous state. Based on the user's last action.

Let's say we have a BottomNavigationBar with two tabs Tab1 and Tab2 each Tab is associated with a Navigator to handle nested routes within that tab.

Consider the below structure

   Tab 1                     Tab2
    |                         |
    |                         |
   Navigator                 Navigator
   
   /  : FirstPage()       /  : FirstPage() 
   /2 : SecondPage()      /2 : SecondPage() 

Use case:

  1. User is on tab1 (FirstPage()) and pushes a new page SecondPage on this tab
  2. switches to tab2 and pushes a new page SecondPage on tab2
  3. Press the back button SecondPage in tab2 should be popped
  4. Press the back button Tab should be switched to tab1 (With SecondPage on the stack)
  5. Press the back button SecondPage should be popped
  6. And on Pressing BackButton again app should be closed (since we are at the root of the nested navigator).

To solve this my idea is to keep track of the two events tab changes and also observe the navigator stack. So I am trying to maintain a consolidated history of both these events

List<RouteHistory> history = [];

class RouteHistory {
  int index; // tab index
  bool base; // whether its a root of the navigator
  RouteHistory({this.index=0, this.base=true});
}

@maheshj01 maheshj01 added the Feature Request New feature or request label Aug 14, 2022
@maheshj01 maheshj01 added the fixed A related PR has been merged which will close this issue label Aug 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request New feature or request fixed A related PR has been merged which will close this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant