mirror of
https://github.com/bitwarden/android.git
synced 2026-06-07 23:58:03 -05:00
BIT-40: Reskin bottom navigation bar (#81)
This commit is contained in:
committed by
Álison Fernandes
parent
5c81560514
commit
60b004eb30
@@ -4,7 +4,9 @@ import android.os.Parcelable
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.BottomAppBar
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.NavigationBarItem
|
||||
import androidx.compose.material3.NavigationBarItemDefaults
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -82,6 +84,7 @@ fun VaultUnlockedNavBarScreen(
|
||||
* Scaffold that contains the bottom nav bar for the [VaultUnlockedNavBarScreen]
|
||||
*/
|
||||
@Composable
|
||||
@Suppress("LongMethod")
|
||||
private fun VaultUnlockedNavBarScaffold(
|
||||
navController: NavHostController,
|
||||
vaultTabClickedAction: () -> Unit,
|
||||
@@ -91,7 +94,9 @@ private fun VaultUnlockedNavBarScaffold(
|
||||
) {
|
||||
Scaffold(
|
||||
bottomBar = {
|
||||
BottomAppBar {
|
||||
BottomAppBar(
|
||||
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||
) {
|
||||
val destinations = listOf(
|
||||
VaultUnlockedNavBarTab.Vault,
|
||||
VaultUnlockedNavBarTab.Send,
|
||||
@@ -101,21 +106,35 @@ private fun VaultUnlockedNavBarScaffold(
|
||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||
val currentDestination = navBackStackEntry?.destination
|
||||
destinations.forEach { destination ->
|
||||
|
||||
val isSelected = currentDestination?.hierarchy?.any {
|
||||
it.route == destination.route
|
||||
} == true
|
||||
|
||||
NavigationBarItem(
|
||||
icon = {
|
||||
Icon(
|
||||
painter = painterResource(id = destination.iconRes),
|
||||
painter = painterResource(
|
||||
id = if (isSelected) {
|
||||
destination.iconResSelected
|
||||
} else {
|
||||
destination.iconRes
|
||||
},
|
||||
),
|
||||
contentDescription = stringResource(
|
||||
id = destination.contentDescriptionRes,
|
||||
),
|
||||
tint = if (isSelected) {
|
||||
MaterialTheme.colorScheme.onSecondaryContainer
|
||||
} else {
|
||||
MaterialTheme.colorScheme.onSurface
|
||||
},
|
||||
)
|
||||
},
|
||||
label = {
|
||||
Text(text = stringResource(id = destination.labelRes))
|
||||
},
|
||||
selected = currentDestination?.hierarchy?.any {
|
||||
it.route == destination.route
|
||||
} == true,
|
||||
selected = isSelected,
|
||||
onClick = {
|
||||
when (destination) {
|
||||
VaultUnlockedNavBarTab.Vault -> vaultTabClickedAction()
|
||||
@@ -124,6 +143,9 @@ private fun VaultUnlockedNavBarScaffold(
|
||||
VaultUnlockedNavBarTab.Settings -> settingsTabClickedAction()
|
||||
}
|
||||
},
|
||||
colors = NavigationBarItemDefaults.colors(
|
||||
indicatorColor = MaterialTheme.colorScheme.secondaryContainer,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -143,10 +165,24 @@ private fun VaultUnlockedNavBarScaffold(
|
||||
}
|
||||
|
||||
/**
|
||||
* Models tabs for the nav bar of the vault unlocked portion of the app.
|
||||
* Represents the different tabs available in the navigation bar
|
||||
* for the unlocked portion of the vault.
|
||||
*
|
||||
* Each tab is modeled with properties that provide information on:
|
||||
* - Regular icon resource
|
||||
* - Icon resource when selected
|
||||
* and other essential UI and navigational data.
|
||||
*
|
||||
* @property iconRes The resource ID for the regular (unselected) icon representing the tab.
|
||||
* @property iconResSelected The resource ID for the icon representing the tab when it's selected.
|
||||
*/
|
||||
@Parcelize
|
||||
private sealed class VaultUnlockedNavBarTab : Parcelable {
|
||||
/**
|
||||
* The resource ID for the icon representing the tab when it is selected.
|
||||
*/
|
||||
abstract val iconResSelected: Int
|
||||
|
||||
/**
|
||||
* Resource id for the icon representing the tab.
|
||||
*/
|
||||
@@ -172,7 +208,8 @@ private sealed class VaultUnlockedNavBarTab : Parcelable {
|
||||
*/
|
||||
@Parcelize
|
||||
data object Generator : VaultUnlockedNavBarTab() {
|
||||
override val iconRes get() = R.drawable.generator_icon
|
||||
override val iconResSelected get() = R.drawable.ic_generator_filled
|
||||
override val iconRes get() = R.drawable.ic_generator
|
||||
override val labelRes get() = R.string.generator
|
||||
override val contentDescriptionRes get() = R.string.generator
|
||||
override val route get() = GENERATOR_ROUTE
|
||||
@@ -183,7 +220,8 @@ private sealed class VaultUnlockedNavBarTab : Parcelable {
|
||||
*/
|
||||
@Parcelize
|
||||
data object Send : VaultUnlockedNavBarTab() {
|
||||
override val iconRes get() = R.drawable.send_icon
|
||||
override val iconResSelected get() = R.drawable.ic_send_filled
|
||||
override val iconRes get() = R.drawable.ic_send
|
||||
override val labelRes get() = R.string.send
|
||||
override val contentDescriptionRes get() = R.string.send
|
||||
override val route get() = SEND_ROUTE
|
||||
@@ -194,7 +232,8 @@ private sealed class VaultUnlockedNavBarTab : Parcelable {
|
||||
*/
|
||||
@Parcelize
|
||||
data object Vault : VaultUnlockedNavBarTab() {
|
||||
override val iconRes get() = R.drawable.sheild_icon
|
||||
override val iconResSelected get() = R.drawable.ic_vault_filled
|
||||
override val iconRes get() = R.drawable.ic_vault
|
||||
override val labelRes get() = R.string.my_vault
|
||||
override val contentDescriptionRes get() = R.string.my_vault
|
||||
override val route get() = VAULT_ROUTE
|
||||
@@ -205,7 +244,8 @@ private sealed class VaultUnlockedNavBarTab : Parcelable {
|
||||
*/
|
||||
@Parcelize
|
||||
data object Settings : VaultUnlockedNavBarTab() {
|
||||
override val iconRes get() = R.drawable.settings_icon
|
||||
override val iconResSelected get() = R.drawable.ic_settings_filled
|
||||
override val iconRes get() = R.drawable.ic_settings
|
||||
override val labelRes get() = R.string.settings
|
||||
override val contentDescriptionRes get() = R.string.settings
|
||||
override val route get() = SETTINGS_ROUTE
|
||||
|
||||
Reference in New Issue
Block a user