<#CJLTWPH7S|compose> #viewmodels Hi everyone Anyon...
# compose
a
#compose #viewmodels Hi everyone Anyone have an idea about working with navigation compose with view models that have been created and cleared automatically within the composable scope and organise the code without any boilerplate? I 'm trying to migrate from normal navigation component to the new navigation compose and I'm facing these problems
i
That's already how Navigation Compose works - any calls to
viewModel()
or
hiltViewModel()
are scoped to that destination
💯 1
a
I tried to use
hiltViewModel()
but I noticed that the
onCleared()
of my VM never get called even I navigated to a different destination.
i
Well, navigating to another destination by default only adds a new destination to the back stack. The
onCleared()
gets called when a destination gets popped off the back stack. This is exactly how Navigation with Fragments work as well 🙂
❤️ 2
a
Thank you for helping I think that what I missed 😅