olshevski / compose-navigation-reimagined

🌈 Type-safe navigation library for Jetpack Compose
https://olshevski.github.io/compose-navigation-reimagined/
MIT License
534 stars 18 forks source link

Deeplink considerations: NavigateUp vs NavigateBack #12

Closed hrach closed 1 year ago

hrach commented 1 year ago

Thanks to the initialBackstack, I can parse deeplink and prepare the backstack to be able to navigateUp. However, when going from deeplink, the app should behave differently for navigateUp and for navigateBack. navigateBack should ignore the "artificial" backstack and return to the previous app. NavigateUp should correctly pop and show the previous entry from the "artificial" backstack.

I guess it is possible to somehow hack it and track how much of this stack is "artificial", but I'd say support for this should be directly in the library.

Any thoughts? Did you consider adding this? Thank you :)

olshevski commented 1 year ago

@hrach This is most definitely the business concerns of your app and not of the core navigation library. There are so many possible navigation patterns and it doesn't make sense to support them all. Maybe as some extension library, but that's another story.

I'm pretty sure you can easily build the required logic yourself in different ways. Just off the top of my head:

  1. Mark your entry in some way that it came from a deeplink and create different handlers for "navigateUp" and "navigateBack" actions.
  2. Alternatively, you can set initialBackstack just to a single entry and recreate the backstack only when you "navigateUp" with replace method.
hrach commented 1 year ago

Thanks for getting back to me. :) Closing