Repository navigation
Grzegorzkruk/predictive back swipe - #59292
grzegorzkruk wants to merge 13 commits into
Conversation
|
Hi @grzegorzkruk! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Warning JavaScript API change detected This PR commits an update to
This change was flagged as: |
…n ReactActivity Summary: - Added new methods to `ReactActivity` to improve back navigation handling on Android API 36 and above, including `getBackPressedCallback()` and `onSystemNavigationBackInvoked()`. - Introduced a `SystemNavigationBackObserver` to manage system back navigation events. - Added unit tests for the new back navigation functionality in `ReactActivityBackPressedCallbackTest.kt`. - Updated `RNTesterActivity` to allow system predictive-back animations while still notifying JS on app exit. Changelog: [GENERAL][CHANGED] - Enhanced back navigation handling and updated hermes-compiler version. Test Plan: - Verified back navigation functionality on Android API 36+. - Ensured that the updated hermes-compiler works without issues in the project.
…ation handling Summary: - Introduced `setInterceptEnabled(enabled: boolean)` method to `BackHandler` for Android, allowing React Native to manage back gesture interception. - Updated `ReactActivity` to handle predictive back animations on Android 16+. - Enhanced type definitions in TypeScript and Flow to include the new method. - Added unit tests to verify the functionality of the new back navigation feature. Changelog: [GENERAL][CHANGED] - Enhanced back navigation handling with new interception capabilities.
Summary: - Introduced `PredictiveBackAnimatedView` and related types for handling predictive back gestures in React Native. - Enhanced `BackHandler` to support predictive back events, allowing developers to listen for gesture phases and progress. - Updated `ReactActivity` to manage predictive back handlers and events, improving back navigation experience on Android. - Added unit tests to validate the new predictive back functionality and ensure proper event handling. Changelog: [GENERAL][ADDED] - Support for predictive back navigation in BackHandler and ReactActivity.
Summary: - Introduced `PredictiveBackAnimatedView` for handling predictive back gestures on Android. - Added `usePredictiveBackAnimatedValue` hook to facilitate animated responses to back gesture progress. - Updated type definitions and flow types to include new predictive back event types and properties. - Enhanced `ReactActivity` to manage predictive back progress listeners without consuming the gesture. - Added unit tests to validate the new predictive back functionality. Changelog: [GENERAL][ADDED] - Support for predictive back navigation with new components and hooks.
Summary: - Updated `BackHandler` and `ReactActivity` to improve predictive back gesture handling on Android. - Removed deprecated `PREDICTIVE_BACK_FRONT_PANE_NATIVE_ID` and adjusted related logic to streamline predictive back animations. - Enhanced type definitions to reflect changes in predictive back event handling. - Updated `RNTesterApp` and Playground example to demonstrate new predictive back functionality without the deprecated ID. - Cleaned up unit tests to align with the new implementation. Changelog: [GENERAL][CHANGED] - Improved predictive back navigation handling and removed deprecated identifiers.
…functionality Summary: - Removed `usePredictiveBackAnimatedValue` hook and related predictive back event types from `BackHandler` and `ReactActivity`. - Updated `PredictiveBackAnimatedView` to streamline predictive back gesture handling. - Adjusted type definitions and flow types to reflect the removal of deprecated predictive back features. - Cleaned up related tests and examples to align with the new implementation. Changelog: [GENERAL][REMOVED] - Deprecated predictive back functionality and related types.
Summary: - Introduced `claimPredictiveBack` method to `BackHandler` for managing back gesture ownership in overlays. - Updated `ReactActivity` to support predictive back claims, allowing for better control over back gesture handling. - Enhanced type definitions to include new methods and properties related to predictive back functionality. - Added unit tests to validate the new predictive back behavior and ensure proper event handling. Changelog: [GENERAL][ADDED] - Support for predictive back gesture management in BackHandler and ReactActivity.
Summary: - Removed `claimPredictiveBack` method from `BackHandler` and related files to streamline back gesture management. - Updated type definitions and interfaces to reflect the removal of predictive back claims. - Cleaned up associated tests and mocks to ensure consistency with the new implementation. Changelog: [GENERAL][REMOVED] - Deprecated predictive back claim functionality from BackHandler and related components.
Summary: - Introduced a RCP file detailing the predictive back gesture support in React Native applications. Changelog: [GENERAL][ADDED] - RCP for predictive back gesture support in React Native.
2edf75f to
651de61
Compare
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary:
On Android 16+ with
targetSdk36, Android turns on predictive back by default and no longer callsActivity.onBackPressed(). To keepBackHandlerworking, #51096 added anOnBackPressedCallbacktoReactActivitythat is always enabled.An enabled callback tells Android "this app handles back itself". So Android never plays its predictive back animation (back to home, back to the previous activity), and
FragmentManagernever receives the swipe. Every React Native app targeting SDK 36 is quietly opted out of predictive back, even apps that never useBackHandler. Native navigation libraries (react-native-screens) and brownfield hosts have to fight this callback, often with reflection.Related RCP
This PR implements the first part of the RCP "Predictive back gesture support in React Native applications".
The RCP proposes that React Native work with Android's back model instead of against it. React Native takes back only when JavaScript says, ahead of time, that it has something to go back to; otherwise Android handles back and plays its animation.
BackHandlerkeeps its API but has smaller guarantees on Android: it's off by default, and native code can override it.targetSdk36+)BackHandler.setInterceptEnabled(enabled), a preference and not a guaranteeReactActivity.getBackPressedCallback()for native libraries and brownfield hostsPRIORITY_SYSTEM_NAVIGATION_OBSERVERsetInterceptEnabledreaching the calling surface's activity (brownfield)The RCP is based on research in a brownfield demo app built on react-native-brownfield (native screen → React Native screen → native screen with an embedded React Native fragment). The research also looked at an observer-only alternative and rejected it as a replacement for
BackHandler: an observer can't block back, works only on Android 16+, allows one per window on Android 16, and fires after the activity has already closed.What this PR changes
BackHandler.setInterceptEnabled(enabled)(Android; a no-op on iOS). JavaScript turns it on while it has something to go back to, for example a pushed JS screen or an open modal. While it's on,hardwareBackPresslisteners run as before, includingreturn trueto block back, and the system animation doesn't play. While it's off, Android handles back. It goes through a newsetInterceptEnabledmethod on the existingDeviceEventManagerTurboModule spec. This is a preference, not a guarantee: a callback that native code enables later still wins.ReactActivity.getBackPressedCallback()for native libraries and brownfield hosts that need to own back, so they no longer need reflection.invokeDefaultOnBackPressed()restores the previous enabled state instead of always re-enabling the callback. OtherwiseBackHandler.exitApp()would turn interception on, and re-enable a callback that a navigation library had disabled.Below
targetSdk36 nothing changes: the callback is never added to the dispatcher, andhardwareBackPressis delivered as before.Behaviour change. On
targetSdk36, apps that rely onhardwareBackPressmust opt in:yarn build-types # regenerates ReactNativeApi.d.ts
./gradlew :packages:react-native:ReactAndroid:compileDebugKotlin
./gradlew :packages:react-native:ReactAndroid:compileDebugJavaWithJavac
./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest
--tests "com.facebook.react.ReactActivityBackInterceptionTest"
./gradlew :packages:react-native:ReactAndroid:ktfmtCheck
npx eslint --max-warnings 0
npx prettier --check
yarn test packages/react-native/Libraries/LogBox/tests # BackHandler mock consumers