{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

Composition

public interface Composition

Known direct subclasses
ControlledComposition

A controlled composition is a Composition that can be directly controlled by the caller.


A composition object is usually constructed for you, and returned from an API that is used to initially compose a UI. For instance, setContent returns a Composition.

The dispose method should be used when you would like to dispose of the UI and the Composition.

Summary

Public methods

abstract void

Clear the hierarchy that was created from the composition and release resources allocated for composition.

abstract boolean

Returns true if any pending invalidations have been scheduled.

abstract boolean

True if dispose has been called.

abstract void
setContent(@Composable @NonNull Function0<Unit> content)

Update the composition with the content described by the content composable.

Public methods

dispose

abstract void dispose()

Clear the hierarchy that was created from the composition and release resources allocated for composition. After calling dispose the composition will no longer be recomposed and calling setContent will throw an IllegalStateException. Calling dispose is idempotent, all calls after the first are a no-op.

getHasInvalidations

abstract boolean getHasInvalidations()

Returns true if any pending invalidations have been scheduled. An invalidation is schedule if RecomposeScope.invalidate has been called on any composition scopes create for the composition.

Modifying MutableState.value of a value produced by mutableStateOf will automatically call RecomposeScope.invalidate for any scope that read State.value of the mutable state instance during composition.

isDisposed

abstract boolean isDisposed()

True if dispose has been called.

setContent

abstract void setContent(@Composable @NonNull Function0<Unit> content)

Update the composition with the content described by the content composable. After this has been called the changes to produce the initial composition has been calculated and applied to the composition.

Will throw an IllegalStateException if the composition has been disposed.

Parameters
@Composable @NonNull Function0<Unit> content

A composable function that describes the content of the composition.

Throws
kotlin.IllegalStateException

thrown in the composition has been disposed.