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 /** Scene 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 val SceneE = SceneKey("SceneE")
31 }
32
33 /** Overlay keys that can be reused by tests. */
34 object TestOverlays {
35 val OverlayA = OverlayKey("OverlayA")
36 val OverlayB = OverlayKey("OverlayB")
37 val OverlayC = OverlayKey("OverlayC")
38 val OverlayD = OverlayKey("OverlayD")
39 }
40
41 /** Element keys that can be reused by tests. */
42 object TestElements {
43 val Foo = ElementKey("Foo")
44 val Bar = ElementKey("Bar")
45 val LowZIndex = ElementKey("LowZIndex", contentPicker = LowestZIndexContentPicker)
46 }
47
48 /** Value keys that can be reused by tests. */
49 object TestValues {
50 val Value1 = ValueKey("Value1")
51 val Value2 = ValueKey("Value2")
52 val Value3 = ValueKey("Value3")
53 val Value4 = ValueKey("Value4")
54 }
55
56 // We use a transition duration of 480ms here because it is a multiple of 16, the time of a frame in
57 // C JVM/Android. Doing so allows us for instance to test the state at progress = 0.5f given that t
58 // = 240ms is also a multiple of 16.
59 val TestTransitionDuration = 480L
60
61 /** A definition of empty transitions between [TestScenes], using different animation specs. */
<lambda>null62 val EmptyTestTransitions = transitions {
63 from(TestScenes.SceneA, to = TestScenes.SceneB) {
64 spec = tween(durationMillis = TestTransitionDuration.toInt(), easing = LinearEasing)
65 }
66
67 from(TestScenes.SceneB, to = TestScenes.SceneC) {
68 spec = tween(durationMillis = TestTransitionDuration.toInt(), easing = FastOutSlowInEasing)
69 }
70
71 from(TestScenes.SceneC, to = TestScenes.SceneA) { spec = snap() }
72
73 from(TestScenes.SceneC, to = TestScenes.SceneD) { spec = snap() }
74 }
75