Google is committed to advancing racial equity for Black communities. See how.

TestMonotonicFrameClock

@ExperimentalCoroutinesApi class TestMonotonicFrameClock : MonotonicFrameClock
kotlin.Any
   ↳ androidx.compose.ui.test.TestMonotonicFrameClock

A MonotonicFrameClock with a time source controlled by a kotlinx-coroutines-test DelayController. This frame clock may be used to consistently drive time under controlled tests.

Calls to withFrameNanos will schedule an upcoming frame frameDelayNanos nanoseconds in the future by launching into coroutineScope if such a frame has not yet been scheduled. The current frame time for withFrameNanos is provided by delayController. It is strongly suggested that coroutineScope contain the test dispatcher controlled by delayController.

Summary

Public constructors
<init>(coroutineScope: CoroutineScope, delayController: DelayController, frameDelayNanos: Long = DefaultFrameDelay)

A MonotonicFrameClock with a time source controlled by a kotlinx-coroutines-test DelayController.

Public methods
suspend R
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.

Inherited extension functions
From androidx.compose.runtime.dispatch
suspend R
MonotonicFrameClock.withFrameMillis(crossinline onFrame: (frameTimeMillis: 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.

Properties
Long

Inherited properties
Extension properties
From androidx.compose.ui.test
Long

The frame delay time for the TestMonotonicFrameClock in milliseconds.

Public constructors

<init>

TestMonotonicFrameClock(
    coroutineScope: CoroutineScope,
    delayController: DelayController,
    frameDelayNanos: Long = DefaultFrameDelay)

A MonotonicFrameClock with a time source controlled by a kotlinx-coroutines-test DelayController. This frame clock may be used to consistently drive time under controlled tests.

Calls to withFrameNanos will schedule an upcoming frame frameDelayNanos nanoseconds in the future by launching into coroutineScope if such a frame has not yet been scheduled. The current frame time for withFrameNanos is provided by delayController. It is strongly suggested that coroutineScope contain the test dispatcher controlled by delayController.

Public methods

withFrameNanos

suspend fun <R> 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 monotonically increasing; after a call to withFrameNanos completes it must not provide the same value again for a subsequent call.

Properties

frameDelayNanos

val frameDelayNanos: Long