Skip to content

Instantly share code, notes, and snippets.

@daneko
Created February 1, 2020 05:52
Show Gist options
  • Save daneko/3e3900793354df516f7720f6a4366805 to your computer and use it in GitHub Desktop.
Save daneko/3e3900793354df516f7720f6a4366805 to your computer and use it in GitHub Desktop.
/**
* wrap sharedViewModel
* [reference](https://github.com/InsertKoinIO/koin/issues/442#issuecomment-527821213)
*/
inline fun <reified T : ViewModel> Fragment.navigationViewModel(
@IdRes navGraphId: Int,
qualifier: Qualifier? = null,
noinline parameters: ParametersDefinition? = null
): Lazy<T> = sharedViewModel(
qualifier = qualifier,
from = { findNavController().getViewModelStoreOwner(navGraphId) },
parameters = parameters
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment