KaustubhPatange / navigator

A small navigation library for Android to ease the use of fragment transactions & handling backstack (also available for Jetpack Compose).
Apache License 2.0
99 stars 5 forks source link

[Navigator Compose] Design of `singleTop` is different from traditional navigation system #9

Closed KaustubhPatange closed 3 years ago

KaustubhPatange commented 3 years ago

For a very long time, we knew how a single top instance worked in the Fragment's navigation world. Since transactions in the FragmentManager are reversible the only way to correctly achieve this functionality of singleTop is to pop the backstack up to the point where we find that respective instance in the FragmentTransaction. This is how navigator & Jetpack Navigation handles single top functionality.

In Compose world, this could take a different turn since destinations are nothing but a State which we observe to switch between different composables we can remove it at any point without affecting the previous transaction (i.e history). The current implementation does not work like how it was done in Fragments world, here we just remove all the existing instances from the backstack directly (i.e no recursive pop till we find that instance).

This could be confusing since the functionality is not carried over to the new system. Now should I keep or change the logic that we are familiar with Fragments? Changing it would then become a breaking change.

KaustubhPatange commented 3 years ago

Also, to achieve the single top functionality of FragmentManager in navigator-compose we can use popUpTo with argument all=true.