adrielcafe / voyager

🛸 A pragmatic navigation library for Jetpack Compose
https://voyager.adriel.cafe
MIT License
2.27k stars 109 forks source link

[Bug][Deeplink] Navigator stack doesn't change after screens list changes #387

Open theolm opened 1 month ago

theolm commented 1 month ago

Issue with Deep Link Implementation

Current Behavior

When initializing the navigator using Navigator(screens = screenStack), it becomes impossible to change the list of screens using the same constructor. This issue becomes problematic for the implementation of deep links.

val screenStack by screenStackFlow.collectAsState()
Navigator(screens = screenStack) // screen list never changes even if screenStack changes

The only workaround I found was to use navigator.replaceAll to swap the entire stack at once.

// This works
val screenStack by screenStackFlow.collectAsState()
 Navigator(screens = screenStack) {
      CurrentScreen()
      it.replaceAll(screenStack)
 }

Expected Behavior

Once screenStack is a state and its content changes, the list of screens in the Navigator(screens = screenStack) composable should change accordingly, respecting the state.

Sample

The issue can be observed in this sample project

bugsample.zip