@@ -19,43 +19,30 @@ package com.example.reply.ui
1919import androidx.compose.foundation.layout.Column
2020import androidx.compose.foundation.layout.fillMaxSize
2121import androidx.compose.foundation.layout.fillMaxWidth
22+ import androidx.compose.material.icons.Icons
23+ import androidx.compose.material.icons.filled.Article
24+ import androidx.compose.material.icons.filled.Inbox
25+ import androidx.compose.material.icons.filled.People
26+ import androidx.compose.material.icons.outlined.ChatBubbleOutline
2227import androidx.compose.material3.Icon
2328import androidx.compose.material3.NavigationBar
2429import androidx.compose.material3.NavigationBarItem
2530import androidx.compose.runtime.Composable
26- import androidx.compose.runtime.getValue
31+ import androidx.compose.runtime.mutableStateOf
2732import androidx.compose.runtime.remember
2833import androidx.compose.ui.Modifier
34+ import androidx.compose.ui.graphics.vector.ImageVector
2935import androidx.compose.ui.res.stringResource
30- import androidx.navigation.NavHostController
31- import androidx.navigation.compose.NavHost
32- import androidx.navigation.compose.composable
33- import androidx.navigation.compose.currentBackStackEntryAsState
34- import androidx.navigation.compose.rememberNavController
35- import com.example.reply.ui.navigation.ReplyNavigationActions
36- import com.example.reply.ui.navigation.ReplyRoute
37- import com.example.reply.ui.navigation.ReplyTopLevelDestination
38- import com.example.reply.ui.navigation.TOP_LEVEL_DESTINATIONS
36+ import com.example.reply.R
3937
4038@Composable
4139fun ReplyApp (
4240 replyHomeUIState : ReplyHomeUIState ,
4341 closeDetailScreen : () -> Unit = {},
4442 navigateToDetail : (Long ) -> Unit
4543) {
46- val navController = rememberNavController()
47- val navigationActions = remember(navController) {
48- ReplyNavigationActions (navController)
49- }
50- val navBackStackEntry by navController.currentBackStackEntryAsState()
51- val selectedDestination =
52- navBackStackEntry?.destination?.route ? : ReplyRoute .INBOX
53-
5444 ReplyAppContent (
5545 replyHomeUIState = replyHomeUIState,
56- navController = navController,
57- selectedDestination = selectedDestination,
58- navigateToTopLevelDestination = navigationActions::navigateTo,
5946 closeDetailScreen = closeDetailScreen,
6047 navigateToDetail = navigateToDetail
6148 )
@@ -65,29 +52,33 @@ fun ReplyApp(
6552fun ReplyAppContent (
6653 modifier : Modifier = Modifier ,
6754 replyHomeUIState : ReplyHomeUIState ,
68- navController : NavHostController ,
69- selectedDestination : String ,
70- navigateToTopLevelDestination : (ReplyTopLevelDestination ) -> Unit ,
7155 closeDetailScreen : () -> Unit ,
7256 navigateToDetail : (Long ) -> Unit ,
7357) {
7458
59+ val selectedDestination = remember { mutableStateOf( ReplyRoute .INBOX ) }
60+
7561 Column (
7662 modifier = modifier
7763 .fillMaxSize()
7864 ) {
79- ReplyNavHost (
80- navController = navController,
81- replyHomeUIState = replyHomeUIState,
82- closeDetailScreen = closeDetailScreen,
83- navigateToDetail = navigateToDetail,
84- modifier = Modifier .weight(1f ),
85- )
65+
66+ if (selectedDestination.value == ReplyRoute .INBOX ) {
67+ ReplyInboxScreen (
68+ replyHomeUIState = replyHomeUIState,
69+ closeDetailScreen = closeDetailScreen,
70+ navigateToDetail = navigateToDetail,
71+ modifier = Modifier .weight(1f )
72+ )
73+ } else {
74+ EmptyComingSoon (modifier = Modifier .weight(1f ))
75+ }
76+
8677 NavigationBar (modifier = Modifier .fillMaxWidth()) {
8778 TOP_LEVEL_DESTINATIONS .forEach { replyDestination ->
8879 NavigationBarItem (
89- selected = selectedDestination == replyDestination.route,
90- onClick = { navigateToTopLevelDestination( replyDestination) },
80+ selected = selectedDestination.value == replyDestination.route,
81+ onClick = { selectedDestination.value = replyDestination.route },
9182 icon = {
9283 Icon (
9384 imageVector = replyDestination.selectedIcon,
@@ -100,34 +91,44 @@ fun ReplyAppContent(
10091 }
10192}
10293
103- @Composable
104- private fun ReplyNavHost (
105- navController : NavHostController ,
106- replyHomeUIState : ReplyHomeUIState ,
107- closeDetailScreen : () -> Unit ,
108- navigateToDetail : (Long ) -> Unit ,
109- modifier : Modifier = Modifier ,
110- ) {
111- NavHost (
112- modifier = modifier,
113- navController = navController,
114- startDestination = ReplyRoute .INBOX ,
115- ) {
116- composable(ReplyRoute .INBOX ) {
117- ReplyInboxScreen (
118- replyHomeUIState = replyHomeUIState,
119- closeDetailScreen = closeDetailScreen,
120- navigateToDetail = navigateToDetail,
121- )
122- }
123- composable(ReplyRoute .DM ) {
124- EmptyComingSoon ()
125- }
126- composable(ReplyRoute .ARTICLES ) {
127- EmptyComingSoon ()
128- }
129- composable(ReplyRoute .GROUPS ) {
130- EmptyComingSoon ()
131- }
132- }
94+
95+ object ReplyRoute {
96+ const val INBOX = " Inbox"
97+ const val ARTICLES = " Articles"
98+ const val DM = " DirectMessages"
99+ const val GROUPS = " Groups"
133100}
101+
102+ data class ReplyTopLevelDestination (
103+ val route : String ,
104+ val selectedIcon : ImageVector ,
105+ val unselectedIcon : ImageVector ,
106+ val iconTextId : Int
107+ )
108+
109+ val TOP_LEVEL_DESTINATIONS = listOf (
110+ ReplyTopLevelDestination (
111+ route = ReplyRoute .INBOX ,
112+ selectedIcon = Icons .Default .Inbox ,
113+ unselectedIcon = Icons .Default .Inbox ,
114+ iconTextId = R .string.tab_inbox
115+ ),
116+ ReplyTopLevelDestination (
117+ route = ReplyRoute .ARTICLES ,
118+ selectedIcon = Icons .Default .Article ,
119+ unselectedIcon = Icons .Default .Article ,
120+ iconTextId = R .string.tab_article
121+ ),
122+ ReplyTopLevelDestination (
123+ route = ReplyRoute .DM ,
124+ selectedIcon = Icons .Outlined .ChatBubbleOutline ,
125+ unselectedIcon = Icons .Outlined .ChatBubbleOutline ,
126+ iconTextId = R .string.tab_inbox
127+ ),
128+ ReplyTopLevelDestination (
129+ route = ReplyRoute .GROUPS ,
130+ selectedIcon = Icons .Default .People ,
131+ unselectedIcon = Icons .Default .People ,
132+ iconTextId = R .string.tab_article
133+ )
134+ )
0 commit comments