Skip to content

Commit aed894a

Browse files
sam-arth07itsPronay
authored andcommitted
fix(navigation) : back navigation registers search screen successfully. (openMF#2408)
1 parent eb13df0 commit aed894a

2 files changed

Lines changed: 10 additions & 17 deletions

File tree

cmp-navigation/src/commonMain/kotlin/cmp/navigation/App.kt

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import androidx.compose.ui.graphics.Color
6666
import androidx.compose.ui.layout.ContentScale
6767
import androidx.compose.ui.unit.dp
6868
import androidx.lifecycle.compose.collectAsStateWithLifecycle
69+
import androidx.navigation.NavGraph.Companion.findStartDestination
6970
import androidx.navigation.compose.currentBackStackEntryAsState
7071
import cmp.navigation.components.MifosNavigationBar
7172
import cmp.navigation.components.NavigationConstants
@@ -195,18 +196,8 @@ fun App(
195196
selected = index == selectedItemIndex,
196197
onClick = {
197198
selectedItemIndex = index
198-
selectedItemIndex?.let {
199-
appState.navController.apply {
200-
navigate(navigationDrawerTabs[it].route) {
201-
restoreState = true
202-
launchSingleTop = true
203-
graph.startDestinationRoute?.let {
204-
popUpTo(route = HomeDestinationsScreen.SearchScreen.route) {
205-
saveState = true
206-
}
207-
}
208-
}
209-
}
199+
appState.navController.navigate(navigationDrawerTabs[index].route) {
200+
launchSingleTop = true
210201
}
211202
scope.launch {
212203
drawerState.close()
@@ -275,10 +266,9 @@ fun App(
275266
navigate(target) {
276267
restoreState = true
277268
launchSingleTop = true
278-
graph.startDestinationRoute?.let {
279-
popUpTo(route = HomeDestinationsScreen.SearchScreen.route) {
280-
saveState = true
281-
}
269+
popUpTo(route = graph.findStartDestination().route.toString()) {
270+
saveState = true
271+
inclusive = false
282272
}
283273
}
284274
}

cmp-navigation/src/commonMain/kotlin/cmp/navigation/components/MifosNavigationBar.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import androidx.compose.material3.NavigationBar
1414
import androidx.compose.material3.NavigationBarItem
1515
import androidx.compose.material3.Text
1616
import androidx.compose.runtime.Composable
17+
import androidx.compose.runtime.remember
1718
import androidx.compose.runtime.saveable.rememberSaveable
1819
import androidx.compose.ui.Modifier
1920
import androidx.compose.ui.graphics.Color
@@ -35,11 +36,13 @@ fun MifosNavigationBar(
3536
HomeDestinationsScreen.GroupListScreen,
3637
)
3738
}
39+
val isAnyTabSelected = remember(route) { tabs.any { route.contains(it.route) } }
3840

3941
NavigationBar(modifier = modifier) {
4042
tabs.forEach { item ->
4143
val targetRoute = item.route
42-
val selected = route.contains(targetRoute)
44+
val selected =
45+
if (isAnyTabSelected) route.contains(targetRoute) else targetRoute == HomeDestinationsScreen.SearchScreen.route
4346
NavigationBarItem(
4447
icon = {
4548
item.icon?.let {

0 commit comments

Comments
 (0)