diff --git a/app/src/main/java/hu/bme/kszk/szobatarsch/composable/BottomNavBar.kt b/app/src/main/java/hu/bme/kszk/szobatarsch/composable/BottomNavBar.kt new file mode 100644 index 0000000000000000000000000000000000000000..6dfdd66d65f5a033c8e589ad27580f2bb385e54c --- /dev/null +++ b/app/src/main/java/hu/bme/kszk/szobatarsch/composable/BottomNavBar.kt @@ -0,0 +1,81 @@ +package hu.bme.kszk.szobatarsch.composable + +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.* +import androidx.compose.material3.* +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.navigation.NavGraph.Companion.findStartDestination +import androidx.navigation.NavHostController +import androidx.navigation.compose.currentBackStackEntryAsState + +sealed class NavRoutes(val route: String) { + object Find : NavRoutes("find") + object Matches : NavRoutes("matches") + object Profile : NavRoutes("profile") + object Settings : NavRoutes("settings") +} + +data class BarItem( + val title: String, + val image: ImageVector, + val route: String +) + +object NavBarItems { + val BarItems = listOf( + BarItem( + title = "Find", + image = Icons.Filled.Search, + route = "find" + ), + BarItem( + title = "Matches", + image = Icons.Filled.ThumbUp, + route = "matches" + ), + BarItem( + title = "Profile", + image = Icons.Filled.Face, + route = "profile" + ), + BarItem( + title = "Settings", + image = Icons.Filled.Settings, + route = "settings" + ) + ) +} + +@Composable +fun BottomNavigationBar(navController: NavHostController) { + NavigationBar { + val backStackEntry by navController.currentBackStackEntryAsState() + val currentRoute = backStackEntry?.destination?.route + + NavBarItems.BarItems.forEach { navItem -> + + NavigationBarItem( + selected = currentRoute == navItem.route, + onClick = { + navController.navigate(navItem.route) { + popUpTo(navController.graph.findStartDestination().id) { + saveState = true + } + launchSingleTop = true + restoreState = true + } + }, + + icon = { + Icon(imageVector = navItem.image, + contentDescription = navItem.title) + }, + label = { + Text(text = navItem.title) + }, + ) + } + } +} \ No newline at end of file