Skip to content

Conversation

@LuisDev2576
Copy link

Summary

This pull request fixes an issue where navigating to the same screen multiple times could occur when interacting with the TopBar. See: #210

Problem

Currently, when a user focuses or clicks on a TopBar tab that corresponds to the screen they are already on, the app still triggers a navigation action.
This behavior leads to an unnecessary recomposition of the current screen, causing redundant work and a less smooth user experience.

Before (current behavior):

Screen_recording_20250820_162620.mp4
  • Selecting the same tab again triggers navigation.
  • The current screen is recomposed unnecessarily.

After (fixed behavior):

Screen_recording_20250820_162752.mp4
  • Selecting the same tab no longer triggers navigation.
  • The app remains stable on the current screen without recomposing.

Changes Introduced

  • Added a validation in DashboardScreen to compare the current route with the target route before calling navController.navigate().
  • Updated DashboardTopBar so that onFocus and onClick events only trigger navigation if the selected tab is different from the current one.

Benefits

  • Prevents redundant navigation calls.
  • Avoids unnecessary recompositions.
  • Improves performance and ensures a smoother user experience when interacting with the TopBar.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @LuisDev2576, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue in the TopBar navigation where selecting the currently active tab would trigger an unnecessary navigation action and screen recomposition. The fix introduces a validation check to prevent navigation if the target screen is already the current screen, thereby improving overall performance and user experience by avoiding redundant work.

Highlights

  • Navigation Optimization: Implemented a check in DashboardScreen to prevent navController.navigate() calls when the user attempts to navigate to the screen they are already on via the TopBar.
  • Performance Improvement: Eliminated unnecessary screen recompositions that previously occurred when interacting with the TopBar and selecting the active tab, leading to a smoother user experience.
  • User Experience Enhancement: Ensured that selecting the same TopBar tab no longer triggers redundant navigation, providing a more stable and responsive interface.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively resolves an issue with unnecessary recompositions when navigating to the same screen from the top bar. The approach of checking the current route against the target route before triggering navigation is correct. I've added one suggestion to use the existing currentDestination state variable for this check, which would make the implementation slightly more consistent with the surrounding code. Overall, this is a good improvement for the app's performance and user experience.

Comment on lines 183 to 190
val targetRoute = screen()
val currentRoute = navController.currentBackStackEntry?.destination?.route
if (currentRoute != targetRoute) {
navController.navigate(targetRoute) {
if (screen == TopBarTabs[0]) popUpTo(TopBarTabs[0].invoke())
launchSingleTop = true
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency and to leverage the existing state management within this composable, you can use the currentDestination state variable that is already being maintained. This avoids querying the navController directly and makes the logic slightly cleaner and more aligned with how state is handled in the rest of this screen.

            val targetRoute = screen()
            if (currentDestination != targetRoute) {
                navController.navigate(targetRoute) {
                    if (screen == TopBarTabs[0]) popUpTo(TopBarTabs[0].invoke())
                    launchSingleTop = true
                }
            }

This commit optimises navigation in `DashboardScreen` by checking against `currentDestination` instead of `navController.currentBackStackEntry?.destination?.route`. This avoids potential recompositions triggered by changes in `currentBackStackEntry` that don't affect the actual route.
Copy link
Contributor

@chikoski chikoski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chikoski chikoski merged commit 5e272ed into android:main Aug 21, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants