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

PausableMonotonicFrameClock

public final class PausableMonotonicFrameClock implements MonotonicFrameClock


A MonotonicFrameClock wrapper that can be paused and resumed.

A paused clock will not dispatch withFrameNanos events until it is resumed. Pausing a clock does not stop or change the frame times reported to withFrameNanos calls; the clock times reported will always remain consistent with frameClock.

PausableMonotonicFrameClock should be used in cases where frames should not be produced under some conditions, such as when a window hosting a UI is not currently visible. As clock times are not altered from the source frameClock, animations in progress may be fully complete by the time the clock is resumed and a new frame is produced.

Summary

Public constructors

Public methods

final boolean

true if this clock is currently paused or false if this clock is currently resumed.

final void

Pause the generation of frames.

final void

Resume the generation of frames.

@NonNull R
<R extends Object> withFrameNanos(
    @NonNull Function1<@NonNull Long, @NonNull R> onFrame
)

Suspends until a new frame is requested, immediately invokes onFrame with the frame time in nanoseconds in the calling context of frame dispatch, then resumes with the result from onFrame.

Inherited methods

From kotlin.coroutines.CoroutineContext
From kotlin.coroutines.CoroutineContext.Element
@NonNull R
<R extends Object> fold(
    @NonNull R initial,
    @NonNull Function2<@NonNull R, @NonNull CoroutineContext.Element, @NonNull R> operation
)
E
@NonNull CoroutineContext
From androidx.compose.runtime.MonotonicFrameClock

Public constructors

PausableMonotonicFrameClock

public PausableMonotonicFrameClock(@NonNull MonotonicFrameClock frameClock)

Public methods

isPaused

public final boolean isPaused()

true if this clock is currently paused or false if this clock is currently resumed. A PausableMonotonicFrameClock is not paused at construction time.

pause

public final void pause()

Pause the generation of frames. Pausing a clock that is already paused has no effect. While the clock is paused any calls to withFrameNanos will suspend until the clock is resumed before delegating to the wrapped frameClock's withFrameNanos method. Call resume to resume generating frames.

resume

public final void resume()

Resume the generation of frames. Any queued calls to withFrameNanos will resume and delegate to the wrapped frameClock's withFrameNanos method.

withFrameNanos

public @NonNull R <R extends Object> withFrameNanos(
    @NonNull Function1<@NonNull Long, @NonNull R> onFrame
)

Suspends until a new frame is requested, immediately invokes onFrame with the frame time in nanoseconds in the calling context of frame dispatch, then resumes with the result from onFrame.

frameTimeNanos should be used when calculating animation time deltas from frame to frame as it may be normalized to the target time for the frame, not necessarily a direct, "now" value.

The time base of the value provided by withFrameNanos is implementation defined. Time values provided are strictly monotonically increasing; after a call to withFrameNanos completes it must not provide the same value again for a subsequent call.