Skip to content

Commit 4218d51

Browse files
Saadnajmiclaude
andcommitted
Filter non-primary button from onPress/onLongPress in responder path
Match react-native-windows approach: add _isDefaultPressButton() helper and use it in all three press paths (onClick, LONG_PRESS_DETECTED, and RESPONDER_RELEASE). The button property is already forwarded from native macOS touch events via BaseTouch. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a750192 commit 4218d51

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

packages/react-native/Libraries/Pressability/Pressability.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,16 @@ export default class Pressability {
410410
_touchActivateTime: ?number;
411411
_touchState: TouchState = 'NOT_RESPONDER';
412412

413+
// [macOS
414+
/**
415+
* Returns true if the button from a press event is the default (primary/left)
416+
* button. A button value of 0 or undefined is considered the default button.
417+
*/
418+
_isDefaultPressButton(button: ?number): boolean {
419+
return !button;
420+
}
421+
// macOS]
422+
413423
constructor(config: PressabilityConfig) {
414424
this.configure(config);
415425
}
@@ -556,8 +566,7 @@ export default class Pressability {
556566

557567
// [macOS Only fire onPress for primary (left) mouse button clicks.
558568
// Non-primary buttons (right, middle) should not trigger onPress.
559-
const button = event?.nativeEvent?.button;
560-
if (button != null && button !== 0) {
569+
if (!this._isDefaultPressButton(event?.nativeEvent?.button)) {
561570
return;
562571
}
563572
// macOS]
@@ -799,7 +808,12 @@ export default class Pressability {
799808

800809
if (isPressInSignal(prevState) && signal === 'LONG_PRESS_DETECTED') {
801810
const {onLongPress} = this._config;
802-
if (onLongPress != null) {
811+
if (
812+
onLongPress != null &&
813+
this._isDefaultPressButton(
814+
getTouchFromPressEvent(event).button,
815+
) /* [macOS] */
816+
) {
803817
onLongPress(event);
804818
}
805819
}
@@ -820,7 +834,12 @@ export default class Pressability {
820834
this._deactivate(event);
821835
}
822836
const {onLongPress, onPress, android_disableSound} = this._config;
823-
if (onPress != null) {
837+
if (
838+
onPress != null &&
839+
this._isDefaultPressButton(
840+
getTouchFromPressEvent(event).button,
841+
) /* [macOS] */
842+
) {
824843
const isPressCanceledByLongPress =
825844
onLongPress != null && prevState === 'RESPONDER_ACTIVE_LONG_PRESS_IN';
826845
if (!isPressCanceledByLongPress) {

0 commit comments

Comments
 (0)