diff --git a/app/src/main/java/com/sadellie/unitto/screens/common/NavigateUpButton.kt b/app/src/main/java/com/sadellie/unitto/screens/common/NavigateUpButton.kt new file mode 100644 index 00000000..52b6210d --- /dev/null +++ b/app/src/main/java/com/sadellie/unitto/screens/common/NavigateUpButton.kt @@ -0,0 +1,42 @@ +/* + * Unitto is a unit converter for Android + * Copyright (c) 2022 Elshan Agaev + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.sadellie.unitto.screens.common + +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.ArrowBack +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.runtime.Composable +import androidx.compose.ui.res.stringResource +import com.sadellie.unitto.R + +/** + * Button that is used in Top bars + * + * @param onClick Action to be called when button is clicked. + */ +@Composable +fun NavigateUpButton(onClick: () -> Unit) { + IconButton(onClick = onClick) { + Icon( + Icons.Outlined.ArrowBack, + contentDescription = stringResource(id = R.string.navigate_up_description) + ) + } +} diff --git a/app/src/main/java/com/sadellie/unitto/screens/common/UnittoLargeTopAppBar.kt b/app/src/main/java/com/sadellie/unitto/screens/common/UnittoLargeTopAppBar.kt index c42a1574..87180d50 100644 --- a/app/src/main/java/com/sadellie/unitto/screens/common/UnittoLargeTopAppBar.kt +++ b/app/src/main/java/com/sadellie/unitto/screens/common/UnittoLargeTopAppBar.kt @@ -20,10 +20,6 @@ package com.sadellie.unitto.screens.common import androidx.compose.animation.rememberSplineBasedDecay import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.outlined.ArrowBack -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton import androidx.compose.material3.LargeTopAppBar import androidx.compose.material3.Scaffold import androidx.compose.material3.Text @@ -32,8 +28,6 @@ import androidx.compose.material3.rememberTopAppBarScrollState import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.input.nestedscroll.nestedScroll -import androidx.compose.ui.res.stringResource -import com.sadellie.unitto.R /** * Commonly used LargeTopAppBar with scroll behavior. @@ -61,9 +55,7 @@ fun UnittoLargeTopAppBar( Text(text = title) }, navigationIcon = { - IconButton(onClick = navigateUpAction) { - Icon(Icons.Outlined.ArrowBack, stringResource(R.string.navigate_up_description)) - } + NavigateUpButton { navigateUpAction() } }, scrollBehavior = scrollBehavior ) diff --git a/app/src/main/java/com/sadellie/unitto/screens/second/components/SearchBar.kt b/app/src/main/java/com/sadellie/unitto/screens/second/components/SearchBar.kt index 1e7bfb7a..61415436 100644 --- a/app/src/main/java/com/sadellie/unitto/screens/second/components/SearchBar.kt +++ b/app/src/main/java/com/sadellie/unitto/screens/second/components/SearchBar.kt @@ -38,7 +38,6 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Favorite import androidx.compose.material.icons.filled.FavoriteBorder import androidx.compose.material.icons.filled.Search -import androidx.compose.material.icons.outlined.ArrowBack import androidx.compose.material.icons.outlined.Clear import androidx.compose.material3.Icon import androidx.compose.material3.IconButton @@ -63,6 +62,7 @@ import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.ImeAction import com.sadellie.unitto.R +import com.sadellie.unitto.screens.common.NavigateUpButton /** * Search bar on the Second screen. Controls what will be shown in the list above this component @@ -170,12 +170,7 @@ fun SearchBar( } }, navigationIcon = { - IconButton(onClick = { stagedNavigateUp() }) { - Icon( - Icons.Outlined.ArrowBack, - contentDescription = stringResource(id = R.string.navigate_up_description) - ) - } + NavigateUpButton { stagedNavigateUp() } }, scrollBehavior = scrollBehavior )