From 61eb9b4453c96d3dc662319c9c9f322bf04d1d44 Mon Sep 17 00:00:00 2001 From: Alex Danoff Date: Thu, 25 May 2023 09:39:53 -0700 Subject: [PATCH] W3CPointerEvents: change click event from direct to bubbling (#37539) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/37539 AFAICT this was added in https://github.com/facebook/react-native/pull/24359 to support accessibility, however per [the spec](https://www.w3.org/TR/uievents/#event-type-click) the click event is supposed to bubble up. This change updates the necessary configs so that `click` is treated as a bubbling event and not as a direct-dispatch event. Changelog: [Android] [Breaking] - W3CPointerEvents: change click event from direct to bubbling Reviewed By: yungsters Differential Revision: D45745906 fbshipit-source-id: 2649375b322037fe7ab20b800daae150640dbede --- .../Libraries/NativeComponent/BaseViewConfig.android.js | 9 ++++++--- .../com/facebook/react/uimanager/BaseViewManager.java | 5 +++++ .../react/uimanager/UIManagerModuleConstants.java | 1 - 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/react-native/Libraries/NativeComponent/BaseViewConfig.android.js b/packages/react-native/Libraries/NativeComponent/BaseViewConfig.android.js index fef57a1aea9a91..f0dfd8d6628105 100644 --- a/packages/react-native/Libraries/NativeComponent/BaseViewConfig.android.js +++ b/packages/react-native/Libraries/NativeComponent/BaseViewConfig.android.js @@ -103,6 +103,12 @@ const bubblingEventTypes = { bubbled: 'onPointerOver', }, }, + topClick: { + phasedRegistrationNames: { + captured: 'onClickCapture', + bubbled: 'onClick', + }, + }, }; const directEventTypes = { @@ -135,9 +141,6 @@ const directEventTypes = { topMomentumScrollEnd: { registrationName: 'onMomentumScrollEnd', }, - topClick: { - registrationName: 'onClick', - }, topLoadingStart: { registrationName: 'onLoadingStart', }, diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java index b8f10af4da9e2c..dc0828689db368 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java @@ -588,6 +588,11 @@ protected void onAfterUpdateTransaction(@NonNull T view) { MapBuilder.of( "phasedRegistrationNames", MapBuilder.of("bubbled", "onPointerOver", "captured", "onPointerOverCapture"))) + .put( + "topClick", + MapBuilder.of( + "phasedRegistrationNames", + MapBuilder.of("bubbled", "onClick", "captured", "onClickCapture"))) .build()); return eventTypeConstants; } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModuleConstants.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModuleConstants.java index fdac6f30858aea..ee4f7969235a01 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModuleConstants.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModuleConstants.java @@ -64,7 +64,6 @@ .put("topLoadingStart", MapBuilder.of(rn, "onLoadingStart")) .put("topSelectionChange", MapBuilder.of(rn, "onSelectionChange")) .put("topMessage", MapBuilder.of(rn, "onMessage")) - .put("topClick", MapBuilder.of(rn, "onClick")) // Scroll events are added as per task T22348735. // Subject for further improvement. .put("topScrollBeginDrag", MapBuilder.of(rn, "onScrollBeginDrag"))