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

Recomposer

public final class Recomposer extends CompositionContext

java.lang.Object
   ↳ androidx.compose.runtime.CompositionContext
     ↳ androidx.compose.runtime.Recomposer

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

Summary

Nested types

@ThreadLocal
public static class Recomposer.Companion

hack: the companion object is thread local in Kotlin/Native to avoid freezing _runningRecomposers with the current memory model.

public enum Recomposer.State extends Enum

Valid operational states of a Recomposer.

Public constructors

Recomposer(@NonNull CoroutineContext effectCoroutineContext)

Public methods

final @NonNull RecomposerInfo

Obtain a read-only RecomposerInfo for this Recomposer.

final void

Suspends until the currently pending recomposition frame is complete.

final void

Permanently shut down this Recomposer for future use.

final void

Close this Recomposer.

final long

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

final @NonNull <Error class: unknown class><@NonNull Recomposer.State>

The current State of this Recomposer, available synchronously.

@NonNull CoroutineContext

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

final boolean

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

final @NonNull <Error class: unknown class><@NonNull Recomposer.State>

The current State of this Recomposer.

final void

Await the completion of a cancel operation.

final void

Pause broadcasting the frame clock while recomposing.

final void

Resume broadcasting the frame clock after is has been paused.

final void

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

final void

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

Public constructors

Recomposer

public Recomposer(@NonNull CoroutineContext effectCoroutineContext)

Public methods

asRecomposerInfo

public final @NonNull RecomposerInfo asRecomposerInfo()

Obtain a read-only RecomposerInfo for this Recomposer.

awaitIdle

public final void awaitIdle()

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

public final void cancel()

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

public final void close()

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.

getChangeCount

public final long getChangeCount()

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.

getCurrentState

public final @NonNull <Error class: unknown class><@NonNull Recomposer.StategetCurrentState()

The current State of this Recomposer, available synchronously.

getEffectCoroutineContext

public @NonNull CoroutineContext getEffectCoroutineContext()

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

getHasPendingWork

public final boolean getHasPendingWork()

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

getState

public final @NonNull <Error class: unknown class><@NonNull Recomposer.StategetState()

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

join

public final void join()

Await the completion of a cancel operation.

pauseCompositionFrameClock

public final void pauseCompositionFrameClock()

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

public final void resumeCompositionFrameClock()

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 withFrameNaons 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

public final void runRecomposeAndApplyChanges()

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
public final void runRecomposeConcurrentlyAndApplyChanges(
    @NonNull CoroutineContext recomposeCoroutineContext
)

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.