Almeric
10/30/2023, 7:52 AMAlmeric
10/30/2023, 7:54 AMNavHost(
modifier = Modifier.padding(it),
navController = appState.navController,
startDestination = "homeGraph"
) {
navigation(
startDestination = "home",
route = "homeGraph"
) {
composable("home") {
Home("A") {
appState.navController.navigate("home2", null)
}
}
composable("home2") {
Greeting("B")
}
}
composable("settings") {
Greeting("C")
}
}
Almeric
10/30/2023, 7:56 AMfun navigateToTopLevelDestination(topLevelDestination: TopLevelDestination) {
val topLevelNavOptions = navOptions {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
when (topLevelDestination) {
TopLevelDestination.HOME -> navController.navigate("homeGraph", topLevelNavOptions)
TopLevelDestination.SETTINGS -> navController.navigate("settings", topLevelNavOptions)
}
}
And here’s a recording of the issue:Almeric
10/30/2023, 7:57 AMStylianos Gakis
10/30/2023, 9:07 AMAlmeric
10/30/2023, 11:03 AMStylianos Gakis
10/30/2023, 11:20 AMascii
10/30/2023, 11:23 AMstartDestination = "home2"
you'll see that pressing back from C will always open B.ascii
10/30/2023, 11:24 AMStylianos Gakis
10/30/2023, 11:30 AMIf you setThen you are breaking the entire graph, why would they want to change the entire start destination for this?you’ll see that pressing back from C will always open B.startDestination = "home2"
other than mutating startDestination via remember + mutableStateOfThat to me sounds like a bad idea. If you do that, then if you are in B and you want to do the back gesture, then what, would you exit the app directly from “home2"? If that’s the start destination you’d also want it to be the beginning of the backstack, so as you try to go back you’ll see the back gesture exiting the app and then you’d actually exit the app, no?
ascii
10/30/2023, 11:52 AMwhy would they want to change the entire start destination for this?Just an example to help them understand
Ian Lake
10/30/2023, 2:00 PMpopUpTo(navController.graph.findSta rtDestination().id)
so the only thing left on the back stack (e.g., what happens when you do system back) is the start destination of the graph, so what you're seeing is exactly what you said you wanted to see.Ian Lake
10/30/2023, 2:00 PMdorche
10/30/2023, 11:19 PMIan Lake
10/30/2023, 11:31 PMpopUpTo(navController.graph.findStartDestination().id)
, that is the start destination of your entire graph. It is actually assumed that it is part of your bottom nav, not the opposite, but that's more of a convention than requirementAlmeric
10/31/2023, 7:47 AMsaveState = true
in the PopupToBuilder
this would also restore the state when popping ‘back’ to this destination.glancy
01/08/2024, 8:23 AMIan Lake
01/08/2024, 3:06 PMglancy
01/08/2024, 6:51 PM[A]
Launch screen B with button:
[A] [B]
Click tab C:
(With popUpTo start, save state)
[A] [C]
(With a saved state at A
of [B]
)
Click system back:
[A]
(No state is restored, so it remains saved)
Launch screen B Prime with button:
[A] [B Prime]
Click tab C:
(With popUpTo start, save state)
[A] [C]
(With a saved state at A
of [B Prime]
, overwriting the original back stack at A
of [B]
)
Click tab A:
Expected:
[A] [B Prime]
(Since the state is restored)
Actual:
[A] [B]
(Original back stack state is restored, not the last back stack seen)
So if the B Prime stack on tab A didn't overwrite the original tab A back stack, did it actually save? How would I restore that? Because it seems like a weird user experience to restore an older back stack on tab A, not your most recent back stack.