xref: /aosp_15_r20/frameworks/base/packages/SystemUI/compose/core/src/com/android/compose/animation/Easings.kt (revision d57664e9bc4670b3ecf6748a746a57c557b6bc9e)
1 /*
<lambda>null2  * 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
18 
19 import androidx.compose.animation.core.CubicBezierEasing
20 import androidx.compose.animation.core.Easing
21 import androidx.core.animation.Interpolator
22 import com.android.app.animation.InterpolatorsAndroidX
23 
24 /**
25  * Compose-compatible definition of Android motion eases, see
26  * https://carbon.googleplex.com/android-motion/pages/easing
27  */
28 object Easings {
29 
30     /** The standard interpolator that should be used on every normal animation */
31     val Standard = fromInterpolator(InterpolatorsAndroidX.STANDARD)
32 
33     /**
34      * The standard accelerating interpolator that should be used on every regular movement of
35      * content that is disappearing e.g. when moving off screen.
36      */
37     val StandardAccelerate = fromInterpolator(InterpolatorsAndroidX.STANDARD_ACCELERATE)
38 
39     /**
40      * The standard decelerating interpolator that should be used on every regular movement of
41      * content that is appearing e.g. when coming from off screen.
42      */
43     val StandardDecelerate = fromInterpolator(InterpolatorsAndroidX.STANDARD_DECELERATE)
44 
45     /** The default emphasized interpolator. Used for hero / emphasized movement of content. */
46     val Emphasized = fromInterpolator(InterpolatorsAndroidX.EMPHASIZED)
47 
48     /**
49      * The accelerated emphasized interpolator. Used for hero / emphasized movement of content that
50      * is disappearing e.g. when moving off screen.
51      */
52     val EmphasizedAccelerate = fromInterpolator(InterpolatorsAndroidX.EMPHASIZED_ACCELERATE)
53 
54     /**
55      * The decelerating emphasized interpolator. Used for hero / emphasized movement of content that
56      * is appearing e.g. when coming from off screen
57      */
58     val EmphasizedDecelerate = fromInterpolator(InterpolatorsAndroidX.EMPHASIZED_DECELERATE)
59 
60     /** The linear interpolator. */
61     val Linear = fromInterpolator(InterpolatorsAndroidX.LINEAR)
62 
63     /**
64      * Use this easing for animating progress values coming from the back callback to get the
65      * predictive-back-typical decelerate motion.
66      *
67      * This easing is similar to [StandardDecelerate] but has a slight acceleration phase at the
68      * start.
69      *
70      * See also [InterpolatorsAndroidX.BACK_GESTURE].
71      */
72     val PredictiveBack = CubicBezierEasing(0.1f, 0.1f, 0f, 1f)
73 
74     /** The default legacy interpolator as defined in Material 1. Also known as FAST_OUT_SLOW_IN. */
75     val Legacy = fromInterpolator(InterpolatorsAndroidX.LEGACY)
76 
77     /**
78      * The default legacy accelerating interpolator as defined in Material 1. Also known as
79      * FAST_OUT_LINEAR_IN.
80      */
81     val LegacyAccelerate = fromInterpolator(InterpolatorsAndroidX.LEGACY_ACCELERATE)
82 
83     /**
84      * T The default legacy decelerating interpolator as defined in Material 1. Also known as
85      * LINEAR_OUT_SLOW_IN.
86      */
87     val LegacyDecelerate = fromInterpolator(InterpolatorsAndroidX.LEGACY_DECELERATE)
88 
89     private fun fromInterpolator(source: Interpolator) = Easing { x -> source.getInterpolation(x) }
90 }
91