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.material.icons.Icons
21 import androidx.compose.material.icons.automirrored.outlined.ArrowBack
22 import androidx.compose.material.icons.outlined.Clear
23 import androidx.compose.material.icons.outlined.FindInPage
24 import androidx.compose.material3.Icon
25 import androidx.compose.material3.IconButton
26 import androidx.compose.runtime.Composable
27 import androidx.compose.ui.res.stringResource
28 import com.android.settingslib.spa.framework.compose.LocalNavController
29
30 /** Action that navigates back to last page. */
31 @Composable
NavigateBacknull32 internal fun NavigateBack() {
33 val navController = LocalNavController.current
34 val contentDescription = stringResource(R.string.abc_action_bar_up_description)
35 BackAction(contentDescription) {
36 navController.navigateBack()
37 }
38 }
39
40 /** Action that collapses the search bar. */
41 @Composable
CollapseActionnull42 internal fun CollapseAction(onClick: () -> Unit) {
43 val contentDescription = stringResource(R.string.abc_toolbar_collapse_description)
44 BackAction(contentDescription, onClick)
45 }
46
47 @Composable
BackActionnull48 private fun BackAction(contentDescription: String, onClick: () -> Unit) {
49 IconButton(onClick) {
50 Icon(
51 imageVector = Icons.AutoMirrored.Outlined.ArrowBack,
52 contentDescription = contentDescription,
53 )
54 }
55 }
56
57 /** Action that expends the search bar. */
58 @Composable
SearchActionnull59 internal fun SearchAction(onClick: () -> Unit) {
60 IconButton(onClick) {
61 Icon(
62 imageVector = Icons.Outlined.FindInPage,
63 contentDescription = stringResource(R.string.search_menu_title),
64 )
65 }
66 }
67
68 /** Action that clear the search query. */
69 @Composable
ClearActionnull70 internal fun ClearAction(onClick: () -> Unit) {
71 IconButton(onClick) {
72 Icon(
73 imageVector = Icons.Outlined.Clear,
74 contentDescription = stringResource(R.string.abc_searchview_description_clear),
75 )
76 }
77 }
78