UNPKG

7.32 kBTypeScriptView Raw
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @format
8 */
9
10import type * as React from 'react';
11import {HostInstance} from '../../types/public/ReactNativeTypes';
12
13export interface LayoutRectangle {
14 x: number;
15 y: number;
16 width: number;
17 height: number;
18}
19
20// @see TextProps.onLayout
21export type LayoutChangeEvent = NativeSyntheticEvent<{layout: LayoutRectangle}>;
22
23interface TextLayoutLine {
24 ascender: number;
25 capHeight: number;
26 descender: number;
27 height: number;
28 text: string;
29 width: number;
30 x: number;
31 xHeight: number;
32 y: number;
33}
34
35/**
36 * @see TextProps.onTextLayout
37 */
38export interface TextLayoutEventData extends TargetedEvent {
39 lines: TextLayoutLine[];
40}
41
42// Similar to React.SyntheticEvent except for nativeEvent
43export interface NativeSyntheticEvent<T>
44 extends React.BaseSyntheticEvent<T, HostInstance, HostInstance> {}
45
46export interface NativeTouchEvent {
47 /**
48 * Array of all touch events that have changed since the last event
49 */
50 changedTouches: NativeTouchEvent[];
51
52 /**
53 * The ID of the touch
54 */
55 identifier: string;
56
57 /**
58 * The X position of the touch, relative to the element
59 */
60 locationX: number;
61
62 /**
63 * The Y position of the touch, relative to the element
64 */
65 locationY: number;
66
67 /**
68 * The X position of the touch, relative to the screen
69 */
70 pageX: number;
71
72 /**
73 * The Y position of the touch, relative to the screen
74 */
75 pageY: number;
76
77 /**
78 * The node id of the element receiving the touch event
79 */
80 target: string;
81
82 /**
83 * A time identifier for the touch, useful for velocity calculation
84 */
85 timestamp: number;
86
87 /**
88 * Array of all current touches on the screen
89 */
90 touches: NativeTouchEvent[];
91
92 /**
93 * 3D Touch reported force
94 * @platform ios
95 */
96 force?: number | undefined;
97}
98
99/**
100 * https://developer.mozilla.org/en-US/docs/Web/API/UIEvent
101 */
102export interface NativeUIEvent {
103 /**
104 * Returns a long with details about the event, depending on the event type.
105 */
106 readonly detail: number;
107}
108
109/**
110 * https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
111 */
112export interface NativeMouseEvent extends NativeUIEvent {
113 /**
114 * The X coordinate of the mouse pointer in global (screen) coordinates.
115 */
116 readonly screenX: number;
117 /**
118 * The Y coordinate of the mouse pointer in global (screen) coordinates.
119 */
120 readonly screenY: number;
121 /**
122 * The X coordinate of the mouse pointer relative to the whole document.
123 */
124 readonly pageX: number;
125 /**
126 * The Y coordinate of the mouse pointer relative to the whole document.
127 */
128 readonly pageY: number;
129 /**
130 * The X coordinate of the mouse pointer in local (DOM content) coordinates.
131 */
132 readonly clientX: number;
133 /**
134 * The Y coordinate of the mouse pointer in local (DOM content) coordinates.
135 */
136 readonly clientY: number;
137 /**
138 * Alias for NativeMouseEvent.clientX
139 */
140 readonly x: number;
141 /**
142 * Alias for NativeMouseEvent.clientY
143 */
144 readonly y: number;
145 /**
146 * Returns true if the control key was down when the mouse event was fired.
147 */
148 readonly ctrlKey: boolean;
149 /**
150 * Returns true if the shift key was down when the mouse event was fired.
151 */
152 readonly shiftKey: boolean;
153 /**
154 * Returns true if the alt key was down when the mouse event was fired.
155 */
156 readonly altKey: boolean;
157 /**
158 * Returns true if the meta key was down when the mouse event was fired.
159 */
160 readonly metaKey: boolean;
161 /**
162 * The button number that was pressed (if applicable) when the mouse event was fired.
163 */
164 readonly button: number;
165 /**
166 * The buttons being depressed (if any) when the mouse event was fired.
167 */
168 readonly buttons: number;
169 /**
170 * The secondary target for the event, if there is one.
171 */
172 readonly relatedTarget: null | number | HostInstance;
173 // offset is proposed: https://drafts.csswg.org/cssom-view/#extensions-to-the-mouseevent-interface
174 /**
175 * The X coordinate of the mouse pointer between that event and the padding edge of the target node
176 */
177 readonly offsetX: number;
178 /**
179 * The Y coordinate of the mouse pointer between that event and the padding edge of the target node
180 */
181 readonly offsetY: number;
182}
183
184/**
185 * https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent
186 */
187export interface NativePointerEvent extends NativeMouseEvent {
188 /**
189 * A unique identifier for the pointer causing the event.
190 */
191 readonly pointerId: number;
192 /**
193 * The width (magnitude on the X axis), in CSS pixels, of the contact geometry of the pointer
194 */
195 readonly width: number;
196 /**
197 * The height (magnitude on the Y axis), in CSS pixels, of the contact geometry of the pointer.
198 */
199 readonly height: number;
200 /**
201 * The normalized pressure of the pointer input in the range 0 to 1, where 0 and 1 represent
202 * the minimum and maximum pressure the hardware is capable of detecting, respectively.
203 */
204 readonly pressure: number;
205 /**
206 * The normalized tangential pressure of the pointer input (also known as barrel pressure or
207 * cylinder stress) in the range -1 to 1, where 0 is the neutral position of the control.
208 */
209 readonly tangentialPressure: number;
210 /**
211 * The plane angle (in degrees, in the range of -90 to 90) between the Y–Z plane and the plane
212 * containing both the pointer (e.g. pen stylus) axis and the Y axis.
213 */
214 readonly tiltX: number;
215 /**
216 * The plane angle (in degrees, in the range of -90 to 90) between the X–Z plane and the plane
217 * containing both the pointer (e.g. pen stylus) axis and the X axis.
218 */
219 readonly tiltY: number;
220 /**
221 * The clockwise rotation of the pointer (e.g. pen stylus) around its major axis in degrees,
222 * with a value in the range 0 to 359.
223 */
224 readonly twist: number;
225 /**
226 * Indicates the device type that caused the event (mouse, pen, touch, etc.)
227 */
228 readonly pointerType: string;
229 /**
230 * Indicates if the pointer represents the primary pointer of this pointer type.
231 */
232 readonly isPrimary: boolean;
233}
234
235export type PointerEvent = NativeSyntheticEvent<NativePointerEvent>;
236
237export interface GestureResponderEvent
238 extends NativeSyntheticEvent<NativeTouchEvent> {}
239
240export interface MouseEvent extends NativeSyntheticEvent<NativeMouseEvent> {}
241
242export interface TargetedEvent {
243 target: number;
244}
245
246export interface PointerEvents {
247 onPointerEnter?: ((event: PointerEvent) => void) | undefined;
248 onPointerEnterCapture?: ((event: PointerEvent) => void) | undefined;
249 onPointerLeave?: ((event: PointerEvent) => void) | undefined;
250 onPointerLeaveCapture?: ((event: PointerEvent) => void) | undefined;
251 onPointerMove?: ((event: PointerEvent) => void) | undefined;
252 onPointerMoveCapture?: ((event: PointerEvent) => void) | undefined;
253 onPointerCancel?: ((event: PointerEvent) => void) | undefined;
254 onPointerCancelCapture?: ((event: PointerEvent) => void) | undefined;
255 onPointerDown?: ((event: PointerEvent) => void) | undefined;
256 onPointerDownCapture?: ((event: PointerEvent) => void) | undefined;
257 onPointerUp?: ((event: PointerEvent) => void) | undefined;
258 onPointerUpCapture?: ((event: PointerEvent) => void) | undefined;
259}
260
\No newline at end of file