Closed Reach2027 closed 2 months ago
@arnaudgiuliani I looked into this and saw that the class should have this field. I have to figure that this would be fixed by stabilization in the navigation library.
Able to reproduce on my side as well
It's mainly due to the fact that the Navigation component library was significantly refactored in recent version and the getArguments()
method was removed from ViewModelStoreOwner
.
public interface ViewModelStoreOwner {
/**
* The owned [ViewModelStore]
*/
public val viewModelStore: ViewModelStore
}
But, koin
continues to use it:
@OptIn(KoinInternalApi::class)
fun defaultNavExtras(viewModelStoreOwner: ViewModelStoreOwner): CreationExtras = when {
viewModelStoreOwner is NavBackStackEntry && viewModelStoreOwner.arguments != null -> viewModelStoreOwner.arguments?.toExtras(viewModelStoreOwner) ?: CreationExtras.Empty
viewModelStoreOwner is HasDefaultViewModelProviderFactory -> viewModelStoreOwner.defaultViewModelCreationExtras
else -> CreationExtras.Empty
}
Actually, koin-compose-viewmodel:4.0.0-RC1
cannot be use with an updated Android project.
@sayah-y
I am looking at the documentation and the NavBackstackEntry still implements ViewModelStoreOwner and has the getArguments() function according to what I found here.
https://developer.android.com/reference/androidx/navigation/NavBackStackEntry
When I debugged the code the is NavBackstackEntry is true, is there a better place to pull documentation?
yes known issue on current jetbrains API
waiting for JB feedback
Solution found in this slack thread: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1725012875898249 Fixed in RC2
Describe the bug In the compose multiplatform project, using koinNavViewModel() to create a ViewModel will cause a crash on Android, it is normal on iOS and desktop.
To Reproduce Launch android app
Expected behavior Create NavBackStackEntry ViewModel success on Android.
Koin module and version:
koin-compose-viewmodel:4.0.0-RC1
Snippet or Sample project to help reproduce https://github.com/Reach2027/Kmp/blob/master/feature/bingwallpaper/src/commonMain/kotlin/com/reach/kmp/feature/bingwallpaper/BingWallpaperScreen.kt
line:62