Recomposer
-
Cmn
class Recomposer : CompositionContext
The scheduler for performing recomposition and applying updates to one or more Compositions.
Summary
Nested types |
|---|
enum Recomposer.State : EnumValid operational states of a |
Public companion properties |
||
|---|---|---|
StateFlow<Set<RecomposerInfo>> |
An observable |
Cmn
|
Public constructors |
|
|---|---|
Recomposer(effectCoroutineContext: CoroutineContext) |
Cmn
|
Public functions |
||
|---|---|---|
RecomposerInfo |
Obtain a read-only |
Cmn
|
suspend Unit |
Suspends until the currently pending recomposition frame is complete. |
Cmn
|
Unit |
cancel()Permanently shut down this |
Cmn
|
Unit |
close()Close this |
Cmn
|
suspend Unit |
join()Await the completion of a |
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 |
Cmn
|
suspend Unit |
@ExperimentalComposeApiAwait the invalidation of any associated |
Cmn
|
open CancellationHandle |
scheduleFrameEndCallback(action: () -> Unit)Schedules an |
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 |
Cmn
|
open CoroutineContext |
The |
Cmn
|
Boolean |
|
Cmn
|
Flow<Recomposer.State> |
This property is deprecated. Replaced by currentState as a StateFlow |
Cmn
|
Extension functions |
||
|---|---|---|
CompositionObserverHandle |
Register an observer to be notified when a composition is added to or removed from the given |
Cmn
|
Public companion properties
runningRecomposers
val runningRecomposers: StateFlow<Set<RecomposerInfo>>
An observable Set of RecomposerInfos for currently running Recomposers. Emitted sets are immutable.
Public constructors
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.
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.
scheduleFrameEndCallback
open fun scheduleFrameEndCallback(action: () -> Unit): CancellationHandle
Schedules an action to be invoked when the recomposer finishes the next composition of a frame (including the completion of subcompositions). If a frame is currently in-progress, action will be invoked when the current frame fully finishes composing. If a frame isn't currently in-progress, a new frame will be scheduled (if one hasn't been already) and action will execute at the completion of the next frame's composition. If a new frame is scheduled and there is no other work to execute, action will still execute.
action will always execute on the applier thread.
| Returns | |
|---|---|
CancellationHandle |
A |
Public properties
changeCount
val 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.
currentState
val currentState: StateFlow<Recomposer.State>
The current State of this Recomposer, available synchronously.
effectCoroutineContext
open val effectCoroutineContext: CoroutineContext
The effectCoroutineContext is derived from the parameter of the same name.
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.
Extension functions
observe
@ExperimentalComposeRuntimeApi
fun Recomposer.observe(observer: CompositionRegistrationObserver): CompositionObserverHandle
Register an observer to be notified when a composition is added to or removed from the given Recomposer. When this method is called, the observer will be notified of all currently registered compositions per the documentation in CompositionRegistrationObserver.onCompositionRegistered.
| Parameters | |
|---|---|
observer: CompositionRegistrationObserver |
the observer that will be informed of new compositions registered with this |
| Returns | |
|---|---|
CompositionObserverHandle |
a handle that allows the observer to be disposed and detached from the |