Any idea how to create viewmodel scoped to composa...
# compose
k
Any idea how to create viewmodel scoped to composable function, means it will be destroyed once the function disposes.
a
not implemented yet
if you use compose-navigation, however, it will be scoped to the NavBackStackEntry
k
wow thanks, i will follow up on issue tracker
1
yes am using navigation will it handle automatically
l
I thought
androidx.lifecycle.viewmodel.compose.viewModel
did this already?
k
ok thanks, will check
l
Ah, my misunderstanding - it's scoped to the fragment/activity.
a
It’s scoped to LocalViewModelStoreOwner, it’s a bit difficult to debug, but Locals can be overridden locally within the hierarchy
so by default, I think it defaults to either the Activity or Fragment ViewModelStoreOwner. But if you use compose-navigation `composable(key)`function, value is changed somewhere into the NavBackStackEntry.
1
i
NavHost
swaps out the
LifecycleOwner
,
ViewModelStoreOwner
,
SavedStateRegistryOwner
, and
SaveableStateProvider
to ones that are tied to that specific destination, yes.
👏🏼 1