1 /* 2 * Copyright 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.compose.ui 18 19 import androidx.compose.runtime.Stable 20 import kotlin.coroutines.CoroutineContext 21 22 /** 23 * Provides a duration scale for motion such as animations. When the duration [scaleFactor] is 0, 24 * the motion will end in the next frame callback. Otherwise, the duration [scaleFactor] will be 25 * used as a multiplier to scale the duration of the motion. The larger the scale, the longer the 26 * motion will take to finish, and therefore the slower it will be perceived. 27 * 28 * ## Testing 29 * 30 * To control the motion duration scale in tests, create an implementation of this interface and 31 * pass it to the `effectContext` parameter either where you call `runComposeUiTest` or where you 32 * create your test rule. 33 */ 34 @Stable 35 interface MotionDurationScale : CoroutineContext.Element { 36 /** 37 * Defines the multiplier for the duration of the motion. This value should be non-negative. 38 * 39 * A [scaleFactor] of 1.0f would play the motion in real time. 0f would cause motion to finish 40 * in the next frame callback. Larger [scaleFactor] will result in longer durations for the 41 * motion/animation (i.e. slower animation). For example, a [scaleFactor] of 10f would cause an 42 * animation with a duration of 100ms to finish in 1000ms. 43 */ 44 val scaleFactor: Float 45 46 override val key: CoroutineContext.Key<*> 47 get() = Key 48 49 companion object Key : CoroutineContext.Key<MotionDurationScale> 50 } 51