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

ManualFrameClock

class ManualFrameClock : MonotonicFrameClock
kotlin.Any
   ↳ androidx.compose.animation.core.ManualFrameClock

A MonotonicFrameClock built on a BroadcastFrameClock that keeps track of the current time.

For backwards compatibility with the older ManualAnimationClock, which immediately calls the subscriber's callback with the current time, supply dispatchOnSubscribe to the constructor.

Summary

Public constructors
<init>(initialTime: Long = 0L)

<init>(initialTime: Long = 0L, dispatchOnSubscribe: Boolean)

A MonotonicFrameClock built on a BroadcastFrameClock that keeps track of the current time.

Public methods
Unit

Advances the clock by the given number of nanoseconds.

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.

Extension functions
From androidx.compose.animation.core
Unit

Advances the clock by the given number of milliseconds.

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

The current time of this frame clock, in nanoseconds.

Boolean

Whether or not there are currently routines awaiting a frame from this clock.

Inherited properties

Public constructors

<init>

ManualFrameClock(initialTime: Long = 0L)

<init>

ManualFrameClock(
    initialTime: Long = 0L,
    dispatchOnSubscribe: Boolean)

A MonotonicFrameClock built on a BroadcastFrameClock that keeps track of the current time.

For backwards compatibility with the older ManualAnimationClock, which immediately calls the subscriber's callback with the current time, supply dispatchOnSubscribe to the constructor.

Public methods

advanceClock

fun advanceClock(nanos: Long): Unit

Advances the clock by the given number of nanoseconds. One frame will be sent, with a frame time that is nanos nanoseconds after the last frame time (or after the initial time, if no frames have been sent yet).

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

currentTime

var currentTime: Long

The current time of this frame clock, in nanoseconds.

hasAwaiters

val hasAwaiters: Boolean

Whether or not there are currently routines awaiting a frame from this clock.

Note that immediately after advanceClock, coroutines that have received a frame time might not have had their continuation run yet. This can lead to hasAwaiters returning false, even though those coroutines may request another frame immediately when they are continued. To work around this caveat, make sure that those coroutines have run before calling hasAwaiters. For example, withContext(AndroidUiDispatcher.Main) {} will finish when all work currently scheduled on the AndroidUiDispatcher is done.