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.compose.animation.scene.demo
18
19 import androidx.compose.foundation.layout.Box
20 import androidx.compose.foundation.layout.Column
21 import androidx.compose.foundation.layout.padding
22 import androidx.compose.runtime.Composable
23 import androidx.compose.ui.Modifier
24 import androidx.compose.ui.unit.dp
25 import com.android.compose.animation.scene.Back
26 import com.android.compose.animation.scene.ContentScope
27 import com.android.compose.animation.scene.ElementKey
28 import com.android.compose.animation.scene.Swipe
29 import com.android.compose.animation.scene.UserActionResult
30 import com.android.compose.animation.scene.UserActionResult.ShowOverlay
31 import com.android.compose.animation.scene.UserActionResult.ShowOverlay.HideCurrentOverlays
32
33 object NotificationShade {
34 object Elements {
35 val Root = ElementKey("NotificationShadeRoot")
36 val Content = ElementKey("NotificationShadeContent")
37 }
38
39 val UserActions =
40 mapOf(
41 Back to UserActionResult.HideOverlay(Overlays.Notifications),
42 Swipe.Up to UserActionResult.HideOverlay(Overlays.Notifications),
43 Swipe.Down(fromSource = SceneContainerArea.EndHalf) to
44 ShowOverlay(
45 Overlays.QuickSettings,
46 hideCurrentOverlays = HideCurrentOverlays.Some(Overlays.Notifications),
47 ),
48 )
49 }
50
51 @Composable
NotificationShadenull52 fun ContentScope.NotificationShade(
53 clock: (@Composable ContentScope.() -> Unit)?,
54 mediaPlayer: (@Composable ContentScope.() -> Unit)?,
55 notificationList: @Composable ContentScope.() -> Unit,
56 modifier: Modifier = Modifier,
57 ) {
58 PartialShade(NotificationShade.Elements.Root, modifier) {
59 Column(Modifier.element(NotificationShade.Elements.Content)) {
60 if (clock != null || mediaPlayer != null) {
61 Column(Modifier.padding(horizontal = 16.dp).padding(top = 16.dp)) {
62 clock?.let { it() }
63 mediaPlayer?.let { it() }
64 }
65 }
66
67 // Don't resize the notifications during the reveal.
68 Box(Modifier.noResizeDuringTransitions()) { notificationList() }
69 }
70 }
71 }
72