Skip to content

Commit 330a9e2

Browse files
author
Gurupreet Singh
committed
remove navigation compose
1 parent 3369e55 commit 330a9e2

File tree

8 files changed

+65
-154
lines changed

8 files changed

+65
-154
lines changed

ThemingCodelab/app/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ dependencies {
123123
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.5.1"
124124
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.5.1"
125125

126-
implementation 'androidx.navigation:navigation-compose:2.5.3'
127-
128126
androidTestImplementation 'androidx.test:rules:1.5.0'
129127
androidTestImplementation 'androidx.test:runner:1.5.2'
130128

ThemingCodelab/app/src/main/java/com/example/reply/ui/ReplyApp.kt

Lines changed: 64 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,30 @@ package com.example.reply.ui
1919
import androidx.compose.foundation.layout.Column
2020
import androidx.compose.foundation.layout.fillMaxSize
2121
import 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
2227
import androidx.compose.material3.Icon
2328
import androidx.compose.material3.NavigationBar
2429
import androidx.compose.material3.NavigationBarItem
2530
import androidx.compose.runtime.Composable
26-
import androidx.compose.runtime.getValue
31+
import androidx.compose.runtime.mutableStateOf
2732
import androidx.compose.runtime.remember
2833
import androidx.compose.ui.Modifier
34+
import androidx.compose.ui.graphics.vector.ImageVector
2935
import 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
4139
fun 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(
6552
fun 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+
)

ThemingCodelab/app/src/main/java/com/example/reply/ui/navigation/ReplyNavigationActions.kt

Lines changed: 0 additions & 88 deletions
This file was deleted.

ThemingCodelab/app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<string name="compose">Compose</string>
2727

2828
<string name="empty_screen_title">Screen under construction</string>
29-
<string name="empty_screen_subtitle">This screen is still under construction. This sample will help you learn about adaptive layouts in Jetpack Compose</string>
29+
<string name="empty_screen_subtitle">This screen is still under construction.</string>
3030

3131
<string name="back_button">Back</string>
3232
<string name="more_options_button">More options</string>

0 commit comments

Comments
 (0)