1
+ package com.everymeal.presentation.ui.bottom
2
+
3
+ import androidx.compose.foundation.border
4
+ import androidx.compose.foundation.layout.fillMaxWidth
5
+ import androidx.compose.foundation.shape.RoundedCornerShape
6
+ import androidx.compose.material3.Icon
7
+ import androidx.compose.material3.NavigationBar
8
+ import androidx.compose.material3.NavigationBarItem
9
+ import androidx.compose.material3.NavigationBarItemDefaults
10
+ import androidx.compose.material3.Text
11
+ import androidx.compose.runtime.Composable
12
+ import androidx.compose.ui.Modifier
13
+ import androidx.compose.ui.draw.clip
14
+ import androidx.compose.ui.graphics.Color
15
+ import androidx.compose.ui.graphics.vector.ImageVector
16
+ import androidx.compose.ui.res.stringResource
17
+ import androidx.compose.ui.res.vectorResource
18
+ import androidx.compose.ui.text.TextStyle
19
+ import androidx.compose.ui.tooling.preview.Preview
20
+ import androidx.compose.ui.unit.dp
21
+ import androidx.compose.ui.unit.sp
22
+ import androidx.navigation.NavDestination
23
+ import androidx.navigation.NavGraph.Companion.findStartDestination
24
+ import androidx.navigation.NavHostController
25
+ import com.everymeal.presentation.ui.theme.Gray300
26
+ import com.everymeal.presentation.ui.theme.Gray500
27
+ import com.everymeal.presentation.ui.theme.Main100
28
+ import com.everymeal.presentation.ui.theme.Paddings
29
+
30
+ @Composable
31
+ fun EveryMealBottomNavigation (
32
+ currentDestination : NavDestination ? ,
33
+ navigateToScreen : (BottomNavigation ) -> Unit ,
34
+ ) {
35
+ NavigationBar (
36
+ containerColor = Color .White ,
37
+ modifier = Modifier
38
+ .fillMaxWidth()
39
+ .clip(RoundedCornerShape (topStart = 14 .dp, topEnd = 14 .dp))
40
+ .border(
41
+ width = 1 .dp,
42
+ color = Gray300 ,
43
+ shape = RoundedCornerShape (topStart = 14 .dp, topEnd = 14 .dp)),
44
+ tonalElevation = Paddings .xextra
45
+ ) {
46
+ BottomNavigation .values().forEach { bottomItem ->
47
+ NavigationBarItem (
48
+ icon = {
49
+ Icon (
50
+ imageVector = ImageVector .vectorResource(bottomItem.icon),
51
+ contentDescription = bottomItem.route,
52
+ tint = if (currentDestination?.route == bottomItem.route) {
53
+ Main100
54
+ } else {
55
+ Gray500
56
+ }
57
+ )
58
+ },
59
+ label = {
60
+ Text (
61
+ text = stringResource(bottomItem.title),
62
+ color = if (currentDestination?.route == bottomItem.route) {
63
+ Main100
64
+ } else {
65
+ Gray500
66
+ },
67
+ style = TextStyle (
68
+ fontSize = 12 .sp,
69
+ )
70
+ )
71
+ },
72
+ selected = currentDestination?.route == bottomItem.route,
73
+ onClick = { navigateToScreen(bottomItem) },
74
+ colors = NavigationBarItemDefaults .colors(indicatorColor = Color .White ),
75
+ )
76
+ }
77
+ }
78
+ }
79
+
80
+ fun navigateBottomNavigationScreen (
81
+ navController : NavHostController ,
82
+ navigationItem : BottomNavigation ,
83
+ ) {
84
+ navController.navigate(navigationItem.route) {
85
+ popUpTo(navController.graph.findStartDestination().id) {
86
+ saveState = true
87
+ }
88
+ launchSingleTop = true
89
+ restoreState = true
90
+ }
91
+ }
92
+
93
+ @Preview
94
+ @Composable
95
+ fun PreviewEveryMealBottomNavigation () {
96
+ EveryMealBottomNavigation (
97
+ currentDestination = null ,
98
+ navigateToScreen = {}
99
+ )
100
+ }
0 commit comments