Fixed
Status Update
Comments
il...@google.com <il...@google.com> #2
This has been fixed in https://android-review.googlesource.com/832161 and will be available as part of Fragment 1.1.0-alpha03
No update yet.
Description
In addition to being able to do
val viewModel: MyViewModel by viewModels()
It would be nice to also be able to gain access to Activity scoped ViewModels via something like
val viewModel: MyViewModel by activityViewModels()
Or perhaps a more general solution could be made by having by viewModels() take in a () -> ViewModelStoreOwner lambda which would be used as the ViewModelStoreOwner when constructing the ViewModelProvider:
val viewModel: MyViewModel by viewModels(viewModelFactory) { requireActivity() }
where the default value for the lambda could just be { this } to use the Fragment