-
-
Save appspell/dc1b028ee621a5922657e01c5177c5ec 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
@Composable | |
inline fun <reified T : ViewModel> daggerViewModel( | |
key: String? = null, | |
crossinline viewModelInstanceCreator: () -> T | |
): T = | |
androidx.lifecycle.viewmodel.compose.viewModel( | |
modelClass = T::class.java, | |
key = key, | |
factory = object : ViewModelProvider.Factory { | |
override fun <T : ViewModel> create(modelClass: Class<T>): T { | |
return viewModelInstanceCreator() as T | |
} | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks your code :)
Can I use your code in my commercial app?
Please let me know how I can use the code for commercial distribution.