Ahmed
12/14/2024, 1:28 PMAhmed
12/14/2024, 1:28 PMnavigation<Graph>(
startDestination = Screen,
) {
composable<Screen> { navBackStackEntry ->
// This is important and will be shared
val graph: Graph = navController.getBackStackEntry<Graph>().toRoute()
val viewModel = navBackStackEntry.sharedViewModel<GraphViewModel>(navController)
// I am adding it with a launched effect
LaunchedEffect(graph) {
viewModel.graphData = GraphData( … )
}
Screen( … )
}
// …
}Stylianos Gakis
12/14/2024, 1:31 PMAhmed
12/14/2024, 1:36 PMhilt , so I was doing this with @AssistedInject in the startDestination and rest of the destinations used sharedViewModel extension.
Is that a more better approach?Ahmed
12/14/2024, 1:38 PMAhmed
12/14/2024, 1:45 PMstartDestination.Ahmed
12/14/2024, 1:50 PMStylianos Gakis
12/14/2024, 3:09 PMAhmed
12/14/2024, 6:54 PMAhmed
12/14/2024, 11:42 PMSavedStateHandle in my VM and the args can be retrieved via savedStateHandle.toRoute<MyClass>()