Created
August 25, 2023 12:16
-
-
Save chiragthummar/c245ac8ec2701169bb7bc104bcbefd06 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @OptIn(ExperimentalMaterial3Api::class) | |
| @Composable | |
| fun HomeScreen( | |
| navigateTo: (route: String) -> Unit | |
| ) { | |
| val topLevelDestinations = listOf( | |
| TopLevelDestination( | |
| route = NavRoute.Screen1.route, | |
| selectedIcon = R.drawable.home, | |
| unselectedIcon = R.drawable.home_outline, | |
| iconText = "Home" | |
| ), TopLevelDestination( | |
| route = NavRoute.Screen2.route, | |
| selectedIcon = R.drawable.bulb, | |
| unselectedIcon = R.drawable.bulb_outline, | |
| iconText = "Generate" | |
| ), TopLevelDestination( | |
| route = NavRoute.Screen3.route, | |
| selectedIcon = R.drawable.my_files, | |
| unselectedIcon = R.drawable.my_files_outline, | |
| iconText = "My Files" | |
| ) | |
| ) | |
| val showBottomBar = remember { mutableStateOf(true) } | |
| val title = remember { | |
| mutableStateOf("Home") | |
| } | |
| val navController = rememberNavController() | |
| Scaffold( | |
| topBar = { | |
| CenterAlignedTopAppBar(title = { | |
| Text( | |
| text = title.value, | |
| color = Color.White, | |
| fontWeight = FontWeight.Bold, | |
| fontSize = 20.sp, | |
| ) | |
| }, colors = TopAppBarDefaults.centerAlignedTopAppBarColors( | |
| containerColor = MaterialTheme.colorScheme.primary | |
| ), actions = { | |
| Icon( | |
| imageVector = Icons.Filled.Settings, | |
| tint = MaterialTheme.colorScheme.onPrimary, | |
| contentDescription = "Settings", | |
| modifier = Modifier | |
| .clickable { | |
| navigateTo(NavRoute.Settings.route) | |
| } | |
| .padding(8.dp) | |
| ) | |
| }) | |
| }, | |
| bottomBar = { | |
| if (showBottomBar.value) { | |
| HomeBottomBar(destinations = topLevelDestinations, | |
| currentDestination = navController.currentBackStackEntryAsState().value?.destination, | |
| onNavigateToDestination = { | |
| title.value = when (it) { | |
| "sc1" -> "Screen 1" | |
| "sc2" -> "Screen 2" | |
| else -> { | |
| "Screen 3" | |
| } | |
| } | |
| navController.navigate(it) { | |
| popUpTo(navController.graph.findStartDestination().id) { | |
| saveState = true | |
| } | |
| restoreState = true | |
| launchSingleTop = true | |
| } | |
| }) | |
| } | |
| } | |
| ) { | |
| Column( | |
| modifier = Modifier | |
| .padding(it) | |
| .fillMaxSize() | |
| ) { | |
| HomeNavHost( | |
| modifier = Modifier | |
| .fillMaxSize() | |
| .weight(1f), | |
| navController = navController, | |
| startDestination = NavRoute.Screen1.route, | |
| navigateTo = navigateTo | |
| ) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment