PM-25162: Fix a navigation bug in bottom navigation (#5842)

This commit is contained in:
David Perez 2025-09-05 11:38:11 -05:00 committed by GitHub
parent 4c50f873e2
commit fe79ea4822
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 15 deletions

View File

@ -24,6 +24,7 @@ import com.bitwarden.ui.platform.components.navigation.model.NavigationItem
import com.bitwarden.ui.platform.components.scaffold.BitwardenScaffold import com.bitwarden.ui.platform.components.scaffold.BitwardenScaffold
import com.bitwarden.ui.platform.components.scaffold.model.ScaffoldNavigationData import com.bitwarden.ui.platform.components.scaffold.model.ScaffoldNavigationData
import com.bitwarden.ui.platform.theme.RootTransitionProviders import com.bitwarden.ui.platform.theme.RootTransitionProviders
import com.bitwarden.ui.platform.util.toObjectNavigationRoute
import com.x8bit.bitwarden.ui.platform.components.util.rememberBitwardenNavController import com.x8bit.bitwarden.ui.platform.components.util.rememberBitwardenNavController
import com.x8bit.bitwarden.ui.platform.feature.search.model.SearchType import com.x8bit.bitwarden.ui.platform.feature.search.model.SearchType
import com.x8bit.bitwarden.ui.platform.feature.settings.about.navigateToAbout import com.x8bit.bitwarden.ui.platform.feature.settings.about.navigateToAbout
@ -272,14 +273,15 @@ private fun VaultUnlockedNavBarScaffold(
* If direct navigation is required, the [navigate] lambda will be invoked with the appropriate * If direct navigation is required, the [navigate] lambda will be invoked with the appropriate
* [NavOptions]. * [NavOptions].
*/ */
@Suppress("MaxLineLength")
private fun NavController.navigateToTabOrRoot( private fun NavController.navigateToTabOrRoot(
tabToNavigateTo: VaultUnlockedNavBarTab, tabToNavigateTo: VaultUnlockedNavBarTab,
navigate: (NavOptions) -> Unit, navigate: (NavOptions) -> Unit,
) { ) {
if (tabToNavigateTo.startDestinationRoute == currentDestination?.route) { if (tabToNavigateTo.startDestinationRoute.toObjectNavigationRoute() == currentDestination?.route) {
// We are at the start destination already, so nothing to do. // We are at the start destination already, so nothing to do.
return return
} else if (currentDestination?.parent?.route == tabToNavigateTo.graphRoute) { } else if (currentDestination?.parent?.route == tabToNavigateTo.graphRoute.toObjectNavigationRoute()) {
// We are not at the start destination but we are in the correct graph, // We are not at the start destination but we are in the correct graph,
// so lets pop up to the start destination. // so lets pop up to the start destination.
popBackStack(route = tabToNavigateTo.startDestinationRoute, inclusive = false) popBackStack(route = tabToNavigateTo.startDestinationRoute, inclusive = false)
@ -300,8 +302,8 @@ private fun NavController.navigateToTabOrRoot(
/** /**
* Determine if the current destination is the same as the given tab. * Determine if the current destination is the same as the given tab.
*/ */
private fun NavBackStackEntry?.isCurrentRoute(route: String): Boolean = private fun NavBackStackEntry?.isCurrentRoute(route: Any): Boolean =
this this
?.destination ?.destination
?.hierarchy ?.hierarchy
?.any { it.route == route } == true ?.any { it.route == route.toObjectNavigationRoute() } == true

View File

@ -4,7 +4,6 @@ import android.os.Parcelable
import com.bitwarden.ui.platform.components.navigation.model.NavigationItem import com.bitwarden.ui.platform.components.navigation.model.NavigationItem
import com.bitwarden.ui.platform.resource.BitwardenDrawable import com.bitwarden.ui.platform.resource.BitwardenDrawable
import com.bitwarden.ui.platform.resource.BitwardenString import com.bitwarden.ui.platform.resource.BitwardenString
import com.bitwarden.ui.platform.util.toObjectNavigationRoute
import com.x8bit.bitwarden.ui.platform.feature.settings.SettingsGraphRoute import com.x8bit.bitwarden.ui.platform.feature.settings.SettingsGraphRoute
import com.x8bit.bitwarden.ui.platform.feature.settings.SettingsRoute import com.x8bit.bitwarden.ui.platform.feature.settings.SettingsRoute
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorGraphRoute import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorGraphRoute
@ -35,8 +34,8 @@ sealed class VaultUnlockedNavBarTab : NavigationItem, Parcelable {
override val iconRes get() = BitwardenDrawable.ic_generator override val iconRes get() = BitwardenDrawable.ic_generator
override val labelRes get() = BitwardenString.generator override val labelRes get() = BitwardenString.generator
override val contentDescriptionRes get() = BitwardenString.generator override val contentDescriptionRes get() = BitwardenString.generator
override val graphRoute get() = GeneratorGraphRoute.toObjectNavigationRoute() override val graphRoute get() = GeneratorGraphRoute
override val startDestinationRoute get() = GeneratorRoute.Standard.toObjectNavigationRoute() override val startDestinationRoute get() = GeneratorRoute.Standard
override val testTag get() = "GeneratorTab" override val testTag get() = "GeneratorTab"
override val notificationCount get() = 0 override val notificationCount get() = 0
} }
@ -50,8 +49,8 @@ sealed class VaultUnlockedNavBarTab : NavigationItem, Parcelable {
override val iconRes get() = BitwardenDrawable.ic_send override val iconRes get() = BitwardenDrawable.ic_send
override val labelRes get() = BitwardenString.send override val labelRes get() = BitwardenString.send
override val contentDescriptionRes get() = BitwardenString.send override val contentDescriptionRes get() = BitwardenString.send
override val graphRoute get() = SendGraphRoute.toObjectNavigationRoute() override val graphRoute get() = SendGraphRoute
override val startDestinationRoute get() = SendRoute.toObjectNavigationRoute() override val startDestinationRoute get() = SendRoute
override val testTag get() = "SendTab" override val testTag get() = "SendTab"
override val notificationCount get() = 0 override val notificationCount get() = 0
} }
@ -66,8 +65,8 @@ sealed class VaultUnlockedNavBarTab : NavigationItem, Parcelable {
) : VaultUnlockedNavBarTab() { ) : VaultUnlockedNavBarTab() {
override val iconResSelected get() = BitwardenDrawable.ic_vault_filled override val iconResSelected get() = BitwardenDrawable.ic_vault_filled
override val iconRes get() = BitwardenDrawable.ic_vault override val iconRes get() = BitwardenDrawable.ic_vault
override val graphRoute get() = VaultGraphRoute.toObjectNavigationRoute() override val graphRoute get() = VaultGraphRoute
override val startDestinationRoute get() = VaultRoute.toObjectNavigationRoute() override val startDestinationRoute get() = VaultRoute
override val testTag get() = "VaultTab" override val testTag get() = "VaultTab"
override val notificationCount get() = 0 override val notificationCount get() = 0
} }
@ -83,8 +82,8 @@ sealed class VaultUnlockedNavBarTab : NavigationItem, Parcelable {
override val iconRes get() = BitwardenDrawable.ic_settings override val iconRes get() = BitwardenDrawable.ic_settings
override val labelRes get() = BitwardenString.settings override val labelRes get() = BitwardenString.settings
override val contentDescriptionRes get() = BitwardenString.settings override val contentDescriptionRes get() = BitwardenString.settings
override val graphRoute get() = SettingsGraphRoute.toObjectNavigationRoute() override val graphRoute get() = SettingsGraphRoute
override val startDestinationRoute get() = SettingsRoute.Standard.toObjectNavigationRoute() override val startDestinationRoute get() = SettingsRoute.Standard
override val testTag get() = "SettingsTab" override val testTag get() = "SettingsTab"
} }
} }

View File

@ -27,12 +27,12 @@ interface NavigationItem {
/** /**
* Route of the tab's graph. * Route of the tab's graph.
*/ */
val graphRoute: String val graphRoute: Any
/** /**
* Route of the tab's start destination. * Route of the tab's start destination.
*/ */
val startDestinationRoute: String val startDestinationRoute: Any
/** /**
* The test tag of the tab. * The test tag of the tab.