Skip to content

Instantly share code, notes, and snippets.

@andreymusth
Created July 18, 2021 07:27
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 andreymusth/019a74f878618999f727ac9ff00801fb to your computer and use it in GitHub Desktop.
Save andreymusth/019a74f878618999f727ac9ff00801fb to your computer and use it in GitHub Desktop.
android compose view
internal fun ViewGroup.setContent(
parent: CompositionContext,
content: @Composable () -> Unit
): Composition {
GlobalSnapshotManager.ensureStarted()
val composeView =
if (childCount > 0) {
getChildAt(0) as? AndroidComposeView
} else {
removeAllViews(); null
} ?: AndroidComposeView(context).also { addView(it.view, DefaultLayoutParams) }
return doSetContent(composeView, parent, content)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment