Skip to content

Commit

Permalink
Added animations for icon size in Bottom Navigation Bar
Browse files Browse the repository at this point in the history
  • Loading branch information
aritra-tech committed Nov 10, 2024
1 parent 40f5a6e commit 2db8471
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions app/src/main/java/com/aritradas/uncrack/navigation/Navigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.app.Activity
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
Expand All @@ -13,7 +14,9 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.font.FontWeight
Expand Down Expand Up @@ -279,13 +282,20 @@ fun ShowBottomNavigation(
)

bottomNavItems.forEach { item ->
val isSelected = backStackEntry.value?.destination?.route == item.route
val animateIconSize by animateFloatAsState(
if (isSelected) 1f else 0.9f,
label = "iconScale"
)

NavigationBarItem(
alwaysShowLabel = true,
icon = {
Icon(
modifier = Modifier.scale(animateIconSize),
imageVector = item.icon,
contentDescription = item.name,
tint = if (backStackEntry.value?.destination?.route == item.route)
tint = if (isSelected)
OnPrimaryContainerLight
else
OnSurfaceVariantLight
Expand All @@ -295,17 +305,17 @@ fun ShowBottomNavigation(
Text(
text = item.name,
fontFamily = DMSansFontFamily,
color = if (backStackEntry.value?.destination?.route == item.route)
color = if (isSelected)
OnPrimaryContainerLight
else
OnSurfaceVariantLight,
fontWeight = if (backStackEntry.value?.destination?.route == item.route)
fontWeight = if (isSelected)
FontWeight.SemiBold
else
FontWeight.Normal,
)
},
selected = backStackEntry.value?.destination?.route == item.route,
selected = isSelected,
onClick = {
val currentDestination =
navController.currentBackStackEntry?.destination?.route
Expand Down

0 comments on commit 2db8471

Please sign in to comment.