From 12eebab2508aa4ec82e5f4e372fd0f3f6b39407a Mon Sep 17 00:00:00 2001 From: chanu Date: Fri, 19 Apr 2024 07:10:55 +0900 Subject: [PATCH] =?UTF-8?q?#11=20[feat]=20:=20=EB=B0=94=ED=85=80=20?= =?UTF-8?q?=EB=84=A4=EB=B9=84=EA=B2=8C=EC=9D=B4=EC=85=98=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/feature/nav/BottomNavigation.kt | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 app/src/main/java/com/sopt/now/compose/feature/nav/BottomNavigation.kt diff --git a/app/src/main/java/com/sopt/now/compose/feature/nav/BottomNavigation.kt b/app/src/main/java/com/sopt/now/compose/feature/nav/BottomNavigation.kt new file mode 100644 index 0000000..32d76cd --- /dev/null +++ b/app/src/main/java/com/sopt/now/compose/feature/nav/BottomNavigation.kt @@ -0,0 +1,47 @@ +package com.sopt.now.compose.feature.nav + +import androidx.compose.material3.Icon +import androidx.compose.material3.NavigationBar +import androidx.compose.material3.NavigationBarItem +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.res.painterResource +import androidx.navigation.NavController +import androidx.navigation.compose.currentBackStackEntryAsState + +@Composable +fun BottomNavigation(navController: NavController) { + val items = listOf( + BottomNavItem.Home, + BottomNavItem.Search, + BottomNavItem.MyPage + ) + + val navBackStackEntry by navController.currentBackStackEntryAsState() + val currentRoute = navBackStackEntry?.destination?.route + NavigationBar { + items.forEachIndexed { index, item -> + NavigationBarItem( + icon = { + val iconPainter = painterResource(id = item.icon) + Icon( + painter = iconPainter, + contentDescription = item.label + ) + }, + label = { Text(item.label) }, + selected = currentRoute == item.screenRoute, + onClick = { + navController.navigate(item.screenRoute) { + navController.graph.startDestinationRoute?.let { + popUpTo(it) { saveState = true } + } + launchSingleTop = true + restoreState = true + } + } + ) + } + } +}