AppBar - Material3Api
kotlin
enum class LaunchTrayScreen(@StringRes val title: Int){
Start(title = R.string.app_name),
Entree(title = R.string.choose_entree),
SideDish(title = R.string.choose_side_dish),
Accompaniment(title = R.string.choose_accompaniment),
Checkout(title = R.string.order_checkout)
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun LaunchTrayAppBar(
@StringRes currentScreenTitle: Int,
canNavigateBack: Boolean,
navigateUp: () -> Unit,
modifier: Modifier = Moidfier
){
CenterAlignedTopAppBar(
title = { Text(stringResource(currentScreenTitle)) },
modifier = modifier,
navigationIcon = {
if (canNavigateBack) {
IconButton(onClick = navigateUp){
Icon(
imageVector = Icons.Filled.ArrowBack,
contentDescription = stringResource(id = R.string.back_button)
)
}
}
}
)
}
@Composable
fun LaunchTrayScreen(){
val viewModel: OrderViewModel = viewModel()
val navControlled = rememberNavController()
val backStackEntry by navController.currentBackStackEntryAsState()
val currentScreen = LaunchTrayScreen.valueOf(
backStackEntry?.destination?.route ?: LaunchTrayScreen.Start.name
)
Scaffold(
topBar = {
LaunchTrayAppBar(
currentScreenTitle = currentScreen.title,
canNavigateBack = navController.previousBackStackEntry != null,
navigateUp = { navController.navigateUp() }
)
}
){ innerPadding ->
val uiState by viewModel.uiState.collectAsState()
// TODO: Navigation host
NavHost(navController = navController,
startDestination = LaunchTrayScreen.Start.name){
composable(route = LaunchTrayScreen.Start.name){
StartOrderScreen(
onStartOrderButtonClicked = { /*TODO*/ },
modifier = Modifier.padding(innerPadding)
)
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66