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.

@kkafar
Copy link
Contributor

kkafar commented Jan 29, 2026

[...] But when React Native Screens adds support then they'll also face this same issue.

Bulls eye! Exactly, we're working on new stack implementation right now and we run in react-native-screens into exactly the same problem as @grahammendick does.

Our issue is even more severe as we use the supportFragmentManager directly, and having this callback prevents the predictiveBackGesture on fragment manager level (not really sure yet why it happens exactly, digging into it). I'm sure we can workaround that, however the issue with predictive back gesture between activity and launcher screen remains.

I'd be great to be able to disable the OnBackPressedCallback registered on ReactActivity and handle the back gesture on our end. It can be disabled either dynamically in runtime or by option in gradle.properties -> we do not mind.

It might make sense to disable it through gradle.properties though, so we're able to throw nice error in case somebody uses BackHandler and disables the back gesture handling in gradle.properties, since I assume this API would stop working then.

Approach with gradle.properties is less flexible though & would require action from user-end, which is less than ideal.

Happy to discuss more here.

@grahammendick
Copy link
Contributor Author

It might make sense to disable it through gradle.properties though, so we're able to throw nice error in case somebody uses BackHandler and disables the back gesture handling in gradle.properties

I don't think you want to throw in this scenario. For example, a 3rd party Tab library might use BackHandler to go back to the first tab but the app itself is using predictive back so disables the callback.

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.

4 participants