I just learned that <androidx.ViewModel and androi...
# koin
c
I just learned that androidx.ViewModel and androidx.navigation is multiplatform and work together (i.e. navigation scoped viewmodels). I'm still new to koin, but has anyone had any luck integrating androix.viewmodel/navigation and koin? I know @John O'Reilly mentioned it about a month ago, but that question was about ViewModels and not viewModels scoped to navigation destinations (which is how I currently enjoy using nav + vm + hilt today on android)
m
Now that JetBrains has released their artifact (which includes JS and WASM support), we should be able to integrate it with Koin. Supporting VMs should ensure navigation works, too. Keep in mind that the Navigation KMP is still in a "very experimental" stage. https://github.com/InsertKoinIO/koin/issues/1826#issuecomment-2062038109
s
What does koin do to know how to scope the VM to the right place? Is it by looking up the composition local for the ViewModelStoreOwner? If so, doesn't the multiplatform navigation artifact provide the right local for this on each destination? What will koin need to do especially to support this here which isn't already done? 🤔
m
@Stylianos Gakis
What does koin do to know how to scope the VM to the right place? Is it by looking up the composition local for the ViewModelStoreOwner?
Koin can either provide their own
koinViewModel
, orthogonal to
hiltViewModel
, which fetches the local
ViewModelStoreOwner
and use the
KoinViewModelProviderFactory
or they can expose their
Factory
and clients can pass it to the default
viewModel
function.
If so, doesn't the multiplatform navigation artifact provide the right local for this on each destination?
Yes, Navigation KMP provides a NavBackStackEntry that is your local ViewModelStoreOwner.
What will koin need to do especially to support this here which isn't already done?
Koin will need to (1) depend upon the JetBrains Multiplatform artifact, (2) migrate their
koinViewModel
function and
Factory
to common, (3) migrate their Binding and Constructor DSL to provide the ViewModel support in common instead of Android. Theoretically, that should be enough.
🌟 4
s
Wow thanks for the summary Marcello!
c
cc: @arnaud.giuliani ^
a
Koin can either provide their own
koinViewModel
, orthogonal to
hiltViewModel
, which fetches the local
ViewModelStoreOwner
and use the
KoinViewModelProviderFactory
or they can expose their
Factory
and clients can pass it to the default
viewModel
function.
Yeah this is already the Koin approach to provide a parallel API to Hilt ones, trying to wire on same and
KoinNavViewModel
is working with NavBackStackEntry in the same way
Koin will need to (1) depend upon the JetBrains Multiplatform artifact, (2) migrate their
koinViewModel
function and
Factory
to common, (3) migrate their Binding and Constructor DSL to provide the ViewModel support in common instead of Android.
Theoretically, that should be enough.
clearly yes 🙂
c
Oooh. okay. so its not ready yet. found this thanks to twitter https://github.com/InsertKoinIO/koin/issues/1826
a
WIP 🚧
❤️ 1
🎉 2