ManualFrameClock
class ManualFrameClock : MonotonicFrameClock
kotlin.Any | |
↳ | androidx.compose.animation.core.ManualFrameClock |
A MonotonicFrameClock built on a BroadcastFrameClock that keeps track of the current time.
Summary
Public constructors | |
---|---|
A MonotonicFrameClock built on a BroadcastFrameClock that keeps track of the current time. |
Public methods | |
---|---|
Unit |
advanceClock(nanos: Long) 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
|
Inherited extension functions | ||
---|---|---|
From androidx.compose.runtime
|
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)
A MonotonicFrameClock built on a BroadcastFrameClock that keeps track of the current time.
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
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.