# MonotonicFrameClock

Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/MonotonicFrameClock.kt+class:androidx.compose.runtime.MonotonicFrameClock) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0) Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  interface MonotonicFrameClock : CoroutineContext.Element
  ```
Known direct subclasses [AndroidUiFrameClock](https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/AndroidUiFrameClock), [BroadcastFrameClock](https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock), [PausableMonotonicFrameClock](https://developer.android.com/reference/kotlin/androidx/compose/runtime/PausableMonotonicFrameClock), [TestMonotonicFrameClock](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/TestMonotonicFrameClock)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/AndroidUiFrameClock` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock` | A simple frame clock. |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/PausableMonotonicFrameClock` | A `https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock` wrapper that can be `https://developer.android.com/reference/kotlin/androidx/compose/runtime/PausableMonotonicFrameClock#pause()`d and `https://developer.android.com/reference/kotlin/androidx/compose/runtime/PausableMonotonicFrameClock#resume()`d. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/TestMonotonicFrameClock` | A `https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock` with a time source controlled by a `kotlinx-coroutines-test` `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/index.html`. |

*** ** * ** ***

Provides a time source for display frames and the ability to perform an action on the next frame. This may be used for matching timing with the refresh rate of a display or otherwise synchronizing work with a desired frame rate.

## Summary

| ### Nested types |
|---|
| `object https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock.Key : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-key/index.html<https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock>` |

| ### Public functions |
|---|---|---|
| `suspend R` | `<R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock#withFrameNanos(kotlin.Function1)(onFrame: (frameTimeNanos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) -> R)` Suspends until a new frame is requested, immediately invokes `https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock#withFrameNanos(kotlin.Function1)` with the frame time in nanoseconds in the calling context of frame dispatch, then resumes with the result from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock#withFrameNanos(kotlin.Function1)`. | Cmn |

| ### Public properties |
|---|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-key/index.html<*>` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock#key()` | Cmn |

| ### Extension functions |
|---|---|---|
| `suspend inline R` | `<R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock.https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock#(androidx.compose.runtime.MonotonicFrameClock).withFrameMillis(kotlin.Function1)( crossinline onFrame: (frameTimeMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) -> R )` Suspends until a new frame is requested, immediately invokes `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#(androidx.compose.runtime.MonotonicFrameClock).withFrameMillis(kotlin.Function1)` with the frame time in milliseconds in the calling context of frame dispatch, then resumes with the result from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#(androidx.compose.runtime.MonotonicFrameClock).withFrameMillis(kotlin.Function1)`. | Cmn |

### Inherited functions

From [kotlin.coroutines.CoroutineContext](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html) `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/plus.html(context: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html)` Cmn From [kotlin.coroutines.CoroutineContext.Element](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/index.html) `open R` `<R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/fold.html(initial: R, operation: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/index.html, R) -> R)` Cmn `open operator E?` `<E : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/index.html> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/get.html(key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-key/index.html<E>)` Cmn `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/minus-key.html(key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-key/index.html<*>)` Cmn

## Public functions

### withFrameNanos

Cmn

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

Suspends until a new frame is requested, immediately invokes `https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock#withFrameNanos(kotlin.Function1)` with the frame time in nanoseconds in the calling context of frame dispatch, then resumes with the result from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock#withFrameNanos(kotlin.Function1)`.

`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 `https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock#withFrameNanos(kotlin.Function1)` is implementation defined. Time values provided are strictly monotonically increasing; after a call to `https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock#withFrameNanos(kotlin.Function1)` completes it must not provide the same value again for a subsequent call.

## Public properties

### key

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
open val key: CoroutineContext.Key<*>
```

## Extension functions

### MonotonicFrameClock.withFrameMillis

Cmn Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/MonotonicFrameClock.kt+function:withFrameMillis)

```
suspend inline fun <R : Any?> MonotonicFrameClock.withFrameMillis(
    crossinline onFrame: (frameTimeMillis: Long) -> R
): R
```

Suspends until a new frame is requested, immediately invokes `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#(androidx.compose.runtime.MonotonicFrameClock).withFrameMillis(kotlin.Function1)` with the frame time in milliseconds in the calling context of frame dispatch, then resumes with the result from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#(androidx.compose.runtime.MonotonicFrameClock).withFrameMillis(kotlin.Function1)`.

`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 `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#(androidx.compose.runtime.MonotonicFrameClock).withFrameMillis(kotlin.Function1)` is implementation defined. Time values provided are monotonically increasing; after a call to `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#(androidx.compose.runtime.MonotonicFrameClock).withFrameMillis(kotlin.Function1)` completes it must not provide a smaller value for a subsequent call.