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

State based navigation with back handling #18

Closed hbmartin closed 1 year ago

hbmartin commented 1 year ago

Enables navigation to be modeled as a set of state emitted from e.g. a VM StateFlow This is based on comparing class types as they are updated on the premise that unique classes (but not unique properties) represent distinct screens. Includes back handling to properly rewind that flow as necessary.

TODO: rebase onto develop and cleanup diff - hoping for early feedback on this approach before I do that

olshevski commented 1 year ago

@hbmartin The library already provides the sample for hoisting navigation state to the view model. You should hoist the whole NavController. It is the recommended way of doing it.

You are trying to reinvent the wheel somehow. You are effectively bringing the second source of truth (BackStackStateFlow) to the app, reimplementing basic navigation methods and trying to keep it in sync with NavController. I see no point in doing so. It just complicates the logic and will potentially bring more issues.

The NavController is already designed to be easily detachable from the UI layer.

Also I strongly disagree with the assumption of comparing destinations by its class. You should work with NavEntries instead and compare them by their unique ID. You can make these assumptions within your own app, it is the constraints you define yourself as you will, but this shouldn't be included into the sample app.