Last active
March 31, 2020 17:56
-
-
Save coroutineDispatcher/2b9de0cd9d9d6b6c8b4932b0b6114901 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <reified T : ViewModel> Fragment.viewModel( | |
crossinline provider: (SavedStateHandle) -> T | |
) = viewModels<T> { | |
object : AbstractSavedStateViewModelFactory(this, fragment.arguments ?: Bundle()) { | |
override fun <T : ViewModel?> create(key: String, modelClass: Class<T>, handle: SavedStateHandle): T = | |
provider(handle) as T | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment