Skip to content

Conversation

@grahammendick
Copy link
Contributor

Summary:

When onBackPressed was migrated to OnBackPressedCallback react native lost the predictive back animation when exiting an app. This PR aims to restore the predictive back animation for apps that support predictive back (it's not reasonable to try and bring this back for all apps). Apps that support predictive back, for example, those that use the Navigation router, can disable the callback in their Activity.

getBackPressedCallback().setEnabled(false);

Expected behavior (and before the migration)

Screen.Recording.2026-01-16.at.17.04.02.mov

Current behavior

Screen.Recording.2026-01-16.at.17.04.58.mov

Changelog:

[ANDROID] [FIXED] - Support predictive back animation when exiting app

Test Plan:

Here is the the Navigation router sample running with the callback disabled

Screen.Recording.2026-01-16.at.17.14.05.mov

This callback prevents the predictive back animation when exiting the app. Apps that use predictive back can disable the callback to restore the exiting animation
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 16, 2026
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jan 16, 2026
The callback might've been manually disabled, in which case want to leave it disabled
@philIip philIip requested a review from alanleedev January 18, 2026 05:19
@alanleedev
Copy link
Contributor

@grahammendick Thanks for raising the issue. Can you add a bit more detail about what the code does and also how this relates to Navigation router? I'm not sure if I have a clear understanding about this.
I do see that mBackPressedCallback.setEnabled(enabled); fixes a potential bug where we can enable the callback which was not used.

@grahammendick
Copy link
Contributor Author

@alanleedev Thanks for the response 🙏

This issue impacts any navigation library for React Native that supports the predictive back gesture on Android. As far as I'm aware, my Navigation router is the only one that currently does, which is why I mention it. But when React Native Screens adds support then they'll also face this same issue.

When I say "supports the predictive back gesture" I mean that the back is handled by the native side running an animation as the gesture progresses. You can take a look at my twitter sample to see it working.

The predictive back animation runs perfectly when the back stays within the app because this is handled by my Navigation router (using the in-built predictive back support provided by the Android FragmentManager). But the animation doesn't run when the back exits the app because of the React Native onBackPressedCallback. Android sees there's an enabled callback so doesn't run the "exit app" animation.

It's important for the animation to run otherwise we go back to the bad old days of users accidentally exiting the app when they didn't mean to.

I mention in the summary that it's not reasonable to bring the "exit app" gesture animation back for navigation libraries that don't support the predictive back gesture. That would involve a significant rewrite where the onBackPressedCallback would run ahead of time and disable itself if there's no back to perform.

But allowing React Native's onBackPressedCallback to be disabled would bring the "exit app" animation back for all apps that support predictive back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants