Navigation
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package `in`.sminnovations.attendanceapp
|
package `in`.sminnovations.attendanceapp
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
@@ -7,34 +9,33 @@ import androidx.navigation.compose.NavHost
|
|||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
import `in`.sminnovations.attendanceapp.screens.login.ui.LoginScreen
|
import `in`.sminnovations.attendanceapp.screens.login.ui.LoginScreen
|
||||||
import `in`.sminnovations.attendanceapp.screens.home.navigationDrawer.ui.NavigationDrawer
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun AppNavigation() {
|
fun AppNavigation() {
|
||||||
val navController = rememberNavController()
|
val navController = rememberNavController()
|
||||||
NavigationHost(navController = navController)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
||||||
|
NavigationHost(navController = navController)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O_MR1)
|
||||||
@Composable
|
@Composable
|
||||||
fun NavigationHost(navController: NavHostController) {
|
fun NavigationHost(navController: NavHostController) {
|
||||||
NavHost(navController = navController, startDestination = "login") {
|
NavHost(navController = navController, startDestination = "login") {
|
||||||
// Login Screen Route
|
|
||||||
composable("login") {
|
composable("login") {
|
||||||
LoginScreen(
|
LoginScreen(
|
||||||
loginViewModel = hiltViewModel(),
|
loginViewModel = hiltViewModel(),
|
||||||
onLoginSuccess = {
|
onLoginSuccess = {
|
||||||
// Navigate to the home screen after login success
|
navController.navigate("main") {
|
||||||
navController.navigate("home") {
|
|
||||||
// Pop the login screen from the back stack
|
|
||||||
popUpTo("login") { inclusive = true }
|
popUpTo("login") { inclusive = true }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
composable("main") {
|
||||||
composable("home") {
|
MainScreen()
|
||||||
NavigationDrawer()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package `in`.sminnovations.attendanceapp.navigation
|
||||||
|
|
||||||
|
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.navigation.NavController
|
||||||
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||||
|
import `in`.sminnovations.attendanceapp.navigation.data.BottomNavItem
|
||||||
|
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun BottomNavigationBar(
|
||||||
|
navController: NavController,
|
||||||
|
items: List<BottomNavItem>,
|
||||||
|
) {
|
||||||
|
NavigationBar {
|
||||||
|
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||||
|
val currentRoute = navBackStackEntry?.destination?.route
|
||||||
|
items.forEach { item ->
|
||||||
|
NavigationBarItem(icon = {
|
||||||
|
BottomNavAnimatedIcon(
|
||||||
|
isSelected = currentRoute == item.route,
|
||||||
|
icon = item.icon,
|
||||||
|
selectedIcon = item.selectedIcon,
|
||||||
|
contentDescription = item.label
|
||||||
|
)
|
||||||
|
},
|
||||||
|
label = { Text(text = item.label) },
|
||||||
|
alwaysShowLabel = true,
|
||||||
|
selected = currentRoute == item.route,
|
||||||
|
onClick = {
|
||||||
|
navController.navigate(item.route) {
|
||||||
|
navController.graph.startDestinationRoute?.let { route ->
|
||||||
|
popUpTo(route) {
|
||||||
|
saveState = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
launchSingleTop = true
|
||||||
|
restoreState = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user