1 /*
2 * Copyright (C) 2023 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 com.android.compose.animation.scene
18
19 import androidx.compose.animation.core.FastOutSlowInEasing
20 import androidx.compose.animation.core.LinearEasing
21 import androidx.compose.animation.core.snap
22 import androidx.compose.animation.core.tween
23
24 /** Scenes keys that can be reused by tests. */
25 object TestScenes {
26 val SceneA = SceneKey("SceneA")
27 val SceneB = SceneKey("SceneB")
28 val SceneC = SceneKey("SceneC")
29 val SceneD = SceneKey("SceneD")
30 }
31
32 /** Element keys that can be reused by tests. */
33 object TestElements {
34 val Foo = ElementKey("Foo")
35 val Bar = ElementKey("Bar")
36 }
37
38 /** Value keys that can be reused by tests. */
39 object TestValues {
40 val Value1 = ValueKey("Value1")
41 val Value2 = ValueKey("Value2")
42 val Value3 = ValueKey("Value3")
43 val Value4 = ValueKey("Value4")
44 }
45
46 // We use a transition duration of 480ms here because it is a multiple of 16, the time of a frame in
47 // C JVM/Android. Doing so allows us for instance to test the state at progress = 0.5f given that t
48 // = 240ms is also a multiple of 16.
49 val TestTransitionDuration = 480L
50
51 /** A definition of empty transitions between [TestScenes], using different animation specs. */
<lambda>null52 val EmptyTestTransitions = transitions {
53 from(TestScenes.SceneA, to = TestScenes.SceneB) {
54 spec = tween(durationMillis = TestTransitionDuration.toInt(), easing = LinearEasing)
55 }
56
57 from(TestScenes.SceneB, to = TestScenes.SceneC) {
58 spec = tween(durationMillis = TestTransitionDuration.toInt(), easing = FastOutSlowInEasing)
59 }
60
61 from(TestScenes.SceneC, to = TestScenes.SceneA) { spec = snap() }
62 }
63