1 /*
2 * Copyright (C) 2024 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.systemui.scene.ui.composable.transitions
18
19 import androidx.compose.animation.core.Spring
20 import androidx.compose.animation.core.spring
21 import androidx.compose.animation.core.tween
22 import androidx.compose.foundation.gestures.Orientation
23 import androidx.compose.ui.unit.IntSize
24 import com.android.compose.animation.scene.Edge
25 import com.android.compose.animation.scene.TransitionBuilder
26 import com.android.compose.animation.scene.UserActionDistance
27 import com.android.compose.animation.scene.UserActionDistanceScope
28 import com.android.systemui.shade.ui.composable.OverlayShade
29 import com.android.systemui.shade.ui.composable.Shade
30 import kotlin.time.Duration.Companion.milliseconds
31
TransitionBuildernull32 fun TransitionBuilder.toQuickSettingsShadeTransition(
33 durationScale: Double = 1.0,
34 ) {
35 spec = tween(durationMillis = (DefaultDuration * durationScale).inWholeMilliseconds.toInt())
36 swipeSpec =
37 spring(
38 stiffness = Spring.StiffnessMediumLow,
39 visibilityThreshold = Shade.Dimensions.ScrimVisibilityThreshold,
40 )
41 distance =
42 object : UserActionDistance {
43 override fun UserActionDistanceScope.absoluteDistance(
44 fromSceneSize: IntSize,
45 orientation: Orientation,
46 ): Float {
47 return fromSceneSize.height.toFloat() * 2 / 3f
48 }
49 }
50
51 translate(OverlayShade.Elements.Panel, Edge.Top)
52
53 fractionRange(end = .5f) { fade(OverlayShade.Elements.Scrim) }
54 }
55
56 private val DefaultDuration = 300.milliseconds
57