Fix double back navigation with react-native-screens#595
Conversation
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
Summary of ChangesHello, 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 Highlights
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
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
navigation.canGoBack()check andnavigation.goBack()call from the back button handlertrueunconditionally to prevent app exit, while allowing react-native-screens to handle the actual back navigation nativelyImplementation 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 returningtrueto prevent the app from exiting when at the root of the navigation stack.https://claude.ai/code/session_01Enpeyb1LdLj6yJ8wG85jaw