NavigateUpButton as a reusable component

This commit is contained in:
Sad Ellie 2022-07-22 22:40:49 +03:00
parent c43d6bb4c5
commit 685a3dfc56
3 changed files with 45 additions and 16 deletions

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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)
)
}
}

View File

@ -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
)

View File

@ -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
)