Kevin Worth
05/08/2023, 8:00 PMdorche
05/08/2023, 8:15 PMKevin Worth
05/08/2023, 8:36 PMKevin Worth
05/08/2023, 8:46 PMpopUpTo
) back to C
, but only if I'm aware of it and its route.
GardenedA -> GardenedB -> GardenedC -> LoginX -> LoginY -> LoginZ
How do I tell it, "pop all the login screens", being completely unaware of what's before them? Make them separate graphs and then pop off an entire graph?dorche
05/08/2023, 8:59 PMKevin Worth
05/08/2023, 9:45 PMCould you not pop up to LoginX inclusively instead?Maybe I'll get this wrong, doing it from memory, but I've mostly seen syntax like
navigate("gardened-c-route") {
popUpTo("gardened-c-route") {
inclusive = true
}
}
But in my case, I want to navigate to that route, without knowing that route. I'm guessing I must be missing something?Kevin Worth
05/08/2023, 9:49 PMpopUpTo
works. Maybe I've got it wrong?Kevin Worth
05/09/2023, 11:13 AMyschimke
05/09/2023, 11:21 AMKevin Worth
05/09/2023, 11:34 AMdorche
05/09/2023, 11:51 AMsaveState
and restoreState
for now:
When the app is launched, deep-link or not, you land at either your starting destination or your deep-link destination. If this destination needs the user to be authenticated, it can simply call .navigate(LoginFlow)
.
Your stack then is
MainFlow (long stack here) -> LoginX -> LoginY -> LoginZ
Once LoginZ is done, it can simply call
navController.popBackStack(LoginX, inclusive = true)
which should then pop all the login screens, leaving you back wherever you were on MainFlow
.dorche
05/09/2023, 11:53 AMMainFlow
+ LoginFlow
and the fact you're not saving state and restoring it.
But I feel like it paints a good starting picture of what we are trying to achieve. Once this is clear you can start thinking about saving and restoring state so that your back stack is even nicerKevin Worth
05/09/2023, 11:55 AM@dorche is there a good sample somewhere of the proper way to save and restore state?navController.popBackStack(LoginX, inclusive = true)
Kevin Worth
05/09/2023, 11:55 AMdorche
05/09/2023, 12:01 PMLoginFlow
on your backstack so that pressing the system back button when you are on LoginX
, backgrounds/kills the app (whatever system does when there's only 1 entry on your back stack and press back)dorche
05/09/2023, 12:04 PMLoginX
by default will bring you back to GardenedDestination
, which then needs to do something about the fact that the user did not go through the login flow - for example navigating again to the login flow, which then could be a bit annoying for the user 🤷Kevin Worth
05/09/2023, 12:12 PMKevin Worth
05/09/2023, 12:14 PMdorche
05/09/2023, 12:19 PMColton Idle
05/09/2023, 12:29 PMKevin Worth
05/09/2023, 1:15 PMColton Idle
05/09/2023, 1:18 PMcomposable
navigation type that requires being logged in.Colton Idle
05/09/2023, 1:18 PMColton Idle
05/09/2023, 1:23 PMNavHost{
composable(Screen.X.route) { ...
composable(Screen.Y.route) { ...
composable(Screen.Z.route) { ...
}
you do
NavHost{
RequireLoggedIn(Screen.X.route) { ...
RequireLoggedIn(Screen.Y.route) { ...
composable(Screen.Z.route) { ...
}
Colton Idle
05/09/2023, 1:24 PM@Composable
fun RequireLoggedIn(
navController: NavController,
appStateHolder: AppStateHolder,
content: @Composable () -> Unit
) {
Colton Idle
05/09/2023, 1:25 PMKevin Worth
05/09/2023, 1:25 PMColton Idle
05/09/2023, 1:29 PMColton Idle
05/09/2023, 1:31 PMColton Idle
05/09/2023, 1:32 PMColton Idle
05/09/2023, 1:33 PM