diff --git a/composeApp/src/androidMain/kotlin/com/maxrave/simpmusic/ui/component/LiquidGlassAppBottomNavigationBar.android.kt b/composeApp/src/androidMain/kotlin/com/maxrave/simpmusic/ui/component/LiquidGlassAppBottomNavigationBar.android.kt index f9a01663d6..22fd5b1ffd 100644 --- a/composeApp/src/androidMain/kotlin/com/maxrave/simpmusic/ui/component/LiquidGlassAppBottomNavigationBar.android.kt +++ b/composeApp/src/androidMain/kotlin/com/maxrave/simpmusic/ui/component/LiquidGlassAppBottomNavigationBar.android.kt @@ -156,6 +156,19 @@ actual fun LiquidGlassAppBottomNavigationBar( currentBackStackEntry?.destination?.let { current -> Logger.d(TAG, "LiquidGlassAppBottomNavigationBar: current route: ${current.route}") isInSearchDestination = current.hasRoute(SearchDestination::class) + // Navigation that does not go through selectTab — above all the system Back + // button — changes the destination without touching selectedIndex, so Back from + // Library, Mix or Search landed on Home with the previous tab still highlighted + // (#2714). Sync the highlight from the destination here, where its changes are + // already observed. A destination outside the tab list matches nothing and keeps + // the current tab. + val matched = + bottomNavScreens.firstOrNull { screen -> + current.hierarchy.any { it.hasRoute(screen.destination::class) } + } + if (matched != null && matched.ordinal != selectedIndex) { + selectedIndex = matched.ordinal + } } } diff --git a/composeApp/src/commonMain/kotlin/com/maxrave/simpmusic/ui/component/AppBottomNavigationBar.kt b/composeApp/src/commonMain/kotlin/com/maxrave/simpmusic/ui/component/AppBottomNavigationBar.kt index 52741776bb..642590778a 100644 --- a/composeApp/src/commonMain/kotlin/com/maxrave/simpmusic/ui/component/AppBottomNavigationBar.kt +++ b/composeApp/src/commonMain/kotlin/com/maxrave/simpmusic/ui/component/AppBottomNavigationBar.kt @@ -100,6 +100,21 @@ fun AppBottomNavigationBar( selectedIndex = BottomNavScreen.Home.ordinal } } + // Navigation that does not go through selectTab — above all the system Back button — changes + // the destination without touching selectedIndex, so Back from Library, Mix or Search landed + // on Home with the previous tab still highlighted (#2714). Sync the highlight from the + // destination whenever it changes. A destination outside the tab list matches nothing and + // keeps the current tab. + LaunchedEffect(currentBackStackEntry) { + val current = currentBackStackEntry?.destination ?: return@LaunchedEffect + val matched = + bottomNavScreens.firstOrNull { screen -> + current.hierarchy.any { it.hasRoute(screen.destination::class) } + } + if (matched != null && matched.ordinal != selectedIndex) { + selectedIndex = matched.ordinal + } + } val selectTab: (BottomNavScreen) -> Unit = { screen -> if (selectedIndex == screen.ordinal) { if (currentBackStackEntry?.destination?.hierarchy?.any {