-
Notifications
You must be signed in to change notification settings - Fork 386
Fix: Topbar navigation recomposition #212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Topbar navigation recomposition #212
Conversation
There was a problem hiding this 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
-
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. ↩
There was a problem hiding this 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.
| 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 | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
chikoski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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
After (fixed behavior):
Screen_recording_20250820_162752.mp4
Changes Introduced
DashboardScreento compare the current route with the target route before callingnavController.navigate().DashboardTopBarso thatonFocusandonClickevents only trigger navigation if the selected tab is different from the current one.Benefits