From a7f7f8aca9eba32d490275024f7cee359cb3cfcd Mon Sep 17 00:00:00 2001 From: Vincent Riemer Date: Tue, 28 Mar 2023 16:00:20 -0700 Subject: [PATCH] Ensure Pressability doesn't forward onClick to onPress when it receives a click via pointer events (#36614) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36614 Changelog: [Internal] - Ensure Pressability doesn't forward onClick to onPress when it receives a click via pointer events. This is a better version of D43128801 which ensures that click events which are triggered by the new pointer events event emitter don't trigger onPress in Pressability — avoiding the double onPress issue while ensuring all existing usecases of onClick continue to work. Reviewed By: yungsters Differential Revision: D44031433 fbshipit-source-id: 5ecdd132f7f91338c5a3632c05510f96495b512e --- .../react-native/Libraries/Pressability/Pressability.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/react-native/Libraries/Pressability/Pressability.js b/packages/react-native/Libraries/Pressability/Pressability.js index 344bb640cf1..39c0807f343 100644 --- a/packages/react-native/Libraries/Pressability/Pressability.js +++ b/packages/react-native/Libraries/Pressability/Pressability.js @@ -547,6 +547,12 @@ export default class Pressability { }, onClick: (event: PressEvent): void => { + // If event has `pointerType`, it was emitted from a PointerEvent and + // we should ignore it to avoid triggering `onPress` twice. + if (event?.nativeEvent?.hasOwnProperty?.('pointerType')) { + return; + } + const {onPress, disabled} = this._config; if (onPress != null && disabled !== true) { onPress(event);