Merge "Rename awaitFrameNanos to withFrameNanos" into androidx-master-dev
diff --git a/compose/compose-runtime/api/0.1.0-dev14.txt b/compose/compose-runtime/api/0.1.0-dev14.txt
index d440507..8026f0c 100644
--- a/compose/compose-runtime/api/0.1.0-dev14.txt
+++ b/compose/compose-runtime/api/0.1.0-dev14.txt
@@ -27,8 +27,8 @@
public final class AndroidUiCompositionFrameClock implements androidx.compose.CompositionFrameClock {
ctor public AndroidUiCompositionFrameClock(android.view.Choreographer choreographer);
- method public suspend <R> Object? awaitFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
method public android.view.Choreographer getChoreographer();
+ method public suspend <R> Object? withFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
}
public final class AndroidUiDispatcher extends kotlinx.coroutines.CoroutineDispatcher {
@@ -181,13 +181,15 @@
}
public interface CompositionFrameClock {
- method public suspend <R> Object? awaitFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
+ method @Deprecated public default suspend <R> Object? awaitFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
+ method public suspend <R> Object? withFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
}
public final class CompositionFrameClockKt {
- method public static suspend inline <R> Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
- method public static suspend Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
- method public static suspend Object? awaitFrameNanos(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
+ method @Deprecated public static suspend inline <R> Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
+ method @Deprecated public static suspend Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
+ method @Deprecated public static suspend Object? awaitFrameNanos(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
+ method public static suspend inline <R> Object? withFrameMillis(androidx.compose.CompositionFrameClock, kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
}
public final class CompositionKt {
diff --git a/compose/compose-runtime/api/current.txt b/compose/compose-runtime/api/current.txt
index d440507..8026f0c 100644
--- a/compose/compose-runtime/api/current.txt
+++ b/compose/compose-runtime/api/current.txt
@@ -27,8 +27,8 @@
public final class AndroidUiCompositionFrameClock implements androidx.compose.CompositionFrameClock {
ctor public AndroidUiCompositionFrameClock(android.view.Choreographer choreographer);
- method public suspend <R> Object? awaitFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
method public android.view.Choreographer getChoreographer();
+ method public suspend <R> Object? withFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
}
public final class AndroidUiDispatcher extends kotlinx.coroutines.CoroutineDispatcher {
@@ -181,13 +181,15 @@
}
public interface CompositionFrameClock {
- method public suspend <R> Object? awaitFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
+ method @Deprecated public default suspend <R> Object? awaitFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
+ method public suspend <R> Object? withFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
}
public final class CompositionFrameClockKt {
- method public static suspend inline <R> Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
- method public static suspend Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
- method public static suspend Object? awaitFrameNanos(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
+ method @Deprecated public static suspend inline <R> Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
+ method @Deprecated public static suspend Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
+ method @Deprecated public static suspend Object? awaitFrameNanos(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
+ method public static suspend inline <R> Object? withFrameMillis(androidx.compose.CompositionFrameClock, kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
}
public final class CompositionKt {
diff --git a/compose/compose-runtime/api/public_plus_experimental_0.1.0-dev14.txt b/compose/compose-runtime/api/public_plus_experimental_0.1.0-dev14.txt
index d440507..8026f0c 100644
--- a/compose/compose-runtime/api/public_plus_experimental_0.1.0-dev14.txt
+++ b/compose/compose-runtime/api/public_plus_experimental_0.1.0-dev14.txt
@@ -27,8 +27,8 @@
public final class AndroidUiCompositionFrameClock implements androidx.compose.CompositionFrameClock {
ctor public AndroidUiCompositionFrameClock(android.view.Choreographer choreographer);
- method public suspend <R> Object? awaitFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
method public android.view.Choreographer getChoreographer();
+ method public suspend <R> Object? withFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
}
public final class AndroidUiDispatcher extends kotlinx.coroutines.CoroutineDispatcher {
@@ -181,13 +181,15 @@
}
public interface CompositionFrameClock {
- method public suspend <R> Object? awaitFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
+ method @Deprecated public default suspend <R> Object? awaitFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
+ method public suspend <R> Object? withFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
}
public final class CompositionFrameClockKt {
- method public static suspend inline <R> Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
- method public static suspend Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
- method public static suspend Object? awaitFrameNanos(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
+ method @Deprecated public static suspend inline <R> Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
+ method @Deprecated public static suspend Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
+ method @Deprecated public static suspend Object? awaitFrameNanos(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
+ method public static suspend inline <R> Object? withFrameMillis(androidx.compose.CompositionFrameClock, kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
}
public final class CompositionKt {
diff --git a/compose/compose-runtime/api/public_plus_experimental_current.txt b/compose/compose-runtime/api/public_plus_experimental_current.txt
index d440507..8026f0c 100644
--- a/compose/compose-runtime/api/public_plus_experimental_current.txt
+++ b/compose/compose-runtime/api/public_plus_experimental_current.txt
@@ -27,8 +27,8 @@
public final class AndroidUiCompositionFrameClock implements androidx.compose.CompositionFrameClock {
ctor public AndroidUiCompositionFrameClock(android.view.Choreographer choreographer);
- method public suspend <R> Object? awaitFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
method public android.view.Choreographer getChoreographer();
+ method public suspend <R> Object? withFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
}
public final class AndroidUiDispatcher extends kotlinx.coroutines.CoroutineDispatcher {
@@ -181,13 +181,15 @@
}
public interface CompositionFrameClock {
- method public suspend <R> Object? awaitFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
+ method @Deprecated public default suspend <R> Object? awaitFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
+ method public suspend <R> Object? withFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
}
public final class CompositionFrameClockKt {
- method public static suspend inline <R> Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
- method public static suspend Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
- method public static suspend Object? awaitFrameNanos(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
+ method @Deprecated public static suspend inline <R> Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
+ method @Deprecated public static suspend Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
+ method @Deprecated public static suspend Object? awaitFrameNanos(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
+ method public static suspend inline <R> Object? withFrameMillis(androidx.compose.CompositionFrameClock, kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
}
public final class CompositionKt {
diff --git a/compose/compose-runtime/api/restricted_0.1.0-dev14.txt b/compose/compose-runtime/api/restricted_0.1.0-dev14.txt
index 3414a67..cb54f3a 100644
--- a/compose/compose-runtime/api/restricted_0.1.0-dev14.txt
+++ b/compose/compose-runtime/api/restricted_0.1.0-dev14.txt
@@ -27,8 +27,8 @@
public final class AndroidUiCompositionFrameClock implements androidx.compose.CompositionFrameClock {
ctor public AndroidUiCompositionFrameClock(android.view.Choreographer choreographer);
- method public suspend <R> Object? awaitFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
method public android.view.Choreographer getChoreographer();
+ method public suspend <R> Object? withFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
}
public final class AndroidUiDispatcher extends kotlinx.coroutines.CoroutineDispatcher {
@@ -196,13 +196,15 @@
}
public interface CompositionFrameClock {
- method public suspend <R> Object? awaitFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
+ method @Deprecated public default suspend <R> Object? awaitFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
+ method public suspend <R> Object? withFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
}
public final class CompositionFrameClockKt {
- method public static suspend inline <R> Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
- method public static suspend Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
- method public static suspend Object? awaitFrameNanos(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
+ method @Deprecated public static suspend inline <R> Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
+ method @Deprecated public static suspend Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
+ method @Deprecated public static suspend Object? awaitFrameNanos(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
+ method public static suspend inline <R> Object? withFrameMillis(androidx.compose.CompositionFrameClock, kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
}
public final class CompositionKt {
diff --git a/compose/compose-runtime/api/restricted_current.txt b/compose/compose-runtime/api/restricted_current.txt
index 3414a67..cb54f3a 100644
--- a/compose/compose-runtime/api/restricted_current.txt
+++ b/compose/compose-runtime/api/restricted_current.txt
@@ -27,8 +27,8 @@
public final class AndroidUiCompositionFrameClock implements androidx.compose.CompositionFrameClock {
ctor public AndroidUiCompositionFrameClock(android.view.Choreographer choreographer);
- method public suspend <R> Object? awaitFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
method public android.view.Choreographer getChoreographer();
+ method public suspend <R> Object? withFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
}
public final class AndroidUiDispatcher extends kotlinx.coroutines.CoroutineDispatcher {
@@ -196,13 +196,15 @@
}
public interface CompositionFrameClock {
- method public suspend <R> Object? awaitFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
+ method @Deprecated public default suspend <R> Object? awaitFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
+ method public suspend <R> Object? withFrameNanos(kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
}
public final class CompositionFrameClockKt {
- method public static suspend inline <R> Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
- method public static suspend Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
- method public static suspend Object? awaitFrameNanos(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
+ method @Deprecated public static suspend inline <R> Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
+ method @Deprecated public static suspend Object? awaitFrameMillis(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
+ method @Deprecated public static suspend Object? awaitFrameNanos(androidx.compose.CompositionFrameClock, kotlin.coroutines.Continuation<? super java.lang.Long> p);
+ method public static suspend inline <R> Object? withFrameMillis(androidx.compose.CompositionFrameClock, kotlin.jvm.functions.Function1<? super java.lang.Long,? extends R> onFrame, kotlin.coroutines.Continuation<? super R> p);
}
public final class CompositionKt {
diff --git a/compose/compose-runtime/src/androidAndroidTest/kotlin/androidx/compose/test/SuspendingEffectsTests.kt b/compose/compose-runtime/src/androidAndroidTest/kotlin/androidx/compose/test/SuspendingEffectsTests.kt
index 024ad4a..35bce1d 100644
--- a/compose/compose-runtime/src/androidAndroidTest/kotlin/androidx/compose/test/SuspendingEffectsTests.kt
+++ b/compose/compose-runtime/src/androidAndroidTest/kotlin/androidx/compose/test/SuspendingEffectsTests.kt
@@ -77,7 +77,7 @@
var awaitFrameTime by mutableStateOf(Long.MAX_VALUE)
compose {
launchInComposition {
- awaitFrameNanos {
+ withFrameNanos {
awaitFrameTime = it
}
}
diff --git a/compose/compose-runtime/src/androidMain/kotlin/androidx/compose/ActualAndroid.kt b/compose/compose-runtime/src/androidMain/kotlin/androidx/compose/ActualAndroid.kt
index 7316300..b261f5b 100644
--- a/compose/compose-runtime/src/androidMain/kotlin/androidx/compose/ActualAndroid.kt
+++ b/compose/compose-runtime/src/androidMain/kotlin/androidx/compose/ActualAndroid.kt
@@ -70,7 +70,7 @@
}
private object MainDispatcherCompositionFrameClock : CompositionFrameClock {
- override suspend fun <R> awaitFrameNanos(onFrame: (frameTimeNanos: Long) -> R): R =
+ override suspend fun <R> withFrameNanos(onFrame: (frameTimeNanos: Long) -> R): R =
withContext(Dispatchers.Main) {
onFrame(System.nanoTime())
}
diff --git a/compose/compose-runtime/src/androidMain/kotlin/androidx/compose/AndroidUiCompositionFrameClock.kt b/compose/compose-runtime/src/androidMain/kotlin/androidx/compose/AndroidUiCompositionFrameClock.kt
index 225fdf7..8651c94 100644
--- a/compose/compose-runtime/src/androidMain/kotlin/androidx/compose/AndroidUiCompositionFrameClock.kt
+++ b/compose/compose-runtime/src/androidMain/kotlin/androidx/compose/AndroidUiCompositionFrameClock.kt
@@ -28,7 +28,7 @@
val choreographer: Choreographer
) : CompositionFrameClock {
- override suspend fun <R> awaitFrameNanos(
+ override suspend fun <R> withFrameNanos(
onFrame: (Long) -> R
): R {
val uiDispatcher = coroutineContext[ContinuationInterceptor] as? AndroidUiDispatcher
@@ -41,8 +41,8 @@
// If we're on an AndroidUiDispatcher then we post callback to happen *after*
// the greedy trampoline dispatch is complete.
// This means that onFrame will run on the current choreographer frame if one is
- // already in progress, but awaitFrameNanos will *not* resume until the frame
- // is complete. This prevents multiple calls to awaitFrameNanos immediately dispatching
+ // already in progress, but withFrameNanos will *not* resume until the frame
+ // is complete. This prevents multiple calls to withFrameNanos immediately dispatching
// on the same frame.
if (uiDispatcher != null && uiDispatcher.choreographer == choreographer) {
diff --git a/compose/compose-runtime/src/commonMain/kotlin/androidx/compose/BroadcastFrameClock.kt b/compose/compose-runtime/src/commonMain/kotlin/androidx/compose/BroadcastFrameClock.kt
index c3f5d2a..5e0ec83 100644
--- a/compose/compose-runtime/src/commonMain/kotlin/androidx/compose/BroadcastFrameClock.kt
+++ b/compose/compose-runtime/src/commonMain/kotlin/androidx/compose/BroadcastFrameClock.kt
@@ -56,7 +56,7 @@
}
}
- override suspend fun <R> awaitFrameNanos(
+ override suspend fun <R> withFrameNanos(
onFrame: (Long) -> R
): R = suspendCancellableCoroutine { co ->
val awaiter = FrameAwaiter(onFrame, co)
diff --git a/compose/compose-runtime/src/commonMain/kotlin/androidx/compose/CompositionFrameClock.kt b/compose/compose-runtime/src/commonMain/kotlin/androidx/compose/CompositionFrameClock.kt
index e2ada0d..6a2e1c8 100644
--- a/compose/compose-runtime/src/commonMain/kotlin/androidx/compose/CompositionFrameClock.kt
+++ b/compose/compose-runtime/src/commonMain/kotlin/androidx/compose/CompositionFrameClock.kt
@@ -32,11 +32,28 @@
* 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 [awaitFrameNanos] is implementation defined.
- * Time values provided are monotonically increasing; after a call to [awaitFrameNanos]
+ * 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.
*/
- suspend fun <R> awaitFrameNanos(onFrame: (frameTimeNanos: Long) -> R): R
+ 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.
+ */
+ @Deprecated("renamed to withFrameNanos", ReplaceWith("withFrameNanos(onFrame)"))
+ suspend fun <R> awaitFrameNanos(onFrame: (frameTimeNanos: Long) -> R): R =
+ withFrameNanos(onFrame)
}
/**
@@ -48,16 +65,36 @@
* 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 [CompositionFrameClock.withFrameMillis] is
+ * implementation defined. Time values provided are monotonically increasing; after a call to
+ * [CompositionFrameClock.withFrameMillis] completes it must not provide the same value again for
+ * a subsequent call.
+ */
+@Suppress("UnnecessaryLambdaCreation")
+suspend inline fun <R> CompositionFrameClock.withFrameMillis(
+ crossinline onFrame: (frameTimeMillis: Long) -> R
+): R = withFrameNanos { onFrame(it / 1_000_000L) }
+
+/**
+ * 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 [awaitFrameNanos] is implementation defined.
* Time values provided are monotonically increasing; after a call to [awaitFrameNanos]
* completes it must not provide the same value again for a subsequent call.
*/
-@Suppress("UnnecessaryLambdaCreation")
+@Deprecated(
+ "renamed to withFrameMillis",
+ ReplaceWith("withFrameMillis(onFrame)", "androidx.compose.withFrameMillis")
+)
suspend inline fun <R> CompositionFrameClock.awaitFrameMillis(
crossinline onFrame: (frameTimeMillis: Long) -> R
-): R = awaitFrameNanos { onFrame(it / 1_000_000L) }
-
-private val timeReturner: (Long) -> Long = { it }
+): R = withFrameMillis(onFrame)
/**
* Suspends until a new frame is requested, returning the frame time in nanoseconds.
@@ -69,7 +106,11 @@
* Time values returned are monotonically increasing; after a call to [awaitFrameNanos]
* returns it must not return the same value again for a subsequent call.
*/
-suspend fun CompositionFrameClock.awaitFrameNanos(): Long = awaitFrameNanos(timeReturner)
+@Deprecated(
+ "callers will resume after missing the frame on most dispatchers",
+ ReplaceWith("withFrameNanos { it }")
+)
+suspend fun CompositionFrameClock.awaitFrameNanos(): Long = withFrameNanos { it }
/**
* Suspends until a new frame is requested, returning the frame time in milliseconds.
@@ -81,4 +122,8 @@
* Time values returned are monotonically increasing; after a call to [awaitFrameMillis]
* returns it must not return the same value again for a subsequent call.
*/
-suspend fun CompositionFrameClock.awaitFrameMillis(): Long = awaitFrameNanos() / 1_000_000L
+@Deprecated(
+ "callers will resume after missing the frame on most dispatchers",
+ ReplaceWith("withFrameMillis { it }", "androidx.compose.withFrameMillis")
+)
+suspend fun CompositionFrameClock.awaitFrameMillis(): Long = withFrameMillis { it }
diff --git a/compose/compose-runtime/src/commonMain/kotlin/androidx/compose/Recomposer.kt b/compose/compose-runtime/src/commonMain/kotlin/androidx/compose/Recomposer.kt
index e223101..c77569f 100644
--- a/compose/compose-runtime/src/commonMain/kotlin/androidx/compose/Recomposer.kt
+++ b/compose/compose-runtime/src/commonMain/kotlin/androidx/compose/Recomposer.kt
@@ -169,7 +169,7 @@
// Align work with the next frame to coalesce changes.
// Note: it is possible to resume from the above with no recompositions pending,
// instead someone might be awaiting our frame clock dispatch below.
- frameClock.awaitFrameNanos { frameTime ->
+ frameClock.withFrameNanos { frameTime ->
trace("recomposeFrame") {
// Propagate the frame time to anyone who is awaiting from the
// recomposer clock.
diff --git a/compose/compose-runtime/src/commonMain/kotlin/androidx/compose/SuspendingEffects.kt b/compose/compose-runtime/src/commonMain/kotlin/androidx/compose/SuspendingEffects.kt
index 1113626..24fdd18 100644
--- a/compose/compose-runtime/src/commonMain/kotlin/androidx/compose/SuspendingEffects.kt
+++ b/compose/compose-runtime/src/commonMain/kotlin/androidx/compose/SuspendingEffects.kt
@@ -43,7 +43,7 @@
/**
* A [CoroutineScope] used for launching [side effects][launchInComposition] of a composition
- * that also permits [awaiting][CompositionFrameClock.awaitFrameNanos] the next presentation
+ * that also permits [awaiting][CompositionFrameClock.withFrameNanos] the next presentation
* frame of the composition. This can be useful for performing the next action of an animation
* while the effect is still present in the composition.
*/
@@ -57,7 +57,7 @@
replaceWith = ReplaceWith("awaitFrameNanos()", "androidx.compose.awaitFrameNanos"),
level = DeprecationLevel.ERROR
)
- suspend fun awaitFrame(): Long = awaitFrameNanos()
+ suspend fun awaitFrame(): Long = withFrameNanos { it }
}
/**
diff --git a/compose/compose-runtime/src/desktopMain/kotlin/androidx/compose/ActualDesktop.kt b/compose/compose-runtime/src/desktopMain/kotlin/androidx/compose/ActualDesktop.kt
index d9014919..541b42e 100644
--- a/compose/compose-runtime/src/desktopMain/kotlin/androidx/compose/ActualDesktop.kt
+++ b/compose/compose-runtime/src/desktopMain/kotlin/androidx/compose/ActualDesktop.kt
@@ -128,7 +128,7 @@
actual fun keySourceInfoOf(key: Any): String? = keyInfo[key]
private object MainCompositionFrameClock : CompositionFrameClock {
- override suspend fun <R> awaitFrameNanos(onFrame: (frameTimeNanos: Long) -> R): R =
+ override suspend fun <R> withFrameNanos(onFrame: (frameTimeNanos: Long) -> R): R =
withContext(Dispatchers.Main) {
onFrame(java.lang.System.nanoTime())
}
diff --git a/compose/compose-runtime/src/unitTest/kotlin/androidx/compose/CompositionTests.kt b/compose/compose-runtime/src/unitTest/kotlin/androidx/compose/CompositionTests.kt
index 4c2fffd..3fd352b 100644
--- a/compose/compose-runtime/src/unitTest/kotlin/androidx/compose/CompositionTests.kt
+++ b/compose/compose-runtime/src/unitTest/kotlin/androidx/compose/CompositionTests.kt
@@ -2353,7 +2353,7 @@
val scope = CoroutineScope(Job())
val clock = object : CompositionFrameClock {
- override suspend fun <R> awaitFrameNanos(onFrame: (Long) -> R): R {
+ override suspend fun <R> withFrameNanos(onFrame: (Long) -> R): R {
// The original version of this test used a mock Recomposer
// that never successfully scheduled a frame.
suspendCancellableCoroutine<Unit> {}
diff --git a/ui/ui-core/src/test/java/androidx/ui/core/ComposedModifierTest.kt b/ui/ui-core/src/test/java/androidx/ui/core/ComposedModifierTest.kt
index f7d1fb8..2d3b191 100644
--- a/ui/ui-core/src/test/java/androidx/ui/core/ComposedModifierTest.kt
+++ b/ui/ui-core/src/test/java/androidx/ui/core/ComposedModifierTest.kt
@@ -231,7 +231,7 @@
frameCh.send(frameTimeNanos)
}
- override suspend fun <R> awaitFrameNanos(onFrame: (Long) -> R): R = onFrame(frameCh.receive())
+ override suspend fun <R> withFrameNanos(onFrame: (Long) -> R): R = onFrame(frameCh.receive())
}
@OptIn(ExperimentalComposeApi::class)
diff --git a/ui/ui-test/src/main/java/androidx/ui/test/android/AndroidComposeTestCaseRunner.kt b/ui/ui-test/src/main/java/androidx/ui/test/android/AndroidComposeTestCaseRunner.kt
index 2376186..327f5c6 100644
--- a/ui/ui-test/src/main/java/androidx/ui/test/android/AndroidComposeTestCaseRunner.kt
+++ b/ui/ui-test/src/main/java/androidx/ui/test/android/AndroidComposeTestCaseRunner.kt
@@ -86,7 +86,7 @@
) : CompositionFrameClock {
private val lastFrameTime = AtomicLong(0L)
- override suspend fun <R> awaitFrameNanos(onFrame: (Long) -> R): R =
+ override suspend fun <R> withFrameNanos(onFrame: (Long) -> R): R =
onFrame(lastFrameTime.getAndAdd(singleFrameTimeNanos))
}