stephanenicolas / toothpick

A scope tree based Dependency Injection (DI) library for Java / Kotlin / Android.
Apache License 2.0
1.12k stars 115 forks source link

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

Open Zhuinden opened 4 years ago

Zhuinden commented 4 years ago

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 commented 4 years ago

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 ).

dlemures commented 4 years ago

Interesting, will do some research and target 4.0.

Thanks for the issue!

dlemures commented 4 years ago

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.