Skip to content

Commit

Permalink
#11 [feat] : 바텀 네비게이션 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
chanubc committed Apr 18, 2024
1 parent 4601400 commit 12eebab
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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>(
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
}
}
)
}
}
}

0 comments on commit 12eebab

Please sign in to comment.