4.28 | 冲刺day10

将页面整合,成一个完整的app

@Composable
fun MainScreen() {
    val navController = rememberNavController()

    NavHost(navController = navController, startDestination = "home") {
        composable("home") {
            HomePage(navController = navController)
        }
        composable("profile") {
            ProfilePage(navController = navController)
        }
        composable("social") {
            SocialPage(navController = navController)
        }
        composable("addMedicine") {
            AddEatMedicinePage(navController = navController)
        }
        composable("adda") {
            AddSocialPage(navController = navController)
        }
        composable("medicine") {
            MedicineScreen(navController = navController)
        }
    }
}

@Composable
fun HomePage(navController: NavController) {

    MySootheTheme {
        Scaffold( bottomBar={ SootheBottomNavigation(navController=navController)}) { padding->
            HomeScreen(Modifier.padding(padding),navController=navController)
        }
    }
}

// Step: Bottom navigation - Material
@Composable
private fun SootheBottomNavigation(modifier: Modifier = Modifier,navController: NavController) {
    NavigationBar(
        modifier = modifier
    ) {
        NavigationBar(
            containerColor = MaterialTheme.colorScheme.surfaceVariant,
            modifier = modifier
        ) {
            NavigationBarItem(
                icon = {
                    Icon(
                        imageVector = Icons.Default.Spa,
                        contentDescription = null
                    )
                },
                label = {
                    Text(stringResource(R.string.bottom_navigation_home))
                },
                selected = true,
                onClick = {
                    navController.navigate("home")
                }
            )
            NavigationRailItem(
                icon = {
                    Icon(
                        imageVector = Icons.Default.AccountBalance,
                        contentDescription = null
                    )
                },
                label = {
                    Text(stringResource(R.string.nav_social))
                },
                selected = false,
                onClick = {
                    navController.navigate("social")
                }
            )
            NavigationBarItem(
                icon = {
                    Icon(
                        imageVector = Icons.Default.AccountCircle,
                        contentDescription = null
                    )
                },
                label = {
                    Text(stringResource(R.string.bottom_navigation_profile))
                },
                selected = false,
                onClick = {
                    navController.navigate("profile")
                }
            )

        }
    }
}
@Composable
fun HomeScreen(
    modifier: Modifier = Modifier,
    navController: NavController
              ) {
    Column(modifier
        .verticalScroll(rememberScrollState())) {
        Spacer(Modifier.height(16.dp))
        SearchBar(Modifier.padding(horizontal = 16.dp))
        HomeSection(title = R.string.homeTitle1) {
            AlignYourBodyRow()
        }
        HomeSection(title = R.string.homeTitle2) {
            FavoriteCollectionsGrid()
        }
        Spacer(Modifier.height(16.dp))
        HomeSection(title = R.string.homeTitle3) {
            PayRow()
        }
        PayColumn(navController = navController)
        Spacer(Modifier.height(16.dp))
    }

}

 

posted on 2024-04-28 21:22  Daniel350  阅读(5)  评论(0编辑  收藏  举报