Compose

object Compose
kotlin.Any
   ↳ androidx.compose.Compose

A global namespace to hold some Compose utility methods, such as Compose.composeInto and Compose.disposeComposition.

Summary

Public methods

CompositionContext?
composeInto(container: ViewGroup, parent: CompositionReference? = null, composable: () -> Unit)

This method is the way to initiate a composition.

CompositionContext
composeInto(container: Emittable, context: Context, parent: CompositionReference? = null, composable: () -> Unit)

This method is the way to initiate a composition.

Unit
disposeComposition(container: ViewGroup, parent: CompositionReference? = null)

Disposes any composition previously run with container as the root.

Unit
disposeComposition(container: Emittable, context: Context, parent: CompositionReference? = null)

Disposes any composition previously run with container as the root.

Component?
findRoot(view: View)

CompositionContext
subcomposeInto(container: Emittable, context: Context, parent: CompositionReference? = null, composable: () -> Unit)

Public methods

composeInto

@MainThread fun composeInto(
    container: ViewGroup,
    parent: CompositionReference? = null,
    composable: () -> Unit
): CompositionContext?

This method is the way to initiate a composition. The composable passed in will be executed to compose the children of the passed in container. Optionally, a parent can be provided to make the composition behave as a sub-composition of the parent. The children of container will be updated and maintained by the time this method returns.

It is important to call disposeComposition whenever this view is no longer needed in order to release resources.

Parameters
container: ViewGroup The view whose children is being composed.
parent: CompositionReference? = null The parent composition reference, if applicable. Default is null.
composable: () -> Unit The composable function intended to compose the children of container.

composeInto

@MainThread fun composeInto(
    container: Emittable,
    context: Context,
    parent: CompositionReference? = null,
    composable: () -> Unit
): CompositionContext

This method is the way to initiate a composition. The composable passed in will be executed to compose the children of the passed in container. Optionally, a parent can be provided to make the composition behave as a sub-composition of the parent. The children of container will be updated and maintained by the time this method returns.

It is important to call Compose.disposeComposition whenever this view is no longer needed in order to release resources.

Parameters
container: Emittable The emittable whose children is being composed.
context: Context The android Context to associate with this composition.
parent: CompositionReference? = null The parent composition reference, if applicable. Default is null.
composable: () -> Unit The composable function intended to compose the children of container.

disposeComposition

@MainThread fun disposeComposition(
    container: ViewGroup,
    parent: CompositionReference? = null
): Unit

Disposes any composition previously run with container as the root. This will release any resources that have been built around the composition, including all onDispose callbacks that have been registered with CompositionLifecycleObserver objects.

It is important to call this for any Compose.composeInto call that is made, or else you may have memory leaks in your application.

Parameters
container: ViewGroup The view that was passed into Compose.composeInto as the root container of the composition
parent: CompositionReference? = null The parent composition reference, if applicable.

disposeComposition

@MainThread fun disposeComposition(
    container: Emittable,
    context: Context,
    parent: CompositionReference? = null
): Unit

Disposes any composition previously run with container as the root. This will release any resources that have been built around the composition, including all onDispose callbacks that have been registered with CompositionLifecycleObserver objects.

It is important to call this for any Compose.composeInto call that is made, or else you may have memory leaks in your application.

Parameters
container: Emittable The view that was passed into Compose.composeInto as the root container of the composition
context: Context The android Context associated with the composition
parent: CompositionReference? = null The parent composition reference, if applicable.

findRoot

fun findRoot(view: View): Component?

subcomposeInto

@MainThread fun subcomposeInto(
    container: Emittable,
    context: Context,
    parent: CompositionReference? = null,
    composable: () -> Unit
): CompositionContext