Skip to content

Commit 1165900

Browse files
authored
[Web] Remove mouse buttons map (#3728)
## Description This PR simplifies logic that handles `mouseButton` property. I've changed `event.button` to `event.buttons`. These values now correctly align with our `MouseButton` enum, so `Map` is no longer necessary. | Button | `event.button` | `MouseButton` | `event.buttons` | |--------|--------------|-------------|---------------| | Left | 0 | 1 | 1 | | Right | 2 | 2 | 2 | | Middle | 1 | 4 | 4 | | Btn_4 | 3 | 8 | 8 | | Btn_5 | 4 | 16 | 16 | You can find values in MDN docs for: - `event.button` [here](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button#value) - `event.buttons` [here](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons#value) > [!NOTE] > `event.buttons` also performs logical `or` operation on buttons, so for example using both **left** and **right** buttons at the same time results in value of `3`. > [!IMPORTANT] > I've tested behavior when trying to activate handler with different buttons. In case where handler has `mouseButton(MouseButton.LEFT)` clicking first with left button, then adding other button results in activation. This is fine and aligns with what we have now. Clicking with other button and then adding left button does not result in activation. This is also fine. > > Now, clicking with both buttons at the same time does not result in activation. This is because in that case there's no `pointerdown` event. Turns out that `pointerdown` is called only for the first button, all the other pointers result in `pointermove` event. In case where both are pressed at the same time, there's only `pointermove` event. ## Test plan Tested on **MouseButtons** example
1 parent 738a33c commit 1165900

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

packages/react-native-gesture-handler/src/web/tools/PointerEventManager.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import EventManager from './EventManager';
2-
import { MouseButton } from '../../handlers/gestureHandlerCommon';
32
import { AdaptedEvent, EventTypes, Point } from '../interfaces';
43
import {
54
PointerTypeMapping,
@@ -13,18 +12,11 @@ const POINTER_CAPTURE_EXCLUDE_LIST = new Set<string>(['SELECT', 'INPUT']);
1312

1413
export default class PointerEventManager extends EventManager<HTMLElement> {
1514
private trackedPointers = new Set<number>();
16-
private readonly mouseButtonsMapper = new Map<number, MouseButton>();
1715
private lastPosition: Point;
1816

1917
constructor(view: HTMLElement) {
2018
super(view);
2119

22-
this.mouseButtonsMapper.set(0, MouseButton.LEFT);
23-
this.mouseButtonsMapper.set(1, MouseButton.MIDDLE);
24-
this.mouseButtonsMapper.set(2, MouseButton.RIGHT);
25-
this.mouseButtonsMapper.set(3, MouseButton.BUTTON_4);
26-
this.mouseButtonsMapper.set(4, MouseButton.BUTTON_5);
27-
2820
this.lastPosition = {
2921
x: -Infinity,
3022
y: -Infinity,
@@ -213,7 +205,7 @@ export default class PointerEventManager extends EventManager<HTMLElement> {
213205
eventType: eventType,
214206
pointerType:
215207
PointerTypeMapping.get(event.pointerType) ?? PointerType.OTHER,
216-
button: this.mouseButtonsMapper.get(event.button),
208+
button: event.buttons,
217209
time: event.timeStamp,
218210
stylusData: tryExtractStylusData(event),
219211
};

0 commit comments

Comments
 (0)