Recomposer


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

Summary

Nested types

Valid operational states of a Recomposer.

Public companion properties

StateFlow<Set<RecomposerInfo>>

An observable Set of RecomposerInfos for currently running Recomposers.

Cmn

Public constructors

Recomposer(effectCoroutineContext: CoroutineContext)
Cmn

Public functions

RecomposerInfo

Obtain a read-only RecomposerInfo for this Recomposer.

Cmn
suspend Unit

Suspends until the currently pending recomposition frame is complete.

Cmn
Unit

Permanently shut down this Recomposer for future use.

Cmn
Unit

Close this Recomposer.

Cmn
suspend Unit

Await the completion of a cancel operation.

Cmn
Unit

Pause broadcasting the frame clock while recomposing.

Cmn
Unit

Resume broadcasting the frame clock after is has been paused.

Cmn
suspend Unit

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

Cmn
suspend Unit

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

Cmn

Public properties

Long

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

Cmn
StateFlow<Recomposer.State>

The current State of this Recomposer, available synchronously.

Cmn
open CoroutineContext

The effectCoroutineContext is derived from the parameter of the same name.

Cmn
Boolean

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

Cmn
Flow<Recomposer.State>

This property is deprecated. Replaced by currentState as a StateFlow

Cmn

Public companion properties

runningRecomposers

val runningRecomposersStateFlow<Set<RecomposerInfo>>

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

Public constructors

Recomposer

Recomposer(effectCoroutineContext: CoroutineContext)

Public functions

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. currentState will immediately reflect State.ShuttingDown (or a lower state) before this call returns. 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.

pauseCompositionFrameClock

fun pauseCompositionFrameClock(): Unit

Pause broadcasting the frame clock while recomposing. This effectively pauses animations, or any other use of the withFrameNanos, while the frame clock is paused.

pauseCompositionFrameClock should be called when the recomposer is not being displayed for some reason such as not being the current activity in Android, for example.

Calls to pauseCompositionFrameClock are thread-safe and idempotent (calling it when the frame clock is already paused is a no-op).

resumeCompositionFrameClock

fun resumeCompositionFrameClock(): Unit

Resume broadcasting the frame clock after is has been paused. Pending calls to withFrameNanos will start receiving frame clock broadcasts at the beginning of the frame and a frame will be requested if there are pending calls to withFrameNanos if a frame has not already been scheduled.

Calls to resumeCompositionFrameClock are thread-safe and idempotent (calling it when the frame clock is running is a no-op).

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

@ExperimentalComposeApi
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.

Public properties

changeCount

val changeCountLong

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.

currentState

val currentStateStateFlow<Recomposer.State>

The current State of this Recomposer, available synchronously.

effectCoroutineContext

open val effectCoroutineContextCoroutineContext

The effectCoroutineContext is derived from the parameter of the same name.

hasPendingWork

val hasPendingWorkBoolean

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

state

val stateFlow<Recomposer.State>

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