Skip to content

Commit 6a047eb

Browse files
committed
Refactor NavigationState
The `remember` block creating the `NavigationState` is now keyed with `startRoute` and `topLevelRoutes`. This ensures the state is correctly recalculated when these parameters change. Additionally, the `rememberSerializable` call for `topLevelRoute` includes these keys for better state consistency.
1 parent 8015304 commit 6a047eb

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

app/src/main/java/com/example/nav3recipes/multiplestacks/NavigationState.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ fun rememberNavigationState(
4444
): NavigationState {
4545

4646
val topLevelRoute = rememberSerializable(
47+
startRoute, topLevelRoutes,
4748
serializer = MutableStateSerializer(NavKeySerializer())
4849
) {
4950
mutableStateOf(startRoute)
5051
}
5152

5253
val backStacks = topLevelRoutes.associateWith { key -> rememberNavBackStack(key) }
5354

54-
return remember {
55+
return remember(startRoute, topLevelRoutes) {
5556
NavigationState(
5657
startRoute = startRoute,
5758
topLevelRoute = topLevelRoute,

0 commit comments

Comments
 (0)