@@ -142,8 +142,7 @@ internal fun AppTopBar(
142142
143143@Composable
144144internal fun AppBottomBar (
145- currentDestination : NavDestination ? ,
146- fallbackTabRouteQualifiedName : String? ,
145+ selectedTabRouteQualifiedName : String? ,
147146 onTabClick : (TopLevelTab ) -> Unit ,
148147 tabs : List <TopLevelTab > = topLevelTabs,
149148 modifier : Modifier = Modifier ,
@@ -155,10 +154,10 @@ internal fun AppBottomBar(
155154 containerColor = MaterialTheme .colorScheme.surface,
156155 ) {
157156 tabs.forEach { tab: TopLevelTab ->
158- val selected = tab.isSelected(currentDestination, fallbackTabRouteQualifiedName, tabs)
157+ val selected = tab.route:: class .qualifiedName == selectedTabRouteQualifiedName
159158 NavigationBarItem (
160159 selected = selected,
161- onClick = { if ( ! currentDestination.matchesRoute(tab.route)) onTabClick(tab) },
160+ onClick = { onTabClick(tab) },
162161 icon = { Icon (painterResource(tab.iconRes), contentDescription = null ) },
163162 label = { Text (stringResource(tab.labelRes)) },
164163 )
@@ -169,8 +168,7 @@ internal fun AppBottomBar(
169168
170169@Composable
171170internal fun AppNavigationRail (
172- currentDestination : NavDestination ? ,
173- fallbackTabRouteQualifiedName : String? ,
171+ selectedTabRouteQualifiedName : String? ,
174172 onTabClick : (TopLevelTab ) -> Unit ,
175173 tabs : List <TopLevelTab > = topLevelTabs,
176174 modifier : Modifier = Modifier ,
@@ -184,10 +182,10 @@ internal fun AppNavigationRail(
184182 ) {
185183 Spacer (Modifier .weight(1f ))
186184 tabs.forEach { tab: TopLevelTab ->
187- val selected = tab.isSelected(currentDestination, fallbackTabRouteQualifiedName, tabs)
185+ val selected = tab.route:: class .qualifiedName == selectedTabRouteQualifiedName
188186 NavigationRailItem (
189187 selected = selected,
190- onClick = { if ( ! currentDestination.matchesRoute(tab.route)) onTabClick(tab) },
188+ onClick = { onTabClick(tab) },
191189 icon = { Icon (painterResource(tab.iconRes), contentDescription = null ) },
192190 label = { Text (stringResource(tab.labelRes)) },
193191 )
@@ -220,16 +218,6 @@ private fun ProfileAvatarButton(
220218 }
221219}
222220
223- private fun TopLevelTab.isSelected (
224- destination : NavDestination ? ,
225- fallbackRouteName : String? ,
226- tabs : List <TopLevelTab >,
227- ): Boolean {
228- val direct = destination.matchesRoute(route)
229- val anyDirect = tabs.any { destination.matchesRoute(it.route) }
230- return direct || (! anyDirect && route::class .qualifiedName == fallbackRouteName)
231- }
232-
233221internal fun NavDestination?.matchesRoute (route : Any ): Boolean {
234222 val destination = this ? : return false
235223 return when (route) {
0 commit comments