Class

ComposeViewContext

[ComposeViewContext] can be used to compose a [ComposeView] while it isn't attached to the view hierarchy.

ComposeViewContextUnattachedSample

@OptIn(ExperimentalComposeViewContextApi::class)
fun ComposeViewContextUnattachedSample(attachedView: View) {
    val composeView = ComposeView(attachedView.context)
    composeView.setContent { Box(Modifier.fillMaxSize()) }
    // If a ComposeViewContext hasn't been attached to the hierarchy, create a new one for this view
    val composeViewContext =
        attachedView.findViewTreeComposeViewContext() ?: ComposeViewContext(attachedView)
    // start composing while composeView isn't attached
    composeView.createComposition(composeViewContext)
}