Skip to content

Instantly share code, notes, and snippets.

@DJDarkByte
Created April 5, 2021 07:54
Show Gist options
  • Save DJDarkByte/aaf7490e76d587667d310844f690e476 to your computer and use it in GitHub Desktop.
Save DJDarkByte/aaf7490e76d587667d310844f690e476 to your computer and use it in GitHub Desktop.
Hilt FragmentExtension
@MainThread
fun <VM : ViewModel> Fragment.viewModels(
clazz: KClass<VM>,
ownerProducer: () -> ViewModelStoreOwner = { this },
factoryProducer: (() -> ViewModelProvider.Factory)? = null
) = createViewModelLazy(clazz, { ownerProducer().viewModelStore }, factoryProducer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment