Hi :wave: Does scoping a ViewModel (injected via K...
# koin
o
Hi 👋 Does scoping a ViewModel (injected via Koin) to a Navigation3 back stack entry work in Compose Multiplatform? Basically I am running into the issue described here: https://github.com/InsertKoinIO/koin/issues/2235, but I am already using
org.koin.compose.viewmodel.koinViewModel()
, but the ViewModel is not being cleared when the Nav3 entry is popped. Is this expected for CMP / Nav3, or am I missing something in the setup? Thx for any hints.
Copy code
Koin : 4.2.0-alpha3
CMP  : 1.10.0-rc01
Nav3 : 1.0.0-alpha06
z
VMs get cleared as expected when navigating back in kotlinconf-app, even if I bump dependencies to those specific versions. Using
io.insert-koin:koin-compose-viewmodel-navigation
as the dependency.
👀 1
o
Thanks, this one was missing in my configuration. I have added this dependency, but VM is not cleared 😞 I have even tried to use deprecated
org.koin.compose.viewmodel.koinNavViewModel
, but no luck.
z
Oh, I just realized what it must be. Do you have
entryDecorators
set on your
NavDisplay
? You probably want the saved state and ViewModel ones:
Copy code
NavDisplay(
    backStack = backstack,
    entryProvider = entryProvider {
        ...
    },
    entryDecorators = listOf(
        rememberSaveableStateHolderNavEntryDecorator(),
        rememberViewModelStoreNavEntryDecorator(),
    ),
)
kodee loving 1
o
Nice, that was a missing piece 😄 Thank you very much! I have added
org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-navigation3
to resolve
rememberViewModelStoreNavEntryDecorator
and now it works as intended 👍