Last active
October 29, 2021 07:34
-
-
Save iruizmar/e15c89e6cbe868f3633facbd4cd313cc to your computer and use it in GitHub Desktop.
Koin Composable nav graph viewmodel API proposal
This file contains hidden or 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
| @OptIn(KoinInternalApi::class) | |
| @Composable | |
| inline fun <reified T : ViewModel> getViewModel( | |
| viewModelStoreOwner: ViewModelStoreOwner = LocalViewModelStoreOwner.current!!, | |
| qualifier: Qualifier? = null, | |
| scope: Scope = GlobalContext.get().scopeRegistry.rootScope, | |
| noinline parameters: ParametersDefinition? = null, | |
| ): T { | |
| return remember(qualifier, parameters) { | |
| scope.getViewModel(qualifier, { | |
| ViewModelOwner.from(viewModelStoreOwner) | |
| }, parameters) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment