-
-
Notifications
You must be signed in to change notification settings - Fork 742
SharedViewModelCompat pass wrong owner #1445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think it's outdated on your side. Current code is @OptIn(KoinInternalApi::class)
@MainThread
fun <T : ViewModel> Fragment.viewModelForClass(
clazz: KClass<T>,
qualifier: Qualifier? = null,
owner: () -> ViewModelStoreOwner = { this },
state: BundleDefinition? = null,
key: String? = null,
parameters: ParametersDefinition? = null,
): Lazy<T> {
return lazy(LazyThreadSafetyMode.NONE) {
val ownerEager = owner()
val viewModelStore = ownerEager.viewModelStore
resolveViewModel(
clazz,
viewModelStore,
extras = state?.invoke()?.toExtras(ownerEager) ?: CreationExtras.Empty,
qualifier = qualifier,
parameters = parameters,
key = key,
scope = getKoinScope()
)
}
} |
@arnaudgiuliani this is an issue at the
See how the |
I also found this 2.2.2 activity viewModelStore
3.0 fragment viewModelStore |
The comment in
This is wrong, because it's using the ViewModelStore from the Fragment as @tomas-kovacs mentioned. |
thanks |
Will be release in koin-android 3.3.3 |
Hello
Here you should pass owner parameter like
fragment.requireActivity()
Now this function creates new viewModel instead of reusing shared viewModel.
koin/android/koin-android-compat/src/main/java/org/koin/android/compat/SharedViewModelCompat.kt
Line 50 in 044bc02
The text was updated successfully, but these errors were encountered: