Skip to content

Commit 291f26c

Browse files
vincentriemerfacebook-github-bot
authored andcommitted
Fill out w3c pointer event types
Summary: Changelog: [Internal] Fill out w3c PointerEvent flow types Reviewed By: yungsters Differential Revision: D36296044 fbshipit-source-id: f1c184fd6486fa72077e5b80d2335919af0fc145
1 parent ca8174e commit 291f26c

2 files changed

Lines changed: 131 additions & 15 deletions

File tree

Libraries/Pressability/Pressability.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -935,16 +935,15 @@ const getTouchFromPressEvent = (event: PressEvent) => {
935935
};
936936

937937
function convertPointerEventToMouseEvent(input: PointerEvent): MouseEvent {
938-
const {touchHistory: _, ...synthEvent} = input;
939-
const {clientX, clientY, timestamp} = input.nativeEvent;
938+
const {clientX, clientY} = input.nativeEvent;
940939
return {
941-
...synthEvent,
940+
...input,
942941
nativeEvent: {
943942
clientX,
944943
clientY,
945944
pageX: clientX,
946945
pageY: clientY,
947-
timestamp,
946+
timestamp: input.timeStamp,
948947
},
949948
};
950949
}

Libraries/Types/CoreEventTypes.js

Lines changed: 128 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,134 @@ export type TextLayoutEvent = SyntheticEvent<
8383
|}>,
8484
>;
8585

86-
export type PointerEvent = ResponderSyntheticEvent<
87-
$ReadOnly<{|
88-
pointerId: number,
89-
pressure: number,
90-
pointerType: string,
91-
clientX: number,
92-
clientY: number,
93-
target: ?number,
94-
timestamp: number,
95-
|}>,
96-
>;
86+
/**
87+
* https://developer.mozilla.org/en-US/docs/Web/API/UIEvent
88+
*/
89+
export interface NativeUIEvent {
90+
/**
91+
* Returns a long with details about the event, depending on the event type.
92+
*/
93+
+detail: number;
94+
}
95+
96+
/**
97+
* https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
98+
*/
99+
export interface NativeMouseEvent extends NativeUIEvent {
100+
/**
101+
* The X coordinate of the mouse pointer in global (screen) coordinates.
102+
*/
103+
+screenX: number;
104+
/**
105+
* The Y coordinate of the mouse pointer in global (screen) coordinates.
106+
*/
107+
+screenY: number;
108+
/**
109+
* The X coordinate of the mouse pointer relative to the whole document.
110+
*/
111+
+pageX: number;
112+
/**
113+
* The Y coordinate of the mouse pointer relative to the whole document.
114+
*/
115+
+pageY: number;
116+
/**
117+
* The X coordinate of the mouse pointer in local (DOM content) coordinates.
118+
*/
119+
+clientX: number;
120+
/**
121+
* The Y coordinate of the mouse pointer in local (DOM content) coordinates.
122+
*/
123+
+clientY: number;
124+
/**
125+
* Alias for NativeMouseEvent.clientX
126+
*/
127+
+x: number;
128+
/**
129+
* Alias for NativeMouseEvent.clientY
130+
*/
131+
+y: number;
132+
/**
133+
* Returns true if the control key was down when the mouse event was fired.
134+
*/
135+
+ctrlKey: boolean;
136+
/**
137+
* Returns true if the shift key was down when the mouse event was fired.
138+
*/
139+
+shiftKey: boolean;
140+
/**
141+
* Returns true if the alt key was down when the mouse event was fired.
142+
*/
143+
+altKey: boolean;
144+
/**
145+
* Returns true if the meta key was down when the mouse event was fired.
146+
*/
147+
+metaKey: boolean;
148+
/**
149+
* The button number that was pressed (if applicable) when the mouse event was fired.
150+
*/
151+
+button: number;
152+
/**
153+
* The buttons being depressed (if any) when the mouse event was fired.
154+
*/
155+
+buttons: number;
156+
/**
157+
* The secondary target for the event, if there is one.
158+
*/
159+
+relatedTarget: null | number | React.ElementRef<HostComponent<mixed>>;
160+
}
161+
162+
/**
163+
* https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent
164+
*/
165+
export interface NativePointerEvent extends NativeMouseEvent {
166+
/**
167+
* A unique identifier for the pointer causing the event.
168+
*/
169+
+pointerId: number;
170+
/**
171+
* The width (magnitude on the X axis), in CSS pixels, of the contact geometry of the pointer
172+
*/
173+
+width: number;
174+
/**
175+
* The height (magnitude on the Y axis), in CSS pixels, of the contact geometry of the pointer.
176+
*/
177+
+height: number;
178+
/**
179+
* The normalized pressure of the pointer input in the range 0 to 1, where 0 and 1 represent
180+
* the minimum and maximum pressure the hardware is capable of detecting, respectively.
181+
*/
182+
+pressure: number;
183+
/**
184+
* The normalized tangential pressure of the pointer input (also known as barrel pressure or
185+
* cylinder stress) in the range -1 to 1, where 0 is the neutral position of the control.
186+
*/
187+
+tangentialPressure: number;
188+
/**
189+
* The plane angle (in degrees, in the range of -90 to 90) between the Y–Z plane and the plane
190+
* containing both the pointer (e.g. pen stylus) axis and the Y axis.
191+
*/
192+
+tiltX: number;
193+
/**
194+
* The plane angle (in degrees, in the range of -90 to 90) between the X–Z plane and the plane
195+
* containing both the pointer (e.g. pen stylus) axis and the X axis.
196+
*/
197+
+tiltY: number;
198+
/**
199+
* The clockwise rotation of the pointer (e.g. pen stylus) around its major axis in degrees,
200+
* with a value in the range 0 to 359.
201+
*/
202+
+twist: number;
203+
/**
204+
* Indicates the device type that caused the event (mouse, pen, touch, etc.)
205+
*/
206+
+pointerType: string;
207+
/**
208+
* Indicates if the pointer represents the primary pointer of this pointer type.
209+
*/
210+
+isPrimary: boolean;
211+
}
212+
213+
export type PointerEvent = SyntheticEvent<NativePointerEvent>;
97214

98215
export type PressEvent = ResponderSyntheticEvent<
99216
$ReadOnly<{|

0 commit comments

Comments
 (0)