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.shade.ui.composable.OverlayShade
30 import com.android.systemui.shade.ui.composable.Shade
31 import com.android.systemui.shade.ui.composable.ShadeHeader
32 import kotlin.time.Duration.Companion.milliseconds
33
TransitionBuildernull34 fun TransitionBuilder.toNotificationsShadeTransition(
35 durationScale: Double = 1.0,
36 ) {
37 spec = tween(durationMillis = (DefaultDuration * durationScale).inWholeMilliseconds.toInt())
38 swipeSpec =
39 spring(
40 stiffness = Spring.StiffnessMediumLow,
41 visibilityThreshold = Shade.Dimensions.ScrimVisibilityThreshold,
42 )
43 distance =
44 object : UserActionDistance {
45 override fun UserActionDistanceScope.absoluteDistance(
46 fromSceneSize: IntSize,
47 orientation: Orientation,
48 ): Float {
49 return fromSceneSize.height.toFloat() * 2 / 3f
50 }
51 }
52
53 translate(OverlayShade.Elements.Panel, Edge.Top)
54
55 fractionRange(end = .5f) { fade(OverlayShade.Elements.Scrim) }
56
57 fractionRange(start = .5f) {
58 fade(ShadeHeader.Elements.Clock)
59 fade(ShadeHeader.Elements.ExpandedContent)
60 fade(ShadeHeader.Elements.PrivacyChip)
61 fade(Notifications.Elements.NotificationScrim)
62 }
63 }
64
65 private val DefaultDuration = 300.milliseconds
66