|
1 | 1 | package com.itocc.icampuspass |
2 | 2 |
|
3 | | -import androidx.compose.animation.AnimatedVisibility |
4 | | -import androidx.compose.foundation.Image |
5 | | -import androidx.compose.foundation.layout.Column |
6 | | -import androidx.compose.foundation.layout.fillMaxWidth |
| 3 | +import androidx.activity.compose.BackHandler |
| 4 | +import androidx.compose.foundation.isSystemInDarkTheme |
| 5 | +import androidx.compose.foundation.layout.fillMaxSize |
| 6 | +import androidx.compose.foundation.layout.padding |
7 | 7 | import androidx.compose.foundation.layout.safeDrawingPadding |
8 | | -import androidx.compose.material3.Button |
| 8 | +import androidx.compose.material3.DrawerState |
| 9 | +import androidx.compose.material3.DrawerValue |
9 | 10 | import androidx.compose.material3.MaterialTheme |
10 | | -import androidx.compose.material3.Text |
| 11 | +import androidx.compose.material3.ModalNavigationDrawer |
| 12 | +import androidx.compose.material3.Scaffold |
| 13 | +import androidx.compose.material3.darkColorScheme |
| 14 | +import androidx.compose.material3.lightColorScheme |
| 15 | +import androidx.compose.material3.rememberDrawerState |
11 | 16 | import androidx.compose.runtime.Composable |
12 | | -import androidx.compose.runtime.getValue |
13 | | -import androidx.compose.runtime.mutableStateOf |
14 | | -import androidx.compose.runtime.remember |
15 | | -import androidx.compose.runtime.setValue |
16 | | -import androidx.compose.ui.Alignment |
| 17 | +import androidx.compose.runtime.rememberCoroutineScope |
17 | 18 | import androidx.compose.ui.Modifier |
18 | 19 | import androidx.compose.ui.tooling.preview.Preview |
19 | | -import icampuspass.composeapp.generated.resources.Res |
20 | | -import icampuspass.composeapp.generated.resources.compose_multiplatform |
21 | | -import org.jetbrains.compose.resources.painterResource |
| 20 | +import androidx.navigation.NavHostController |
| 21 | +import androidx.navigation.compose.NavHost |
| 22 | +import androidx.navigation.compose.composable |
| 23 | +import androidx.navigation.compose.rememberNavController |
| 24 | +import com.itocc.icampuspass.components.ModalDrawerSheetComponent |
| 25 | +import com.itocc.icampuspass.components.TopAppBarComponent |
| 26 | +import com.itocc.icampuspass.destinations.ClassScheduleDestination |
| 27 | +import com.itocc.icampuspass.destinations.MainDestination |
| 28 | +import com.itocc.icampuspass.screens.ClassScheduleScreen |
| 29 | +import com.itocc.icampuspass.screens.MainScreen |
| 30 | +import kotlinx.coroutines.CoroutineScope |
| 31 | +import kotlinx.coroutines.launch |
22 | 32 |
|
23 | 33 | @Preview |
24 | 34 | @Composable |
25 | 35 | fun App() { |
26 | | - MaterialTheme { |
27 | | - var showContent by remember { mutableStateOf(value = false) } |
| 36 | + val drawerState: DrawerState = rememberDrawerState(initialValue = DrawerValue.Closed) |
28 | 37 |
|
29 | | - Column( |
30 | | - modifier = Modifier.fillMaxWidth().safeDrawingPadding(), |
31 | | - horizontalAlignment = Alignment.CenterHorizontally |
32 | | - ) { |
33 | | - Button(onClick = { showContent = !showContent }) { |
34 | | - Text(text = "Click me!") |
35 | | - } |
| 38 | + val scope: CoroutineScope = rememberCoroutineScope() |
36 | 39 |
|
37 | | - AnimatedVisibility(visible = showContent) { |
38 | | - val greeting = remember { Greeting().greet() } |
| 40 | + val navController: NavHostController = rememberNavController() |
39 | 41 |
|
40 | | - Column( |
41 | | - modifier = Modifier.fillMaxWidth(), |
42 | | - horizontalAlignment = Alignment.CenterHorizontally |
43 | | - ) { |
44 | | - Image( |
45 | | - painter = painterResource(resource = Res.drawable.compose_multiplatform), |
46 | | - contentDescription = null |
47 | | - ) |
| 42 | + MaterialTheme( |
| 43 | + colorScheme = if (isSystemInDarkTheme()) { |
| 44 | + darkColorScheme() |
| 45 | + } else { |
| 46 | + lightColorScheme() |
| 47 | + } |
| 48 | + ) { |
| 49 | + ModalNavigationDrawer( |
| 50 | + drawerContent = { |
| 51 | + ModalDrawerSheetComponent( |
| 52 | + navController = navController, |
| 53 | + scope = scope, |
| 54 | + drawerState = drawerState |
| 55 | + ) |
| 56 | + }, |
| 57 | + modifier = Modifier.fillMaxSize().safeDrawingPadding(), |
| 58 | + drawerState = drawerState, |
| 59 | + gesturesEnabled = drawerState.isOpen, |
| 60 | + content = { |
| 61 | + Scaffold( |
| 62 | + topBar = { |
| 63 | + TopAppBarComponent(scope = scope, drawerState = drawerState) |
| 64 | + }, |
| 65 | + content = { innerPadding -> |
| 66 | + NavHost(navController = navController, startDestination = MainDestination) { |
| 67 | + composable<MainDestination> { |
| 68 | + MainScreen( |
| 69 | + modifier = Modifier |
| 70 | + .padding(innerPadding) |
| 71 | + .fillMaxSize() |
| 72 | + ) |
| 73 | + } |
| 74 | + composable<ClassScheduleDestination> { |
| 75 | + ClassScheduleScreen( |
| 76 | + modifier = Modifier |
| 77 | + .padding(innerPadding) |
| 78 | + .fillMaxSize() |
| 79 | + ) |
| 80 | + } |
| 81 | + } |
48 | 82 |
|
49 | | - Text(text = "Compose: $greeting") |
50 | | - } |
| 83 | + BackHandler(enabled = drawerState.isOpen) { |
| 84 | + scope.launch { |
| 85 | + drawerState.close() |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + ) |
51 | 90 | } |
52 | | - } |
| 91 | + ) |
53 | 92 | } |
54 | 93 | } |
0 commit comments