rachael
03/04/2021, 5:29 PMVipulyaara
03/04/2021, 5:43 PMnavigation
can scope a viewModel to a backStackEntry
val viewModel = hiltNavGraphViewModel()
edit: val viewModel = viewModel()
or
viewModel(factory = HiltViewModelFactory(LocalContext.current, navBackStackEntry))alorma
03/04/2021, 5:53 PMIan Lake
03/04/2021, 5:54 PMviewModel()
within a NavHost
composable
will scope it to that individual screen (it doesn't matter what factory you use)rachael
03/04/2021, 5:58 PMGabriel
03/04/2021, 6:00 PMNavHost(navController, startDestination = Screen.LaunchScreen.route) {
composable(Screen.LoadingScreen.route) { LoadingScreen() }
composable(Screen.LaunchScreen.route) {
val playersViewModel by viewModels<PlayersViewModel>()
LaunchScreen(playersViewModel)
}
}
Ian Lake
03/04/2021, 6:29 PMval playersViewModel = viewModel<PlayersViewModel>()
in Compose land: https://developer.android.com/jetpack/compose/interop#viewmodelGabriel
03/04/2021, 6:30 PMIan Lake
03/04/2021, 6:30 PMPlayersViewModel
instance to only the LaunchScreen
destinationFunkyMuse
03/04/2021, 9:04 PMGabriel
03/04/2021, 9:10 PMnavController = rememberNavController()
NavHost(navController, startDestination = Screen.LaunchScreen.route) {
composable(Screen.LoadingScreen.route) { LoadingScreen() }
composable(Screen.LaunchScreen.route) {
val playersViewModel = viewModel<PlayersViewModel>(
factory = PlayersViewModelFactory(
PlayersRepository()
)
)
LaunchScreen(playersViewModel)
}
}
Colton Idle
03/05/2021, 1:50 AMIt seems like the preference in a pure compose app is to not use fragments at all. Does that mean a single activity app where I have a ViewModel for every screen that's tied to that single Activity's lifecycle?I believe Ian Lake or Adam Powell have basically said that if you're building a pure compose app, then you can likely declare you're handling all config changes in the AndroidManifest, and then you wouldn't even need an AAC ViewModel since the main benefit of AAC VM is that it simplifies config changes for you.
Ian Lake
03/05/2021, 3:25 AMFunkyMuse
03/05/2021, 7:35 AMGabriel
03/05/2021, 7:37 AM