Skip to content

Commit 4a9bea2

Browse files
yuxizhenecolas
authored andcommitted
[fix] Pressable prevent longpress contextmenu on Windows
Long-press with a touch on a Pressable does not suppress the contextmenu on Windows. On iOS and Android, the contextmenu is triggered while the pointer is down, after a certain length of time. However, on Windows, the contextmenu is displayed after pointerup (with the same timestamp as pointerup), whether triggered by a mouse right-click or a touch long-press. Fix #2296 Close #2316
1 parent 07feddf commit 4a9bea2

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/react-native-web-examples/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@
1414
"react-dom": "^17.0.2",
1515
"react-native-web": "0.18.6"
1616
},
17+
"devDependencies": {
18+
"@babel/core": "^7.18.6",
19+
"@babel/preset-flow": "^7.18.6"
20+
},
1721
"license": "MIT"
1822
}

packages/react-native-web/src/modules/usePressEvents/PressResponder.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,12 @@ export default class PressResponder {
482482
event: ResponderEvent
483483
): void {
484484
if (isTerminalSignal(signal)) {
485-
this._isPointerTouch = false;
485+
// Pressable suppression of contextmenu on windows.
486+
// On Windows, the contextmenu is displayed after pointerup.
487+
// https://github.com/necolas/react-native-web/issues/2296
488+
setTimeout(() => {
489+
this._isPointerTouch = false;
490+
}, 0);
486491
this._touchActivatePosition = null;
487492
this._cancelLongPressDelayTimeout();
488493
}

0 commit comments

Comments
 (0)