.
Is there a way to do this without create a custom
ViewModelStoreOwner
? 🤔
cc: @Ian Lake
j
julioromano
07/05/2021, 3:07 PM
You might wanna make ScreenA and ScreenB part of a nested navigation graph. They can then share a viewmodel by scoping it to the nested nav graph.
think smart 2
💡 1
n
nglauber
07/05/2021, 3:08 PM
Seems like a good idea… 🤔
j
julioromano
07/05/2021, 3:09 PM
Copy code
NavHost {
navigation(route = "myNestedGraph") {
composable { // ScreenA
val vm = hiltViewModel<MyViewModel>(viewModelStoreOwner = navController.getBackStackEntry("myNestedGraph"))
}
composable { // ScreenB
// Get the vm in the same way.
}
}
}