From 4ba2aaca90b6b2e434f9db0b757f5413911e0c3b Mon Sep 17 00:00:00 2001 From: jpcmpc23 <129786532+jpcmpc123@users.noreply.github.com> Date: Mon, 16 Nov 2026 15:31:43 -0400 Subject: [PATCH] fix(bottom-bar): sync selected tab with current destination The bottom bars only updated selectedIndex on tap, so pressing Back from Library, Mix or Search landed on Home with the previous tab still highlighted. Sync the highlight from the destination whenever it changes. Refs maxrave-dev/SimpMusic#2714 --- .../LiquidGlassAppBottomNavigationBar.android.kt | 13 +++++++++++++ .../ui/component/AppBottomNavigationBar.kt | 15 +++++++++++++++ 2 files changed, 28 insertions(+) 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 {