• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * Creating an Object
18 * @since 7
19 */
20declare enum PanDirection {
21  /**
22   * Default.
23   * @since 7
24   */
25  None,
26
27  /**
28   * Sliding horizontally.
29   * @since 7
30   */
31  Horizontal,
32
33  /**
34   * Sliding left.
35   * @since 7
36   */
37  Left,
38
39  /**
40   * Sliding right.
41   * @since 7
42   */
43  Right,
44
45  /**
46   * Sliding Vertical
47   * @since 7
48   */
49  Vertical,
50
51  /**
52   * Sliding up.
53   * @since 7
54   */
55  Up,
56
57  /**
58   * Sliding Down.
59   * @since 7
60   */
61  Down,
62
63  /**
64   * Sliding in all directions.
65   * @since 7
66   */
67  All,
68}
69
70/**
71 * Creating an Object
72 * @since 8
73 */
74declare enum SwipeDirection {
75  /**
76   * Default.
77   * @since 8
78   */
79  None,
80
81  /**
82   * Sliding horizontally.
83   * @since 8
84   */
85  Horizontal,
86
87  /**
88   * Sliding Vertical
89   * @since 8
90   */
91  Vertical,
92
93  /**
94   * Sliding in all directions.
95   * @since 8
96   */
97  All,
98}
99
100/**
101 * Creating an Object
102 * @since 7
103 */
104declare enum GestureMode {
105  /**
106   * Sequential gesture recognition is performed in sequence according to the gesture registration sequence.
107   * @since 7
108   */
109  Sequence,
110
111  /**
112   * Simultaneous recognition. Registration gestures participate in recognition. Everything can be triggered.
113   * @since 7
114   */
115  Parallel,
116
117  /**
118   * Mutually exclusive recognition. Only one gesture is successfully recognized.
119   * @since 7
120   */
121  Exclusive,
122}
123
124/**
125 * Creating an Object
126 * @since 7
127 */
128declare enum GestureMask {
129  /**
130   * High-priority response to the current gesture.When the current gesture fails to be recognized, other gesture responses are triggered.For gestures with the same priority, responses are performed based on the recognition sequence.
131   * @since 7
132   */
133  Normal,
134
135  /**
136   * Ignore internal gestures and recognize the current gesture first.
137   * @since 7
138   */
139  IgnoreInternal,
140}
141
142/**
143 * Type of the finger information.
144 * @since 8
145 */
146interface FingerInfo {
147  /**
148   * Finger unique identifier.
149   * @since 8
150   */
151  id: number;
152
153  /**
154   * X coordinate of the touch point relative to the left edge of the device screen.
155   * @since 8
156   */
157  globalX: number;
158
159  /**
160   * The Y coordinate of the touch point relative to the upper edge of the device screen.
161   * @since 8
162   */
163  globalY: number;
164
165  /**
166   * X coordinate of the touch point relative to the left edge of the touched element.
167   * @since 8
168   */
169  localX: number;
170
171  /**
172   * Y coordinate of the touch point relative to the upper edge of the touched element.
173   * @since 8
174   */
175  localY: number;
176}
177
178/**
179 * Defines the Gesture Type.
180 * @since 7
181 */
182declare type GestureType =
183  TapGestureInterface
184  | LongPressGestureInterface
185  | PanGestureInterface
186  | PinchGestureInterface
187  | SwipeGestureInterface
188  | RotationGestureInterface
189  | GestureGroupInterface;
190
191/**
192 * Defines event info for gesture.
193 * @since 7
194 */
195interface GestureEvent extends BaseEvent {
196  /**
197   * Indicates whether an event is triggered repeatedly.
198   * Used in LongPressGesture.
199   * @since 7
200   */
201  repeat: boolean;
202
203  /**
204   * All finger information.
205   * Used in LongPressGesture and TapGesture.
206   * @since 8
207   */
208  fingerList: FingerInfo[];
209
210  /**
211   * Gesture event offset X.
212   * The unit is vp.
213   * Used in PanGesture.
214   * @since 7
215   */
216  offsetX: number;
217
218  /**
219   * Gesture event offset Y.
220   * The unit is vp.
221   * Used in PanGesture.
222   * @since 7
223   */
224  offsetY: number;
225
226  /**
227   * Gesture event direction angle.
228   * The unit is deg.
229   * Used in RotationGesture and SwipeGesture.
230   * @since 7
231   */
232  angle: number;
233
234  /**
235   * Gesture event slide speed.
236   * The unit is vp.
237   * Used in SwipeGesture.
238   * @since 8
239   */
240  speed: number;
241
242  /**
243   * Scaling ratio.
244   * Used in PinchGesture.
245   * @since 7
246   */
247  scale: number;
248
249  /**
250   * X-axis coordinate of the kneading center point.
251   * The unit is vp.
252   * Used in PinchGesture.
253   * @since 7
254   */
255  pinchCenterX: number;
256
257  /**
258   * Y-axis coordinate of the kneading center point.
259   * The unit is vp.
260   * Used in PinchGesture.
261   * @since 7
262   */
263  pinchCenterY: number;
264}
265
266/**
267 * Defines TapGesture interface.
268 * @since 7
269 */
270interface TapGestureInterface {
271  /**
272   * Set the value.
273   * count:Number of consecutive clicks recognized. If the value is less than 1, the default value is used.
274   * fingers:The hand index that triggers the click. If the value is less than 1, the default value is used.
275   * @since 7
276   */
277  (value?: { count?: number; fingers?: number }): TapGestureInterface;
278
279  /**
280   * Tap gesture recognition success callback.
281   * @since 7
282   */
283  onAction(event: (event?: GestureEvent) => void): TapGestureInterface;
284}
285
286/**
287 * Defines LongPressGesture interface.
288 * @since 7
289 */
290interface LongPressGestureInterface {
291  /**
292   * Set the value.
293   * fingers: Indicates the hand index that triggers the long press.
294   * repeat: Indicates whether to trigger event callback continuously.
295   * duration: Minimum press and hold time, in milliseconds.
296   * @since 7
297   */
298  (value?: { fingers?: number; repeat?: boolean; duration?: number }): LongPressGestureInterface;
299
300  /**
301   * LongPress gesture recognition success callback.
302   * @since 7
303   */
304  onAction(event: (event?: GestureEvent) => void): LongPressGestureInterface;
305
306  /**
307   * The LongPress gesture is successfully recognized. When the finger is lifted, the callback is triggered.
308   * @since 7
309   */
310  onActionEnd(event: (event?: GestureEvent) => void): LongPressGestureInterface;
311
312  /**
313   * The LongPress gesture is successfully recognized and a callback is triggered when the touch cancel event is received.
314   * @since 7
315   */
316  onActionCancel(event: () => void): LongPressGestureInterface;
317}
318
319/**
320 * Defines the PanGesture options.
321 * @since 7
322 */
323declare class PanGestureOptions {
324  /**
325   * Constructor parameters.
326   * @since 7
327   */
328  constructor(value?: { fingers?: number; direction?: PanDirection; distance?: number });
329
330  /**
331   * Sets the direction attribute.
332   * @since 7
333   */
334  setDirection(value: PanDirection);
335
336  /**
337   * Sets the setDistance attribute.
338   * @since 7
339   */
340  setDistance(value: number);
341
342  /**
343   * Sets the setFingers attribute.
344   * @since 7
345   */
346  setFingers(value: number);
347}
348
349/**
350 * Defines the PanGesture interface.
351 * @since 7
352 */
353interface PanGestureInterface {
354  /**
355   * Set the value.
356   * @since 7
357   */
358  (value?: { fingers?: number; direction?: PanDirection; distance?: number } | PanGestureOptions): PanGestureInterface;
359
360  /**
361   * Pan gesture recognition success callback.
362   * @since 7
363   */
364  onActionStart(event: (event?: GestureEvent) => void): PanGestureInterface;
365
366  /**
367   * Callback when the Pan gesture is moving.
368   * @since 7
369   */
370  onActionUpdate(event: (event?: GestureEvent) => void): PanGestureInterface;
371
372  /**
373   * The Pan gesture is successfully recognized. When the finger is lifted, the callback is triggered.
374   * @since 7
375   */
376  onActionEnd(event: (event?: GestureEvent) => void): PanGestureInterface;
377
378  /**
379   * The Pan gesture is successfully recognized and a callback is triggered when the touch cancel event is received.
380   * @since 7
381   */
382  onActionCancel(event: () => void): PanGestureInterface;
383}
384
385/**
386 * Defines the SwipeGesture interface.
387 * @since 8
388 */
389interface SwipeGestureInterface {
390  /**
391   * Set the value.
392   * @since 8
393   */
394  (value?: { fingers?: number; direction?: SwipeDirection; speed?: number }): SwipeGestureInterface;
395
396  /**
397   * Slide gesture recognition success callback.
398   * @since 8
399   */
400  onAction(event: (event?: GestureEvent) => void): SwipeGestureInterface;
401}
402
403/**
404 * Defines the PinchGesture interface.
405 * @since 7
406 */
407interface PinchGestureInterface {
408  /**
409   * Set the value.
410   * @since 7
411   */
412  (value?: { fingers?: number; distance?: number }): PinchGestureInterface;
413
414  /**
415   * Pan gesture recognition success callback.
416   * @since 7
417   */
418  onActionStart(event: (event?: GestureEvent) => void): PinchGestureInterface;
419
420  /**
421   * Callback when the Pan gesture is moving.
422   * @since 7
423   */
424  onActionUpdate(event: (event?: GestureEvent) => void): PinchGestureInterface;
425
426  /**
427   * The Pan gesture is successfully recognized. When the finger is lifted, the callback is triggered.
428   * @since 7
429   */
430  onActionEnd(event: (event?: GestureEvent) => void): PinchGestureInterface;
431
432  /**
433   * The Pan gesture is successfully recognized and a callback is triggered when the touch cancel event is received.
434   * @since 7
435   */
436  onActionCancel(event: () => void): PinchGestureInterface;
437}
438
439/**
440 * Defines the RotationGesture interface.
441 * @since 7
442 */
443interface RotationGestureInterface {
444  /**
445   * Set the value.
446   * @since 7
447   */
448  (value?: { fingers?: number; angle?: number }): RotationGestureInterface;
449
450  /**
451   * Pan gesture recognition success callback.
452   * @since 7
453   */
454  onActionStart(event: (event?: GestureEvent) => void): RotationGestureInterface;
455
456  /**
457   * Callback when the Pan gesture is moving.
458   * @since 7
459   */
460  onActionUpdate(event: (event?: GestureEvent) => void): RotationGestureInterface;
461
462  /**
463   * The Pan gesture is successfully recognized. When the finger is lifted, the callback is triggered.
464   * @since 7
465   */
466  onActionEnd(event: (event?: GestureEvent) => void): RotationGestureInterface;
467
468  /**
469   * The Pan gesture is successfully recognized and a callback is triggered when the touch cancel event is received.
470   * @since 7
471   */
472  onActionCancel(event: () => void): RotationGestureInterface;
473}
474
475/**
476 * Defines the GestureGroup interface.
477 * @since 7
478 */
479interface GestureGroupInterface {
480  /**
481   * Return to Obtain GestureGroup.
482   * @since 7
483   */
484  (mode: GestureMode, ...gesture: GestureType[]): GestureGroupInterface;
485
486  /**
487   * The Pan gesture is successfully recognized and a callback is triggered when the touch cancel event is received.
488   * @since 7
489   */
490  onCancel(event: () => void): GestureGroupInterface;
491}
492
493/**
494 * Defines TapGesture Component.
495 * @since 7
496 */
497declare const TapGesture: TapGestureInterface;
498
499/**
500 * Defines LongPressGesture Component.
501 * @since 7
502 */
503declare const LongPressGesture: LongPressGestureInterface;
504
505/**
506 * Defines PanGesture Component.
507 * @since 7
508 */
509declare const PanGesture: PanGestureInterface;
510
511/**
512 * Defines SwipeGesture Component.
513 * @since 7
514 */
515declare const SwipeGesture: SwipeGestureInterface;
516
517/**
518 * Defines PinchGesture Component.
519 * @since 7
520 */
521declare const PinchGesture: PinchGestureInterface;
522
523/**
524 * Defines RotationGesture Component.
525 * @since 7
526 */
527declare const RotationGesture: RotationGestureInterface;
528
529/**
530 * Defines GestureGroup Component.
531 * @since 7
532 */
533declare const GestureGroup: GestureGroupInterface;
534