Skip to content

Instantly share code, notes, and snippets.

@yasukotelin
Last active July 20, 2020 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yasukotelin/1eab5674785c69cb430df4f8d6c672ff to your computer and use it in GitHub Desktop.
Save yasukotelin/1eab5674785c69cb430df4f8d6c672ff to your computer and use it in GitHub Desktop.
@MainThread
inline fun <reified VM : ViewModel> Fragment.parentViewModels(
noinline ownerProducer: () -> ViewModelStoreOwner = { requireParentFragment() },
noinline factoryProducer: (() -> ViewModelProvider.Factory)? = null
) = createViewModelLazy(VM::class, { ownerProducer().viewModelStore }, factoryProducer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment