Smorg
08/18/2021, 10:25 PMhiltViewModel
calls (from the androidx.hilt.naviagtion.compose
lib) returns a new instance of the retrieved viewmodel as opposed to returning the same viewmodel scoped to a navigation graph where it is first retrieved. Any ideas what I might be missing?Colton Idle
08/18/2021, 10:28 PMSmorg
08/18/2021, 10:34 PM@HiltViewModel
class MyViewModel @Inject constructor() : ViewModel
...
navigation(route = "root", startDestination="...") {
// Expected: MyViewModel should be the same instance in the composables below
// Actual: MyViewModel is different instances in the comoosables
composable(...) {
hiltViewModel<MyViewModel>
}
composable(...) {
hiltViewModel<MyViewModel>
}
}
...
Anthony
08/18/2021, 10:36 PMcomposable(route) {
val viewmodel = hiltViewModel<ViewModel>( navController.getBackStackEntry(navigationRoute)
)
Composable(viewmodel ,
navigateUp = {
navController.navigateUp()
}
)
}
Smorg
08/18/2021, 10:38 PMAnthony
08/18/2021, 10:38 PM