[Web] GestureDetector blocks context menu by default
I maintainer di solito rispondono entro 2 giorni
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 56/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- react-native, typescript
Direzione di ricerca
Start in web/handlers/GestureHandler.ts and v3/detectors/HostGestureDetector.web.tsx, where the issue identifies the context menu defaults and reset path. Compare those paths with GestureHandlerWebDelegate.shouldDisableContextMenu and the v2 behavior described here. Add or update web tests for native context menus and onContextMenu propagation; done means the native menu is suppressed only for an explicit false setting or a gesture using MouseButton.RIGHT.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
Since v3, every gesture handler on web blocks the browser's native context menu by default. Right-clicking anywhere inside a GestureDetector or an RNGH component (ScrollView, FlatList, Pressable, …) no longer opens the browser menu, even when the gesture doesn't use the right mouse button.
This worked in v2 (tested with 2.25.0). There, the native menu was only suppressed for gestures listening to MouseButton.RIGHT or with an explicit enableContextMenu={false}.
Why this is a problem
In a real app, whole screens will be wrapped in RNGH components (ScrollView, FlatList). contextmenu bubbles, and one preventDefault() on any ancestor cancels the browser menu. So a single default-configured handler anywhere above an element is enough to block it.
To use the native context menu or onContextMenu in an RNGH app, I now have to add enableContextMenu to every RNGH component that may contain an element with a context menu. That means nearly every GestureDetector, ScrollView and list in the app, plus third-party libraries built on RNGH that may not expose the prop. Missing one ancestor breaks it again.
enableContextMenu={true} is also not equivalent to the v2 default. It attaches a listener that calls e.stopPropagation(), so the event never reaches ancestors, including React's root listener, and onContextMenu handlers higher in the tree stop firing. In v2 the default (undefined) attached no listener at all, so both the native menu and onContextMenu worked without any extra props.
Root cause
GestureHandlerWebDelegate still uses the v2 check:
private shouldDisableContextMenu() {
return (
(this.gestureHandler.enableContextMenu === undefined &&
this.gestureHandler.isButtonInConfig(MouseButton.RIGHT)) ||
this.gestureHandler.enableContextMenu === false
);
}
In v3, enableContextMenu can no longer be undefined, so the first branch is dead and the second always matches:
web/handlers/GestureHandler.ts:private _enableContextMenu: boolean = false. It is only overwritten when the config value is notundefined, and the reset path sets it back tofalse.v3/detectors/HostGestureDetector.web.tsx→unpackDOMProps:source.enableContextMenu ?? DEFAULT_ENABLE_CONTEXT_MENU, whereDEFAULT_ENABLE_CONTEXT_MENU = false.
Expected
Same as v2: only suppress the native menu when enableContextMenu={false} is passed explicitly or the gesture listens to MouseButton.RIGHT.
Steps to reproduce
-
Render on web:
import { GestureHandlerRootView, ScrollView } from 'react-native-gesture-handler'; import { Text } from 'react-native'; export default function App() { return ( <GestureHandlerRootView style={{ flex: 1 }}> <ScrollView> <Text onContextMenu={() => console.log('onContextMenu')}> Right-click me </Text> </ScrollView> </GestureHandlerRootView> ); } -
Right-click the text.
-
With 3.4.0: no browser context menu appears.
-
Switch to 2.25.0 and repeat: the browser context menu opens.
A link to a Gist, an Expo Snack or a link to a repository based on this template that reproduces the bug.
Gesture Handler version
3.5.0
React Native version
0.86.0
Platforms
Web
JavaScript runtime
None
Workflow
None
Build type
None
Device
None
Device model
No response
Acknowledgements
Yes
- Lingua principale
- TypeScript
- Stelle
- 6.8k
- Fork
- 1.1k
- Merge medio
- 1g 23h
- PR unite (30g)
- 46
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di software-mansion/react-native-gesture-handler
-
[Jest][3.5.0] `fireEvent.press` no longer reaches `Touchable` when its child is inside an `InterceptingGestureDetector`Forse già presa @m-bert l’ha presa 3 giorni fa. ApertaMissing info Platform: Web
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
software-mansion/react-native-gesture-handler#4689 · 4 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
[Android] v3 `ReanimatedSwipeable` takes over a vertical scroll in a React Native list once the finger drifts 10 dp sidewaysForse di nuovo libera @JaydeepAgravat l’ha presa 10 giorni fa e non c’è nessuna pull request aperta. ApertaPlatform: Android
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
software-mansion/react-native-gesture-handler#4670 · 6 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
Jest: with the hook API, raw touch events fired under a `GestureDetector` don't reach ancestors under Testing Library 14Forse di nuovo libera @aliassar l’ha presa 13 giorni fa e non c’è nessuna pull request aperta. ApertaPlatform: Android Platform: iOS
Difficoltà 3/5 1-2 giorni Idoneità per principianti 66/100
software-mansion/react-native-gesture-handler#4656 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
[Android] A held tap on a Touchable or Pressable in ScrollView does nothing while the keyboard is upForse già presa @m-bert l’ha presa 6 giorni fa. ApertaMissing repro Platform: Android
Difficoltà 4/5 3-5 giorni Idoneità per principianti 50/100
software-mansion/react-native-gesture-handler#4653 · 7 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
[IOS] The "hitslop" attribute used in the packaging component FlatList does not work as expected.ApertaClose when stale Missing repro Platform: iOS
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
software-mansion/react-native-gesture-handler#4649 · 2 commenti ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di software-mansion/react-native-gesture-handler
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
pollen-robotics/reachy-mini-desktop-app#341 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
mike-north/AgentMonitors#648 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
vercel-labs/ui#700 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 2 giorni