Vlad
07/19/2023, 3:27 PMkoin-androidx-compose
hooks compose UI with the ViewModelStore to notify it that the composable is disposed so viewModel should be removed from the store?
I am having the weird situation, when I just remove from the composition a screen, I can see that the DisposableEffect
triggers its onDispose, but the view model is not cleared.
And when the screen returns into the composition - the same instance of the view model is provided. Although I don't scope it to activity or anything. Just using bare org.koin.androidx.compose.getViewModel()
.
So in practice we have a composable screen with its viewmodel. It triggers API and gets 401. The not authenticated state delivered and this screen just goes out of the composition via if(logged) and Login screen is the only screen in the composition.
And then we close the login, and re-create the initial screen - it gets old view model instance.
And the more weird part is that if I just close the screen via back button (having Voyager for navigation), the view model does get cleared.
Any hints?Vlad
07/20/2023, 2:05 PMkoinViewModel()
gets Activity's ViewModelStore, so basically scoped to activity.
And since the activity never changes - the view models don't die if their screens out of the composition.
So I need somehow my composable functions, which I treat as "Screen" to have their own ViewModelStore?!s3rius
07/21/2023, 8:08 PMarnaud.giuliani
07/28/2023, 1:01 PMarnaud.giuliani
07/28/2023, 1:02 PMkoinViewModel
is based on Android API and then, all the lifecycle plumbing. Did you try to inject just a factory
instance?Vlad
07/28/2023, 1:04 PMarnaud.giuliani
07/28/2023, 1:05 PMfactory
. use koinInject
instead of koinViewModel
Vlad
07/28/2023, 1:07 PMVlad
07/28/2023, 1:08 PMarnaud.giuliani
07/28/2023, 1:14 PMarnaud.giuliani
07/28/2023, 1:14 PMVlad
07/28/2023, 1:15 PMarnaud.giuliani
07/28/2023, 1:16 PMarnaud.giuliani
07/28/2023, 1:16 PMVlad
07/28/2023, 1:17 PMarnaud.giuliani
07/28/2023, 1:23 PMarnaud.giuliani
07/28/2023, 1:23 PM