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