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

MonotonicFrameAnimationClock

class MonotonicFrameAnimationClock : AnimationClockObservable
kotlin.Any
   ↳ androidx.compose.animation.core.MonotonicFrameAnimationClock

A MonotonicFrameAnimationClock is an AnimationClockObservable that is built on top of the MonotonicFrameClock found in the given scope. Use this when you want to use APIs that require the old AnimationClockObservable, but your clock is a coroutine based MonotonicFrameClock. If the scope doesn't contain a frame clock, the DefaultMonotonicFrameClock is used.

Since a frame clock is a coroutine element, you can add it to an existing scope using composition:

withContext(ManualFrameClock(0L) + CoroutineName("Scope with a manually driven clock")) {
    withFrameMillis {
        // ...
    }
}

Note that some coroutine contexts define a default frame clock, so make sure you add your frame clock to a context (context + clock) instead of the other way around (clock + context).

Summary

Public constructors

A MonotonicFrameAnimationClock is an AnimationClockObservable that is built on top of the MonotonicFrameClock found in the given scope.

Public methods
Unit

Subscribes an observer to the animation clock source.

Unit

Unsubscribes an observer from the animation clock.

Inherited extension functions
From androidx.compose.animation
DisposableAnimationClock

Return a new AnimationClockObservable wrapping this one that will auto-unsubscribe all AnimationClockObservers when this call leaves the composition, preventing clock subscriptions from persisting beyond the composition lifecycle.

Properties
Boolean

Public constructors

<init>

MonotonicFrameAnimationClock(scope: CoroutineScope)

A MonotonicFrameAnimationClock is an AnimationClockObservable that is built on top of the MonotonicFrameClock found in the given scope. Use this when you want to use APIs that require the old AnimationClockObservable, but your clock is a coroutine based MonotonicFrameClock. If the scope doesn't contain a frame clock, the DefaultMonotonicFrameClock is used.

Since a frame clock is a coroutine element, you can add it to an existing scope using composition:

withContext(ManualFrameClock(0L) + CoroutineName("Scope with a manually driven clock")) {
    withFrameMillis {
        // ...
    }
}

Note that some coroutine contexts define a default frame clock, so make sure you add your frame clock to a context (context + clock) instead of the other way around (clock + context).

Public methods

subscribe

fun subscribe(observer: AnimationClockObserver): Unit

Subscribes an observer to the animation clock source.

Observers may only be added to a clock once. Calls to add the same observer more than once will be ignored, and a single call to unsubscribe will unregister from further callbacks.

Parameters
observer: AnimationClockObserver The observer that will be notified when animation clock time is updated.

unsubscribe

fun unsubscribe(observer: AnimationClockObserver): Unit

Unsubscribes an observer from the animation clock.

Observers may only be added to a clock once. If subscribe has been called multiple times with the same observer, a single call to this method will unregister the observer completely.

Parameters
observer: AnimationClockObserver The observer to be removed from the subscription list.

Properties

hasObservers

val hasObservers: Boolean