Android 12 Developer Preview is here! Try it out, and give us your feedback!

Recomposer

class Recomposer : CompositionContext
kotlin.Any
   ↳ androidx.compose.runtime.CompositionContext
   ↳ androidx.compose.runtime.Recomposer

The scheduler for performing recomposition and applying updates to one or more Compositions.

Summary

Nested classes
enum

Valid operational states of a Recomposer.

Public constructors
<init>(effectCoroutineContext: CoroutineContext)

The scheduler for performing recomposition and applying updates to one or more Compositions.

Public methods
RecomposerInfo

Obtain a read-only RecomposerInfo for this Recomposer.

suspend Unit

Suspends until the currently pending recomposition frame is complete.

Unit

Permanently shut down this Recomposer for future use.

Unit

Close this Recomposer.

suspend Unit

Await the completion of a cancel operation.

suspend Unit

Await the invalidation of any associated Composers, recompose them, and apply their changes to their associated Compositions if recomposition is successful.

suspend Unit

Await the invalidation of any associated Composers, recompose them, and apply their changes to their associated Compositions if recomposition is successful.

Properties
Long

This is a running count of the number of times the recomposer awoke and applied changes to one or more composers.

Boolean

true if this Recomposer has any pending work scheduled, regardless of whether or not it is currently running.

Flow<Recomposer.State>

The current State of this Recomposer.

Companion properties
StateFlow<Set<RecomposerInfo>>

An observable Set of RecomposerInfos for currently running Recomposers.

Public constructors

<init>

Recomposer(effectCoroutineContext: CoroutineContext)

The scheduler for performing recomposition and applying updates to one or more Compositions.

Public methods

asRecomposerInfo

fun asRecomposerInfo(): RecomposerInfo

Obtain a read-only RecomposerInfo for this Recomposer.

awaitIdle

suspend fun awaitIdle(): Unit

Suspends until the currently pending recomposition frame is complete. Any recomposition for this recomposer triggered by actions before this call begins will be complete and applied (if recomposition was successful) when this call returns.

If runRecomposeAndApplyChanges is not currently running the Recomposer is considered idle and this method will not suspend.

cancel

fun cancel(): Unit

Permanently shut down this Recomposer for future use. All ongoing recompositions will stop, new composer invalidations with this Recomposer at the root will no longer occur, and any LaunchedEffects currently running in compositions managed by this Recomposer will be cancelled. Any rememberCoroutineScope scopes from compositions managed by this Recomposer will also be cancelled. See join to await the completion of all of these outstanding tasks.

close

fun close(): Unit

Close this Recomposer. Once all effects launched by managed compositions complete, any active call to runRecomposeAndApplyChanges will return normally and this Recomposer will be State.ShutDown. See join to await the completion of all of these outstanding tasks.

join

suspend fun join(): Unit

Await the completion of a cancel operation.

runRecomposeAndApplyChanges

suspend fun runRecomposeAndApplyChanges(): Unit

Await the invalidation of any associated Composers, recompose them, and apply their changes to their associated Compositions if recomposition is successful.

While runRecomposeAndApplyChanges is running, awaitIdle will suspend until there are no more invalid composers awaiting recomposition.

This method will not return unless the Recomposer is closed and all effects in managed compositions complete. Unhandled failure exceptions from child coroutines will be thrown by this method.

runRecomposeConcurrentlyAndApplyChanges

suspend fun runRecomposeConcurrentlyAndApplyChanges(recomposeCoroutineContext: CoroutineContext): Unit

Await the invalidation of any associated Composers, recompose them, and apply their changes to their associated Compositions if recomposition is successful.

While runRecomposeConcurrentlyAndApplyChanges is running, awaitIdle will suspend until there are no more invalid composers awaiting recomposition.

Recomposition of invalidated composers will occur in recomposeCoroutineContext. recomposeCoroutineContext must not contain a Job.

This method will not return unless the Recomposer is closed and all effects in managed compositions complete. Unhandled failure exceptions from child coroutines will be thrown by this method.

Properties

changeCount

var changeCount: Long

This is a running count of the number of times the recomposer awoke and applied changes to one or more composers. This count is unaffected if the composer awakes and recomposed but composition did not produce changes to apply.

hasPendingWork

val hasPendingWork: Boolean

true if this Recomposer has any pending work scheduled, regardless of whether or not it is currently running.

state

val state: Flow<Recomposer.State>

The current State of this Recomposer. See each State value for its meaning.

Companion properties

runningRecomposers

val runningRecomposers: StateFlow<Set<RecomposerInfo>>

An observable Set of RecomposerInfos for currently running Recomposers. Emitted sets are immutable.