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.notifications.ui.composable.Notifications
29 import com.android.systemui.qs.ui.composable.QuickSettings
30 import com.android.systemui.scene.shared.model.Scenes
31 import com.android.systemui.shade.ui.composable.Shade
32 import com.android.systemui.shade.ui.composable.ShadeHeader
33 import kotlin.time.Duration.Companion.milliseconds
34
toShadeTransitionnull35 fun TransitionBuilder.toShadeTransition(
36 durationScale: Double = 1.0,
37 ) {
38 spec = tween(durationMillis = (DefaultDuration * durationScale).inWholeMilliseconds.toInt())
39 swipeSpec =
40 spring(
41 stiffness = Spring.StiffnessMediumLow,
42 visibilityThreshold = Shade.Dimensions.ScrimVisibilityThreshold,
43 )
44 distance =
45 object : UserActionDistance {
46 override fun UserActionDistanceScope.absoluteDistance(
47 fromSceneSize: IntSize,
48 orientation: Orientation,
49 ): Float {
50 return Notifications.Elements.NotificationScrim.targetOffset(Scenes.Shade)?.y ?: 0f
51 }
52 }
53
54 fractionRange(start = .58f) {
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 }
62 translate(
63 QuickSettings.Elements.QuickQuickSettings,
64 y = -ShadeHeader.Dimensions.CollapsedHeight * .66f
65 )
66 translate(Notifications.Elements.NotificationScrim, Edge.Top, false)
67 }
68
69 private val DefaultDuration = 500.milliseconds
70