Recomposer
public class Recomposer(effectCoroutineContext: CoroutineContext) : CompositionContext()
The scheduler for performing recomposition and applying updates to one or more Compositions.
Functions
public fun asRecomposerInfo(): RecomposerInfo
Obtain a read-only RecomposerInfo for this Recomposer.
public 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.
@ExperimentalComposeApi
public 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 fun 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.
public fun 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.
public suspend fun join()
Await the completion of a cancel operation.
public suspend fun 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.
public fun 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).
public fun 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 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).
Companion Object
Properties
public val runningRecomposers: StateFlow<Set<RecomposerInfo>>
An observable Set of RecomposerInfos for currently
running Recomposers. Emitted sets are immutable.
