• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.settingslib.spa.widget.scaffold
18 
19 import androidx.appcompat.R
20 import androidx.compose.foundation.background
21 import androidx.compose.foundation.layout.padding
22 import androidx.compose.foundation.layout.size
23 import androidx.compose.material.icons.Icons
24 import androidx.compose.material.icons.automirrored.outlined.ArrowBack
25 import androidx.compose.material.icons.outlined.Clear
26 import androidx.compose.material.icons.outlined.FindInPage
27 import androidx.compose.material3.Icon
28 import androidx.compose.material3.IconButton
29 import androidx.compose.material3.MaterialTheme
30 import androidx.compose.runtime.Composable
31 import androidx.compose.ui.Modifier
32 import androidx.compose.ui.draw.clip
33 import androidx.compose.ui.res.stringResource
34 import com.android.settingslib.spa.framework.compose.LocalNavController
35 import com.android.settingslib.spa.framework.theme.SettingsDimension
36 import com.android.settingslib.spa.framework.theme.SettingsShape
37 import com.android.settingslib.spa.framework.theme.isSpaExpressiveEnabled
38 
39 /** Action that navigates back to last page. */
40 @Composable
NavigateBacknull41 internal fun NavigateBack() {
42     val navController = LocalNavController.current
43     val contentDescription = stringResource(R.string.abc_action_bar_up_description)
44     BackAction(contentDescription) { navController.navigateBack() }
45 }
46 
47 /** Action that collapses the search bar. */
48 @Composable
CollapseActionnull49 internal fun CollapseAction(onClick: () -> Unit) {
50     val contentDescription = stringResource(R.string.abc_toolbar_collapse_description)
51     BackAction(contentDescription, onClick)
52 }
53 
54 @Composable
BackActionnull55 private fun BackAction(contentDescription: String, onClick: () -> Unit) {
56     IconButton(
57         onClick = onClick,
58         modifier =
59             if (isSpaExpressiveEnabled)
60                 Modifier.padding(
61                         start = SettingsDimension.paddingExtraSmall5,
62                         end = SettingsDimension.paddingSmall,
63                         top = SettingsDimension.paddingExtraSmall,
64                         bottom = SettingsDimension.paddingExtraSmall,
65                     )
66                     .size(SettingsDimension.actionIconSize)
67                     .clip(SettingsShape.CornerExtraLarge)
68             else Modifier,
69     ) {
70         Icon(
71             imageVector = Icons.AutoMirrored.Outlined.ArrowBack,
72             contentDescription = contentDescription,
73             modifier =
74                 if (isSpaExpressiveEnabled)
75                     Modifier.size(SettingsDimension.actionIconSize)
76                         .clip(SettingsShape.CornerExtraLarge)
77                         .background(MaterialTheme.colorScheme.surfaceContainerHighest)
78                         .padding(SettingsDimension.actionIconPadding)
79                 else Modifier,
80         )
81     }
82 }
83 
84 /** Action that expends the search bar. */
85 @Composable
SearchActionnull86 internal fun SearchAction(onClick: () -> Unit) {
87     IconButton(onClick) {
88         Icon(
89             imageVector = Icons.Outlined.FindInPage,
90             contentDescription = stringResource(R.string.search_menu_title),
91         )
92     }
93 }
94 
95 /** Action that clear the search query. */
96 @Composable
ClearActionnull97 internal fun ClearAction(onClick: () -> Unit) {
98     IconButton(onClick) {
99         Icon(
100             imageVector = Icons.Outlined.Clear,
101             contentDescription = stringResource(R.string.abc_searchview_description_clear),
102         )
103     }
104 }
105