toothpick icon indicating copy to clipboard operation
toothpick copied to clipboard

smoothie lifecycle extension does not support arbitrary ViewModelStoreOwner, only Activity/Fragment

Open Zhuinden opened this issue 4 years ago • 3 comments

This is a problem, because Jetpack Navigation allows for the creation of NavGraph-scoped ViewModels, bound to the lifecycle of a NavBackStackEntry.

Toothpick should be able to support this scenario.

Zhuinden avatar May 30 '20 09:05 Zhuinden

It also begs the question, how to use AbstractSavedStateViewModelFactory to get a SavedStateHandle into a ViewModel provided by the Toothpick ViewModelBinding.

Should be a separate issue, though (and now it is: https://github.com/stephanenicolas/toothpick/issues/410 ).

Zhuinden avatar May 30 '20 09:05 Zhuinden

Interesting, will do some research and target 4.0.

Thanks for the issue!

dlemures avatar Jun 13 '20 00:06 dlemures

We just need to update toothpick.smoothie.viewmodel.ViewModelProvider to use the new API for androidx...ViewModelProvider:

https://developer.android.com/reference/androidx/lifecycle/ViewModelProvider

It takes a ViewModelStoreOwner as a constructor param, it will make it work with this use case and simplify TP code as well.

dlemures avatar Jun 13 '20 06:06 dlemures