Skip to content

Instantly share code, notes, and snippets.

@tfcporciuncula
Last active March 1, 2024 08:47
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 tfcporciuncula/6595ced51397acb9da53b557d30f1927 to your computer and use it in GitHub Desktop.
Save tfcporciuncula/6595ced51397acb9da53b557d30f1927 to your computer and use it in GitHub Desktop.
val creationCallback: (MyViewModel.Factory) -> MyViewModel = { factory ->
factory.create(runtimeArg = "abc")
}
val viewModel = viewModel<MyViewModel>(
extras = requireNotNull(LocalViewModelStoreOwner.current).run {
if (this is HasDefaultViewModelProviderFactory) {
this.defaultViewModelCreationExtras.withCreationCallback(creationCallback)
} else {
CreationExtras.Empty.withCreationCallback(creationCallback)
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment