Skip to content

Fix double back navigation with react-native-screens#595

Merged
guytepper merged 1 commit intomainfrom
claude/fix-android-back-gesture-fQSuL
Mar 6, 2026
Merged

Fix double back navigation with react-native-screens#595
guytepper merged 1 commit intomainfrom
claude/fix-android-back-gesture-fQSuL

Conversation

@guytepper
Copy link
Member

Summary

Fixed an issue where the back button handler was calling goBack() in addition to the native back navigation handling provided by react-native-screens, causing two screens to be popped instead of one.

Changes

  • Removed the explicit navigation.canGoBack() check and navigation.goBack() call from the back button handler
  • Updated the handler to return true unconditionally to prevent app exit, while allowing react-native-screens to handle the actual back navigation natively
  • Updated comments to clarify that react-native-screens handles back navigation for both hardware button and predictive back gesture

Implementation Details

The react-native-screens library already provides native back navigation handling for both the hardware back button and the predictive back gesture. By calling goBack() explicitly in addition to this native handling, the app was popping two screens instead of one. The fix removes the redundant navigation call and relies solely on the native implementation, while still returning true to prevent the app from exiting when at the root of the navigation stack.

https://claude.ai/code/session_01Enpeyb1LdLj6yJ8wG85jaw

With RN 0.81 targeting Android 16, predictive back is enabled by
default. react-native-screens handles back navigation natively for
both the hardware button and gestures. The custom BackHandler was
also calling goBack(), causing a double-pop on formSheet screens
like the train info sheet.

Remove the redundant goBack() call — the handler now only prevents
the app from exiting when not on an exit route.

https://claude.ai/code/session_01Enpeyb1LdLj6yJ8wG85jaw
@gemini-code-assist
Copy link

Summary of Changes

Hello, 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 where the application was performing a double back navigation, causing an unexpected user experience. The fix streamlines the back button handling by removing a redundant goBack() call, allowing the react-native-screens library to exclusively manage native back navigation. This ensures that only one screen is popped at a time, improving navigation consistency and user flow.

Highlights

  • Redundant Navigation Call Removed: Eliminated the explicit navigation.goBack() call from the back button handler, which was causing two screens to be popped instead of one due to react-native-screens' native handling.
  • Back Button Handler Logic Updated: Modified the back button handler to unconditionally return true to prevent the app from exiting, while relying solely on react-native-screens for actual back navigation.
  • Code Comments Clarified: Updated comments to clearly state that react-native-screens manages back navigation for both hardware buttons and predictive back gestures.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • app/navigators/navigation-utilities.tsx
    • Removed the conditional navigation.canGoBack() check and subsequent navigation.goBack() call.
    • Changed the back button handler to always return true to prevent app exit.
    • Added new comments explaining the role of react-native-screens in handling native back navigation.
Activity
  • No human activity has been recorded on this pull request yet.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 addresses a double back navigation issue when using react-native-screens. The change correctly removes the manual navigation.goBack() call from the useBackButtonHandler hook, relying on the native back navigation provided by the library. This fixes the bug where two screens were popped instead of one. Additionally, by returning true for non-exit routes, the change prevents the app from closing unexpectedly when the back button is pressed at the root of a navigation stack, which is a good improvement to the user experience. The code is now simpler and the new comments clearly explain the rationale. The implementation looks solid.

@guytepper guytepper merged commit 379175e into main Mar 6, 2026
3 checks passed
@guytepper guytepper deleted the claude/fix-android-back-gesture-fQSuL branch March 6, 2026 15:23
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