1 /*
2 * Copyright (C) 2022 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.credentialmanager.common.ui
18
19 import android.credentials.flags.Flags
20 import androidx.compose.foundation.layout.Arrangement
21 import androidx.compose.foundation.layout.ColumnScope
22 import androidx.compose.foundation.layout.WindowInsets
23 import androidx.compose.foundation.layout.fillMaxWidth
24 import androidx.compose.foundation.layout.asPaddingValues
25 import androidx.compose.foundation.layout.navigationBars
26 import androidx.compose.foundation.layout.padding
27 import androidx.compose.foundation.layout.wrapContentHeight
28 import androidx.compose.foundation.lazy.LazyColumn
29 import androidx.compose.foundation.lazy.LazyListScope
30 import androidx.compose.material3.Card
31 import androidx.compose.material3.CardDefaults
32 import androidx.compose.runtime.Composable
33 import androidx.compose.ui.Alignment
34 import androidx.compose.ui.Modifier
35 import androidx.compose.ui.graphics.Color
36 import androidx.compose.ui.unit.dp
37 import com.android.compose.theme.LocalAndroidColorScheme
38 import com.android.credentialmanager.ui.theme.Shapes
39
40 /**
41 * Container card for the whole sheet.
42 *
43 * Surface 1 color. No vertical padding. 24dp horizontal padding. 24dp bottom padding. 24dp top
44 * padding if [topAppBar] is not present, and none otherwise.
45 */
46 @Composable
SheetContainerCardnull47 fun SheetContainerCard(
48 topAppBar: (@Composable () -> Unit)? = null,
49 modifier: Modifier = Modifier,
50 contentVerticalArrangement: Arrangement.Vertical = Arrangement.Top,
51 content: LazyListScope.() -> Unit,
52 ) {
53 Card(
54 modifier = modifier.fillMaxWidth().wrapContentHeight(),
55 border = null,
56 colors = CardDefaults.cardColors(
57 containerColor = LocalAndroidColorScheme.current.surfaceBright,
58 ),
59 ) {
60 if (topAppBar != null) {
61 topAppBar()
62 }
63 LazyColumn(
64 modifier = Modifier.padding(
65 start = 24.dp,
66 end = 24.dp,
67 bottom = if (Flags.selectorUiImprovementsEnabled()) 8.dp else 18.dp,
68 top = if (topAppBar == null) 24.dp else 0.dp
69 ).fillMaxWidth().wrapContentHeight(),
70 horizontalAlignment = Alignment.CenterHorizontally,
71 content = content,
72 verticalArrangement = contentVerticalArrangement,
73 // The bottom sheet overlaps with the navigation bars but make sure the actual content
74 // in the bottom sheet does not.
75 contentPadding = WindowInsets.navigationBars.asPaddingValues(),
76 )
77 }
78 }
79
80 /**
81 * Container card for the entries.
82 *
83 * Surface 3 color. No padding. Four rounded corner shape.
84 */
85 @Composable
CredentialContainerCardnull86 fun CredentialContainerCard(
87 modifier: Modifier = Modifier,
88 content: @Composable ColumnScope.() -> Unit,
89 ) {
90 Card(
91 modifier = modifier.fillMaxWidth().wrapContentHeight(),
92 shape = Shapes.medium,
93 border = null,
94 colors = CardDefaults.cardColors(
95 containerColor = Color.Transparent,
96 ),
97 content = content,
98 )
99 }