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

MonotonicFrameClockKt

public final class MonotonicFrameClockKt


Summary

Public methods

static final @NonNull MonotonicFrameClock

Returns the MonotonicFrameClock for this CoroutineContext or throws IllegalStateException if one is not present.

static final @NonNull R
<R extends Object> withFrameMillis(
    @NonNull Function1<@NonNull Long, @NonNull R> onFrame
)

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

static final @NonNull R
<R extends Object> withFrameMillis(
    @NonNull MonotonicFrameClock receiver,
    @NonNull Function1<@NonNull Long, @NonNull R> onFrame
)

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

static final @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.

Public methods

getMonotonicFrameClock

public static final @NonNull MonotonicFrameClock getMonotonicFrameClock(@NonNull CoroutineContext receiver)

Returns the MonotonicFrameClock for this CoroutineContext or throws IllegalStateException if one is not present.

withFrameMillis

public static final @NonNull R <R extends Object> withFrameMillis(
    @NonNull Function1<@NonNull Long, @NonNull R> onFrame
)

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

frameTimeMillis 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 MonotonicFrameClock.withFrameMillis is implementation defined. Time values provided are monotonically increasing; after a call to withFrameMillis completes it must not provide a smaller value for a subsequent call.

This function will invoke MonotonicFrameClock.withFrameNanos using the calling CoroutineContext's MonotonicFrameClock and will throw an IllegalStateException if one is not present in the CoroutineContext.

withFrameMillis

public static final @NonNull R <R extends Object> withFrameMillis(
    @NonNull MonotonicFrameClock receiver,
    @NonNull Function1<@NonNull Long, @NonNull R> onFrame
)

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

frameTimeMillis 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 MonotonicFrameClock.withFrameMillis is implementation defined. Time values provided are monotonically increasing; after a call to withFrameMillis completes it must not provide a smaller value for a subsequent call.

withFrameNanos

public static final @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.

This function will invoke MonotonicFrameClock.withFrameNanos using the calling CoroutineContext's MonotonicFrameClock and will throw an IllegalStateException if one is not present in the CoroutineContext.