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