Commit 2bdd543
authored
[web] fix context menu (#3939)
## Description
Context menu was broken on v3, this PR fixes it.
WebDelegate never handled changing contextMenu. when context had been
disabled the `areContextMenuListenersAdded` was set to true, later when
it was enabled it would not change the listener from disabled to enabled
as the `addContextMenuListeners` returned after seeing that the
listeners had already been added.
## Test plan
Tested on the following example:
<details>
```tsx
import React from 'react';
import { StyleSheet, View } from 'react-native';
import {
GestureDetector,
MouseButton,
usePanGesture,
} from 'react-native-gesture-handler';
export default function ContextMenuExample() {
const p1 = usePanGesture({ mouseButton: MouseButton.RIGHT });
const p2 = usePanGesture({});
const p3 = usePanGesture({});
return (
<View style={styles.container}>
<GestureDetector gesture={p1}>
<View style={[styles.box, styles.grandParent]}>
<GestureDetector gesture={p2} enableContextMenu={true}>
<View style={[styles.box, styles.parent]}>
<GestureDetector gesture={p3} enableContextMenu={false}>
<View style={[styles.box, styles.child]} />
</GestureDetector>
</View>
</GestureDetector>
</View>
</GestureDetector>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'space-around',
alignItems: 'center',
},
grandParent: {
width: 300,
height: 300,
backgroundColor: "navy",
},
parent: {
width: 200,
height: 200,
backgroundColor: "purple",
},
child: {
width: 100,
height: 100,
backgroundColor: "blue",
},
box: {
display: 'flex',
justifyContent: 'space-around',
alignItems: 'center',
borderRadius: 20,
},
});
```
</details>1 parent 0c130e3 commit 2bdd543
1 file changed
Lines changed: 17 additions & 5 deletions
Lines changed: 17 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
158 | 159 | | |
159 | 160 | | |
160 | 161 | | |
| 162 | + | |
161 | 163 | | |
162 | 164 | | |
163 | 165 | | |
| 166 | + | |
164 | 167 | | |
165 | 168 | | |
166 | 169 | | |
| |||
173 | 176 | | |
174 | 177 | | |
175 | 178 | | |
176 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
177 | 184 | | |
178 | 185 | | |
179 | | - | |
| 186 | + | |
180 | 187 | | |
181 | 188 | | |
182 | 189 | | |
| |||
220 | 227 | | |
221 | 228 | | |
222 | 229 | | |
223 | | - | |
224 | | - | |
225 | | - | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
226 | 236 | | |
227 | 237 | | |
| 238 | + | |
| 239 | + | |
228 | 240 | | |
229 | 241 | | |
230 | 242 | | |
| |||
0 commit comments