Jesse Hill
10/07/2022, 9:51 PMhasCompletedOnboarding
state would it be improper to trigger a navigation change to the onboarding
navigation graph from the home
graph based on the given state? The thought would be to use LaunchedEffect
so that the navigation would only happen when the state changed and wouldn’t be explicitly tied to the composition of that composable but that feels like the wrong approach. There is a code example in the thread.fun NavGraphBuilder.home(
navController: NavController
) {
navigation(
startDestination = Screen.Home.startDestination,
route = Screen.Home.route
) {
composable(route = Screen.Home.Dashboard.route) {
val activeUser = LocalActiveUser.current // Maybe this should be from the VM too ¯\_(ツ)_/¯
LaunchedEffect(activeUser) { if (activeUser?.isOnboarded != true) navController.navigate(Screen.Onboarding.route) }
HomeScreen()
}
}
}
Example swapping nav destinations (this is definitely broken or at least my implementation of it is):
@Composable
fun AppNavigation(
modifier: Modifier = Modifier,
navController: NavHostController
) {
val activeUser = LocalActiveUser.current
val startDestination = remember(activeUser) {
if (activeUser?.isOnboarded == true) Screen.Home.route else Screen.Onboarding.route
}
AnimatedNavHost(
modifier = modifier,
navController = navController,
startDestination = startDestination
) {
home(navController = navController)
onboarding(navController = navController)
}
}
Ian Lake
10/08/2022, 12:20 AMpajatopmr
10/31/2022, 8:37 PMIan Lake
10/31/2022, 9:08 PM