PausableMonotonicFrameClock

  • Common/All
  • Android/JVM

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

Cmn

Public functions

Unit

Pause the generation of frames.

Cmn
Unit

Resume the generation of frames.

Cmn
open suspend R
<R : Any?> withFrameNanos(onFrame: (frameTimeNanos: Long) -> R)

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.

Cmn

Public properties

Boolean

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

Cmn

Inherited functions

open operator CoroutineContext
Cmn
open R
<R : Any?> fold(initial: R, operation: (CoroutineContext.Element, R) -> R)
Cmn
open operator E?
Cmn
open CoroutineContext
Cmn

Public constructors

PausableMonotonicFrameClock

PausableMonotonicFrameClock(frameClock: MonotonicFrameClock)

Public functions

pause

fun pause(): Unit

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

fun resume(): Unit

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

withFrameNanos

open suspend fun <R : Any?> withFrameNanos(onFrame: (frameTimeNanos: Long) -> R): R

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.

Public properties

isPaused

val isPausedBoolean

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