f-klubben / fappen

F-Klub web-app
Other
2 stars 2 forks source link

Circular backstack when using navigation menu #64

Open krestenlaust opened 10 months ago

krestenlaust commented 10 months ago

An example in navigation: (1) Main menu -> (2) songbook -> (3) a song -> (4) main menu -> (5) songbook -> (6) main menu.

Now using back navigation, the stack just pops as presented. Instead you expect the stack to not include duplicates, so when step 5 is reached, all views until the identical step 2 should be popped, so the stack looks like (1) main menu -> (2) songbook instead.

That's my understanding anyway, source: https://developer.android.com/guide/navigation/backstack/circular

jonasKjellerup commented 10 months ago

Honestly I'm not entirely sure that I understand what you are suggesting.

Currently we just use the default browser behavior. But I assume what you are trying to get at is something like a tree structure, where pressing the back button will always go one step up in the tree.

E.g. If we were to somehow navigate to /songbook/songA from /stregsystem the back button will bring us to /songbook and not /stregsystem.

krestenlaust commented 6 months ago

No.. that's not it.

I'm not sure that I am able to explain it better 🤔 I think the idea is just that the same page can't be in the backstack twice, if it already exists, then past entries up until that page should be removed. I haven't implemented it myself, but that's the way I understand it. The link I referred originally has a pretty good demonstration/example of the undesirable situation

jonasKjellerup commented 6 months ago

Looking back at the link and your original example, I think I get it now. The main thing that got me confused is that the example you provided marks the (4)->(5) transition as the where the unwinding happens, but it is at the (3)->(4) transition as the main menu is already on the stack.

Basically in pseudo code:

navigateTo(path) {
  if backStack.contains(path) {
    backStack = backStack.takeWhile(x => x != path)
  }
  backStack.push(path)
}

With how simple the page flow is in the app, I don't see any issue with using this approach.