|
| 1 | +package com.hackeros.app.ui.components |
| 2 | + |
| 3 | +import androidx.compose.animation.animateColorAsState |
| 4 | +import androidx.compose.animation.core.Spring |
| 5 | +import androidx.compose.animation.core.spring |
| 6 | +import androidx.compose.foundation.background |
| 7 | +import androidx.compose.foundation.clickable |
| 8 | +import androidx.compose.foundation.interaction.MutableInteractionSource |
| 9 | +import androidx.compose.foundation.layout.* |
| 10 | +import androidx.compose.foundation.shape.CircleShape |
| 11 | +import androidx.compose.material.icons.Icons |
| 12 | +import androidx.compose.material.icons.filled.* |
| 13 | +import androidx.compose.material3.* |
| 14 | +import androidx.compose.runtime.Composable |
| 15 | +import androidx.compose.runtime.getValue |
| 16 | +import androidx.compose.runtime.remember |
| 17 | +import androidx.compose.ui.Alignment |
| 18 | +import androidx.compose.ui.Modifier |
| 19 | +import androidx.compose.ui.draw.clip |
| 20 | +import androidx.compose.ui.graphics.Color |
| 21 | +import androidx.compose.ui.graphics.vector.ImageVector |
| 22 | +import androidx.compose.ui.text.font.FontWeight |
| 23 | +import androidx.compose.ui.unit.dp |
| 24 | +import androidx.compose.ui.unit.sp |
| 25 | +import com.hackeros.app.data.model.AppScreen |
| 26 | +import com.hackeros.app.ui.theme.LocalAppTheme |
| 27 | +import com.hackeros.app.ui.theme.mutedColor |
| 28 | +import com.hackeros.app.ui.theme.primaryColor |
| 29 | +import com.hackeros.app.ui.theme.textColor |
| 30 | +import com.hackeros.app.utils.Translations |
| 31 | + |
| 32 | +data class NavItem( |
| 33 | + val screen: AppScreen, |
| 34 | + val icon: ImageVector, |
| 35 | + val label: String |
| 36 | +) |
| 37 | + |
| 38 | +@Composable |
| 39 | +fun HackerOSNavBar( |
| 40 | + currentScreen: AppScreen, |
| 41 | + onScreenChange: (AppScreen) -> Unit, |
| 42 | + translations: Translations |
| 43 | +) { |
| 44 | + val theme = LocalAppTheme.current |
| 45 | + |
| 46 | + val navItems = listOf( |
| 47 | + NavItem(AppScreen.RELEASES, Icons.Default.List, translations.nav_releases), |
| 48 | + NavItem(AppScreen.WALLPAPERS, Icons.Default.Image, translations.nav_wallpapers), |
| 49 | + NavItem(AppScreen.GALLERY, Icons.Default.CameraAlt, translations.nav_gallery), |
| 50 | + NavItem(AppScreen.TEAM, Icons.Default.Group, translations.nav_team), |
| 51 | + NavItem(AppScreen.SETTINGS, Icons.Default.Settings, translations.nav_config), |
| 52 | + ) |
| 53 | + |
| 54 | + Box( |
| 55 | + modifier = Modifier |
| 56 | + .fillMaxWidth() |
| 57 | + .background(theme.backgroundColor().copy(alpha = 0.92f)) |
| 58 | + ) { |
| 59 | + // Top border line |
| 60 | + Divider( |
| 61 | + color = Color.White.copy(alpha = 0.05f), |
| 62 | + thickness = 1.dp, |
| 63 | + modifier = Modifier.align(Alignment.TopCenter) |
| 64 | + ) |
| 65 | + |
| 66 | + NavigationBar( |
| 67 | + containerColor = Color.Transparent, |
| 68 | + tonalElevation = 0.dp, |
| 69 | + modifier = Modifier |
| 70 | + .fillMaxWidth() |
| 71 | + .navigationBarsPadding() |
| 72 | + ) { |
| 73 | + navItems.forEach { item -> |
| 74 | + val isActive = currentScreen == item.screen |
| 75 | + val iconColor by animateColorAsState( |
| 76 | + targetValue = if (isActive) theme.primaryColor() else theme.mutedColor(), |
| 77 | + animationSpec = spring(stiffness = Spring.StiffnessMedium), |
| 78 | + label = "iconColor" |
| 79 | + ) |
| 80 | + |
| 81 | + NavigationBarItem( |
| 82 | + selected = isActive, |
| 83 | + onClick = { onScreenChange(item.screen) }, |
| 84 | + icon = { |
| 85 | + Column(horizontalAlignment = Alignment.CenterHorizontally) { |
| 86 | + Box( |
| 87 | + modifier = Modifier |
| 88 | + .clip(androidx.compose.foundation.shape.RoundedCornerShape(12.dp)) |
| 89 | + .background( |
| 90 | + if (isActive) theme.primaryColor().copy(alpha = 0.15f) |
| 91 | + else Color.Transparent |
| 92 | + ) |
| 93 | + .padding(horizontal = 12.dp, vertical = 4.dp) |
| 94 | + ) { |
| 95 | + Icon( |
| 96 | + imageVector = item.icon, |
| 97 | + contentDescription = item.label, |
| 98 | + tint = iconColor, |
| 99 | + modifier = Modifier.size(20.dp) |
| 100 | + ) |
| 101 | + } |
| 102 | + if (isActive) { |
| 103 | + Spacer(modifier = Modifier.height(2.dp)) |
| 104 | + Box( |
| 105 | + modifier = Modifier |
| 106 | + .size(4.dp) |
| 107 | + .clip(CircleShape) |
| 108 | + .background(theme.primaryColor()) |
| 109 | + ) |
| 110 | + } |
| 111 | + } |
| 112 | + }, |
| 113 | + label = { |
| 114 | + Text( |
| 115 | + text = item.label.uppercase(), |
| 116 | + fontSize = 9.sp, |
| 117 | + fontWeight = FontWeight.Bold, |
| 118 | + color = if (isActive) theme.primaryColor() else theme.mutedColor().copy(alpha = 0.6f), |
| 119 | + letterSpacing = 0.5.sp, |
| 120 | + maxLines = 1 |
| 121 | + ) |
| 122 | + }, |
| 123 | + colors = NavigationBarItemDefaults.colors( |
| 124 | + indicatorColor = Color.Transparent |
| 125 | + ), |
| 126 | + interactionSource = remember { MutableInteractionSource() } |
| 127 | + ) |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | +} |
0 commit comments