Hey guys, I have a `ComposeView` which contains a...
# compose
r
Hey guys, I have a
ComposeView
which contains a
NavHost
with a
NavController
inside. Is it normal that the `NavController`s
viewModelStore
s are not cleared when that
ComposeView
is removed from the layout hierarchy? I am doing that as a workaround:
Copy code
navController.currentBackStack.value.forEach { 
   it.viewModelStore.clear()
}
but we are not supposed to access the
currentBackStack
from the outside of the library with groupid = androidx.navigation is there a better way to tackle that?
i
That still won't clear any saved back stacks (destinations you've saved with
saveState
ala bottom navs) - that's why that's the wrong API to use, even if it was public
What you need is the parent ViewModelStoreOwner to be cleared. That could be when a Fragment that owns the ComposeView is removed from its FragmentManager or the whole activity is finished
But adding and removing a View isn't enough, even in the View world (that's why things like Fragments exist)