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.TransitionBuilder
25 import com.android.compose.animation.scene.UserActionDistance
26 import com.android.compose.animation.scene.UserActionDistanceScope
27 import com.android.systemui.notifications.ui.composable.Notifications
28 import com.android.systemui.qs.ui.composable.QuickSettings
29 import com.android.systemui.shade.ui.composable.Shade
30 import com.android.systemui.shade.ui.composable.ShadeHeader
31 import kotlin.time.Duration.Companion.milliseconds
32 
TransitionBuildernull33 fun TransitionBuilder.toSplitShadeTransition(
34     durationScale: Double = 1.0,
35 ) {
36     spec = tween(durationMillis = (DefaultDuration * durationScale).inWholeMilliseconds.toInt())
37     swipeSpec =
38         spring(
39             stiffness = Spring.StiffnessMediumLow,
40             visibilityThreshold = Shade.Dimensions.ScrimVisibilityThreshold,
41         )
42     distance =
43         object : UserActionDistance {
44             override fun UserActionDistanceScope.absoluteDistance(
45                 fromSceneSize: IntSize,
46                 orientation: Orientation,
47             ): Float {
48                 return fromSceneSize.height.toFloat() * 2 / 3f
49             }
50         }
51 
52     fractionRange(end = .33f) { fade(Shade.Elements.BackgroundScrim) }
53 
54     fractionRange(start = .33f) {
55         fade(ShadeHeader.Elements.Clock)
56         fade(ShadeHeader.Elements.CollapsedContentStart)
57         fade(ShadeHeader.Elements.CollapsedContentEnd)
58         fade(ShadeHeader.Elements.PrivacyChip)
59         fade(QuickSettings.Elements.SplitShadeQuickSettings)
60         fade(QuickSettings.Elements.FooterActions)
61         fade(Notifications.Elements.NotificationScrim)
62     }
63 }
64 
65 private val DefaultDuration = 500.milliseconds
66