mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Ensure Pressability doesn't forward onClick to onPress when it receives a click via pointer events (#36614)
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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
eaf8f8a161
commit
a7f7f8aca9
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user