Hi, I was using sharedViewModel extension and now I see that the parameter "from" was deleted on latest version. Now the sharedviewmodel only works with hosting activity. Is not possible now to use this feature with another owner than the activity?
+1, i can't get viewmodel from parentFragment
i write a fun by myself
inline fun <reified T : ViewModel> Fragment.sharedViewModel(
qualifier: Qualifier? = null,
noinline from: ()->ViewModelStoreOwner = { activity as ViewModelStoreOwner },
noinline parameters: ParametersDefinition? = null
): Lazy<T> = lazy{
getKoin().getViewModel<T>(
from(),
qualifier,
parameters
)
}
Well, you can use requireParentFragment() just like this:
private val filterControlViewModel: FilterControlViewModel by lazy {
requireParentFragment().getViewModel<FilterControlViewModel>()
}
Most helpful comment
Well, you can use
requireParentFragment()just like this: