android: Render filled icon for selected bottom nav icon (#326)

Signed-off-by: Rahul Krishna <Rahulkrishna585@gmail.com>
This commit is contained in:
Rahul Krishna 2022-07-03 01:20:15 +05:30 committed by GitHub
parent 493e6c23c1
commit 4a048e8ff0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 3 deletions

View file

@ -87,6 +87,7 @@ fun LobstersApp(
label = "Hottest",
route = Destinations.Hottest.getRoute(),
icon = ClawIcons.Flame,
selectedIcon = ClawIcons.FlameFilled,
) {
coroutineScope.launch { hottestListState.animateScrollToItem(index = 0) }
},
@ -94,6 +95,7 @@ fun LobstersApp(
label = "Newest",
route = Destinations.Newest.getRoute(),
icon = ClawIcons.New,
selectedIcon = ClawIcons.NewFilled,
) {
coroutineScope.launch { newestListState.animateScrollToItem(index = 0) }
},
@ -101,6 +103,7 @@ fun LobstersApp(
label = "Saved",
route = Destinations.Saved.getRoute(),
icon = ClawIcons.HeartBorder,
selectedIcon = ClawIcons.Heart,
) {
coroutineScope.launch { savedListState.animateScrollToItem(index = 0) }
},

View file

@ -1,6 +1,7 @@
package dev.msfjarvis.claw.android.ui.decorations
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.Crossfade
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
@ -28,12 +29,20 @@ fun ClawNavigationBar(
) {
NavigationBar(modifier = modifier) {
items.forEach { navItem ->
val isCurrentDestination = navController.currentDestination?.route == navItem.route
NavigationBarItem(
icon = { Icon(painter = navItem.icon, contentDescription = navItem.label.uppercase()) },
icon = {
Crossfade(isCurrentDestination) {
Icon(
painter = if (it) navItem.selectedIcon else navItem.icon,
contentDescription = navItem.label.uppercase()
)
}
},
label = { Text(text = navItem.label) },
selected = navController.currentDestination?.route == navItem.route,
selected = isCurrentDestination,
onClick = {
if (navController.currentDestination?.route == navItem.route) {
if (isCurrentDestination) {
navItem.listStateResetCallback()
return@NavigationBarItem
}
@ -52,5 +61,6 @@ class NavigationItem(
val label: String,
val route: String,
val icon: Painter,
val selectedIcon: Painter,
val listStateResetCallback: () -> Unit,
)