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
This commit is contained in:
Vincent Riemer 2022-05-19 18:48:24 -07:00 коммит произвёл Facebook GitHub Bot
Родитель ca8174e15f
Коммит 291f26c5c0
2 изменённых файлов: 131 добавлений и 15 удалений

Просмотреть файл

@ -935,16 +935,15 @@ const getTouchFromPressEvent = (event: PressEvent) => {
};
function convertPointerEventToMouseEvent(input: PointerEvent): MouseEvent {
const {touchHistory: _, ...synthEvent} = input;
const {clientX, clientY, timestamp} = input.nativeEvent;
const {clientX, clientY} = input.nativeEvent;
return {
...synthEvent,
...input,
nativeEvent: {
clientX,
clientY,
pageX: clientX,
pageY: clientY,
timestamp,
timestamp: input.timeStamp,
},
};
}

Просмотреть файл

@ -83,17 +83,134 @@ export type TextLayoutEvent = SyntheticEvent<
|}>,
>;
export type PointerEvent = ResponderSyntheticEvent<
$ReadOnly<{|
pointerId: number,
pressure: number,
pointerType: string,
clientX: number,
clientY: number,
target: ?number,
timestamp: number,
|}>,
>;
/**
* https://developer.mozilla.org/en-US/docs/Web/API/UIEvent
*/
export interface NativeUIEvent {
/**
* Returns a long with details about the event, depending on the event type.
*/
+detail: number;
}
/**
* https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
*/
export interface NativeMouseEvent extends NativeUIEvent {
/**
* The X coordinate of the mouse pointer in global (screen) coordinates.
*/
+screenX: number;
/**
* The Y coordinate of the mouse pointer in global (screen) coordinates.
*/
+screenY: number;
/**
* The X coordinate of the mouse pointer relative to the whole document.
*/
+pageX: number;
/**
* The Y coordinate of the mouse pointer relative to the whole document.
*/
+pageY: number;
/**
* The X coordinate of the mouse pointer in local (DOM content) coordinates.
*/
+clientX: number;
/**
* The Y coordinate of the mouse pointer in local (DOM content) coordinates.
*/
+clientY: number;
/**
* Alias for NativeMouseEvent.clientX
*/
+x: number;
/**
* Alias for NativeMouseEvent.clientY
*/
+y: number;
/**
* Returns true if the control key was down when the mouse event was fired.
*/
+ctrlKey: boolean;
/**
* Returns true if the shift key was down when the mouse event was fired.
*/
+shiftKey: boolean;
/**
* Returns true if the alt key was down when the mouse event was fired.
*/
+altKey: boolean;
/**
* Returns true if the meta key was down when the mouse event was fired.
*/
+metaKey: boolean;
/**
* The button number that was pressed (if applicable) when the mouse event was fired.
*/
+button: number;
/**
* The buttons being depressed (if any) when the mouse event was fired.
*/
+buttons: number;
/**
* The secondary target for the event, if there is one.
*/
+relatedTarget: null | number | React.ElementRef<HostComponent<mixed>>;
}
/**
* https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent
*/
export interface NativePointerEvent extends NativeMouseEvent {
/**
* A unique identifier for the pointer causing the event.
*/
+pointerId: number;
/**
* The width (magnitude on the X axis), in CSS pixels, of the contact geometry of the pointer
*/
+width: number;
/**
* The height (magnitude on the Y axis), in CSS pixels, of the contact geometry of the pointer.
*/
+height: number;
/**
* The normalized pressure of the pointer input in the range 0 to 1, where 0 and 1 represent
* the minimum and maximum pressure the hardware is capable of detecting, respectively.
*/
+pressure: number;
/**
* The normalized tangential pressure of the pointer input (also known as barrel pressure or
* cylinder stress) in the range -1 to 1, where 0 is the neutral position of the control.
*/
+tangentialPressure: number;
/**
* The plane angle (in degrees, in the range of -90 to 90) between the YZ plane and the plane
* containing both the pointer (e.g. pen stylus) axis and the Y axis.
*/
+tiltX: number;
/**
* The plane angle (in degrees, in the range of -90 to 90) between the XZ plane and the plane
* containing both the pointer (e.g. pen stylus) axis and the X axis.
*/
+tiltY: number;
/**
* The clockwise rotation of the pointer (e.g. pen stylus) around its major axis in degrees,
* with a value in the range 0 to 359.
*/
+twist: number;
/**
* Indicates the device type that caused the event (mouse, pen, touch, etc.)
*/
+pointerType: string;
/**
* Indicates if the pointer represents the primary pointer of this pointer type.
*/
+isPrimary: boolean;
}
export type PointerEvent = SyntheticEvent<NativePointerEvent>;
export type PressEvent = ResponderSyntheticEvent<
$ReadOnly<{|