julioromano
07/22/2021, 1:24 PMnavigation-compose 2.4.0-alpha05
? There must have been some behavior changes because my navigation logic now leads to infinite loops which didn’t happen with alpha04.Ian Lake
07/22/2021, 1:31 PMjulioromano
07/22/2021, 1:33 PMSideEffect
.
Need to debug more to create something reproducible.SideEffect
which used to be triggered only once is now being trigged multiple times, perhaps this is because of the added crossfade navigation animation?Ian Lake
07/22/2021, 2:04 PMSideEffect
and other effects like LaunchedEffect
is that side effect runs every composition, so that doesn't seem like the right tool for what you wantif (backStackEntry.lifecycle.currentState == Lifecycle.State.RESUMED)
- the Lifecycle gets moved down immediately once you call navigate the first timejulioromano
07/22/2021, 2:05 PMnavigateUp()
and the viewModel<>()
method is called within the composable()
lambda.
NavHost(
navController = navController,
startDestination = "a",
modifier = Modifier.fillMaxSize(),
route = "mainGraph",
) {
composable(route = "a") {
ScreenA { navController.navigate("b") }
}
navigation(
startDestination = "b",
route = "subGraph",
) {
composable(route = "b") {
val vm = viewModel<SomeViewModel>(
viewModelStoreOwner = navController.getBackStackEntry("subGraph")
)
ScreenB { navController.navigateUp() }
}
}
}
Error is: No destination with route subGraph is on the NavController's back stack. The current destination is Destination(0xe5901274) route=a
Ian Lake
07/22/2021, 2:12 PMjulioromano
07/22/2021, 2:28 PMviewModel()
inside the screen composable. Since I didn’t want to make the screen composable dependent on NavController
I had to use LocalViewModelStoreOwner
to indirectly propagate the owner tied to the subgraph:
composable(
route = "b",
) {
val owner = remember { navController.getBackStackEntry("subGraph") }
CompositionLocalProvider(
LocalViewModelStoreOwner provides owner
) {
ScreenB { navController.navigateUp() }
}
}
pepos
07/22/2021, 5:53 PMpopUpTo
navOption
, probably same root causeIan Lake
07/22/2021, 6:24 PMpepos
07/22/2021, 8:28 PM