react-native-gesture-handler 2.16.0 → 2.16.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/lib/commonjs/handlers/PanGestureHandler.js.map +1 -1
- package/lib/commonjs/handlers/createHandler.js +9 -3
- package/lib/commonjs/handlers/createHandler.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector.js +15 -0
- package/lib/commonjs/handlers/gestures/GestureDetector.js.map +1 -1
- package/lib/commonjs/handlers/gestures/flingGesture.js +13 -0
- package/lib/commonjs/handlers/gestures/flingGesture.js.map +1 -1
- package/lib/commonjs/handlers/gestures/forceTouchGesture.js +17 -0
- package/lib/commonjs/handlers/gestures/forceTouchGesture.js.map +1 -1
- package/lib/commonjs/handlers/gestures/gesture.js +135 -0
- package/lib/commonjs/handlers/gestures/gesture.js.map +1 -1
- package/lib/commonjs/handlers/gestures/gestureObjects.js +66 -0
- package/lib/commonjs/handlers/gestures/gestureObjects.js.map +1 -1
- package/lib/commonjs/handlers/gestures/gestureStateManager.web.js +1 -1
- package/lib/commonjs/handlers/gestures/gestureStateManager.web.js.map +1 -1
- package/lib/commonjs/handlers/gestures/hoverGesture.js +1 -1
- package/lib/commonjs/handlers/gestures/hoverGesture.js.map +1 -1
- package/lib/commonjs/handlers/gestures/longPressGesture.js +12 -0
- package/lib/commonjs/handlers/gestures/longPressGesture.js.map +1 -1
- package/lib/commonjs/handlers/gestures/nativeGesture.js +10 -0
- package/lib/commonjs/handlers/gestures/nativeGesture.js.map +1 -1
- package/lib/commonjs/handlers/gestures/panGesture.js +76 -0
- package/lib/commonjs/handlers/gestures/panGesture.js.map +1 -1
- package/lib/commonjs/handlers/gestures/tapGesture.js +42 -0
- package/lib/commonjs/handlers/gestures/tapGesture.js.map +1 -1
- package/lib/commonjs/utils.js +5 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/web/handlers/GestureHandler.js +7 -7
- package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/PanGestureHandler.js +3 -1
- package/lib/commonjs/web/handlers/PanGestureHandler.js.map +1 -1
- package/lib/commonjs/web/interfaces.js.map +1 -1
- package/lib/module/handlers/PanGestureHandler.js.map +1 -1
- package/lib/module/handlers/createHandler.js +9 -3
- package/lib/module/handlers/createHandler.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector.js +15 -0
- package/lib/module/handlers/gestures/GestureDetector.js.map +1 -1
- package/lib/module/handlers/gestures/flingGesture.js +13 -0
- package/lib/module/handlers/gestures/flingGesture.js.map +1 -1
- package/lib/module/handlers/gestures/forceTouchGesture.js +17 -0
- package/lib/module/handlers/gestures/forceTouchGesture.js.map +1 -1
- package/lib/module/handlers/gestures/gesture.js +135 -0
- package/lib/module/handlers/gestures/gesture.js.map +1 -1
- package/lib/module/handlers/gestures/gestureObjects.js +67 -0
- package/lib/module/handlers/gestures/gestureObjects.js.map +1 -1
- package/lib/module/handlers/gestures/gestureStateManager.web.js +1 -1
- package/lib/module/handlers/gestures/gestureStateManager.web.js.map +1 -1
- package/lib/module/handlers/gestures/hoverGesture.js +1 -1
- package/lib/module/handlers/gestures/hoverGesture.js.map +1 -1
- package/lib/module/handlers/gestures/longPressGesture.js +12 -0
- package/lib/module/handlers/gestures/longPressGesture.js.map +1 -1
- package/lib/module/handlers/gestures/nativeGesture.js +10 -0
- package/lib/module/handlers/gestures/nativeGesture.js.map +1 -1
- package/lib/module/handlers/gestures/panGesture.js +76 -0
- package/lib/module/handlers/gestures/panGesture.js.map +1 -1
- package/lib/module/handlers/gestures/tapGesture.js +42 -0
- package/lib/module/handlers/gestures/tapGesture.js.map +1 -1
- package/lib/module/utils.js +5 -1
- package/lib/module/utils.js.map +1 -1
- package/lib/module/web/handlers/GestureHandler.js +7 -7
- package/lib/module/web/handlers/GestureHandler.js.map +1 -1
- package/lib/module/web/handlers/PanGestureHandler.js +3 -1
- package/lib/module/web/handlers/PanGestureHandler.js.map +1 -1
- package/lib/module/web/interfaces.js.map +1 -1
- package/lib/typescript/handlers/PanGestureHandler.d.ts +4 -4
- package/lib/typescript/handlers/gestures/GestureDetector.d.ts +36 -0
- package/lib/typescript/handlers/gestures/flingGesture.d.ts +11 -0
- package/lib/typescript/handlers/gestures/forceTouchGesture.d.ts +14 -0
- package/lib/typescript/handlers/gestures/gesture.d.ts +113 -0
- package/lib/typescript/handlers/gestures/gestureObjects.d.ts +57 -0
- package/lib/typescript/handlers/gestures/hoverGesture.d.ts +1 -1
- package/lib/typescript/handlers/gestures/longPressGesture.d.ts +10 -0
- package/lib/typescript/handlers/gestures/nativeGesture.d.ts +8 -0
- package/lib/typescript/handlers/gestures/panGesture.d.ts +67 -4
- package/lib/typescript/handlers/gestures/tapGesture.d.ts +35 -0
- package/lib/typescript/web/handlers/GestureHandler.d.ts +2 -2
- package/lib/typescript/web/handlers/IGestureHandler.d.ts +1 -1
- package/lib/typescript/web/interfaces.d.ts +1 -0
- package/package.json +3 -2
- package/src/handlers/PanGestureHandler.ts +8 -4
- package/src/handlers/createHandler.tsx +14 -10
- package/src/handlers/gestures/GestureDetector.tsx +38 -0
- package/src/handlers/gestures/flingGesture.ts +11 -0
- package/src/handlers/gestures/forceTouchGesture.ts +14 -0
- package/src/handlers/gestures/gesture.ts +113 -0
- package/src/handlers/gestures/gestureObjects.ts +57 -0
- package/src/handlers/gestures/gestureStateManager.web.ts +1 -1
- package/src/handlers/gestures/hoverGesture.ts +1 -1
- package/src/handlers/gestures/longPressGesture.ts +10 -0
- package/src/handlers/gestures/nativeGesture.ts +8 -0
- package/src/handlers/gestures/panGesture.ts +75 -4
- package/src/handlers/gestures/tapGesture.ts +35 -0
- package/src/utils.ts +9 -2
- package/src/web/handlers/GestureHandler.ts +9 -9
- package/src/web/handlers/IGestureHandler.ts +1 -1
- package/src/web/handlers/PanGestureHandler.ts +4 -0
- package/src/web/interfaces.ts +1 -0
|
@@ -155,6 +155,10 @@ export abstract class BaseGesture<
|
|
|
155
155
|
: [gesture];
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Sets a `ref` to the gesture object, allowing for interoperability with the old API.
|
|
160
|
+
* @param ref
|
|
161
|
+
*/
|
|
158
162
|
withRef(ref: React.MutableRefObject<GestureType | undefined>) {
|
|
159
163
|
this.config.ref = ref;
|
|
160
164
|
return this;
|
|
@@ -166,18 +170,32 @@ export abstract class BaseGesture<
|
|
|
166
170
|
return callback.__workletHash !== undefined;
|
|
167
171
|
}
|
|
168
172
|
|
|
173
|
+
/**
|
|
174
|
+
* Set the callback that is being called when given gesture handler starts receiving touches.
|
|
175
|
+
* At the moment of this callback the handler is in `BEGAN` state and we don't know yet if it will recognize the gesture at all.
|
|
176
|
+
* @param callback
|
|
177
|
+
*/
|
|
169
178
|
onBegin(callback: (event: GestureStateChangeEvent<EventPayloadT>) => void) {
|
|
170
179
|
this.handlers.onBegin = callback;
|
|
171
180
|
this.handlers.isWorklet[CALLBACK_TYPE.BEGAN] = this.isWorklet(callback);
|
|
172
181
|
return this;
|
|
173
182
|
}
|
|
174
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Set the callback that is being called when the gesture is recognized by the handler and it transitions to the `ACTIVE` state.
|
|
186
|
+
* @param callback
|
|
187
|
+
*/
|
|
175
188
|
onStart(callback: (event: GestureStateChangeEvent<EventPayloadT>) => void) {
|
|
176
189
|
this.handlers.onStart = callback;
|
|
177
190
|
this.handlers.isWorklet[CALLBACK_TYPE.START] = this.isWorklet(callback);
|
|
178
191
|
return this;
|
|
179
192
|
}
|
|
180
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Set the callback that is being called when the gesture that was recognized by the handler finishes and handler reaches `END` state.
|
|
196
|
+
* It will be called only if the handler was previously in the `ACTIVE` state.
|
|
197
|
+
* @param callback
|
|
198
|
+
*/
|
|
181
199
|
onEnd(
|
|
182
200
|
callback: (
|
|
183
201
|
event: GestureStateChangeEvent<EventPayloadT>,
|
|
@@ -190,6 +208,10 @@ export abstract class BaseGesture<
|
|
|
190
208
|
return this;
|
|
191
209
|
}
|
|
192
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Set the callback that is being called when the handler finalizes handling gesture - the gesture was recognized and has finished or it failed to recognize.
|
|
213
|
+
* @param callback
|
|
214
|
+
*/
|
|
193
215
|
onFinalize(
|
|
194
216
|
callback: (
|
|
195
217
|
event: GestureStateChangeEvent<EventPayloadT>,
|
|
@@ -202,6 +224,10 @@ export abstract class BaseGesture<
|
|
|
202
224
|
return this;
|
|
203
225
|
}
|
|
204
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Set the `onTouchesDown` callback which is called every time a pointer is placed on the screen.
|
|
229
|
+
* @param callback
|
|
230
|
+
*/
|
|
205
231
|
onTouchesDown(callback: TouchEventHandlerType) {
|
|
206
232
|
this.config.needsPointerData = true;
|
|
207
233
|
this.handlers.onTouchesDown = callback;
|
|
@@ -211,6 +237,10 @@ export abstract class BaseGesture<
|
|
|
211
237
|
return this;
|
|
212
238
|
}
|
|
213
239
|
|
|
240
|
+
/**
|
|
241
|
+
* Set the `onTouchesMove` callback which is called every time a pointer is moved on the screen.
|
|
242
|
+
* @param callback
|
|
243
|
+
*/
|
|
214
244
|
onTouchesMove(callback: TouchEventHandlerType) {
|
|
215
245
|
this.config.needsPointerData = true;
|
|
216
246
|
this.handlers.onTouchesMove = callback;
|
|
@@ -220,6 +250,10 @@ export abstract class BaseGesture<
|
|
|
220
250
|
return this;
|
|
221
251
|
}
|
|
222
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Set the `onTouchesUp` callback which is called every time a pointer is lifted from the screen.
|
|
255
|
+
* @param callback
|
|
256
|
+
*/
|
|
223
257
|
onTouchesUp(callback: TouchEventHandlerType) {
|
|
224
258
|
this.config.needsPointerData = true;
|
|
225
259
|
this.handlers.onTouchesUp = callback;
|
|
@@ -229,6 +263,10 @@ export abstract class BaseGesture<
|
|
|
229
263
|
return this;
|
|
230
264
|
}
|
|
231
265
|
|
|
266
|
+
/**
|
|
267
|
+
* Set the `onTouchesCancelled` callback which is called every time a pointer stops being tracked, for example when the gesture finishes.
|
|
268
|
+
* @param callback
|
|
269
|
+
*/
|
|
232
270
|
onTouchesCancelled(callback: TouchEventHandlerType) {
|
|
233
271
|
this.config.needsPointerData = true;
|
|
234
272
|
this.handlers.onTouchesCancelled = callback;
|
|
@@ -238,36 +276,77 @@ export abstract class BaseGesture<
|
|
|
238
276
|
return this;
|
|
239
277
|
}
|
|
240
278
|
|
|
279
|
+
/**
|
|
280
|
+
* Indicates whether the given handler should be analyzing stream of touch events or not.
|
|
281
|
+
* @param enabled
|
|
282
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/pan-gesture#enabledvalue-boolean
|
|
283
|
+
*/
|
|
241
284
|
enabled(enabled: boolean) {
|
|
242
285
|
this.config.enabled = enabled;
|
|
243
286
|
return this;
|
|
244
287
|
}
|
|
245
288
|
|
|
289
|
+
/**
|
|
290
|
+
* When true the handler will cancel or fail recognition (depending on its current state) whenever the finger leaves the area of the connected view.
|
|
291
|
+
* @param value
|
|
292
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/pan-gesture#shouldcancelwhenoutsidevalue-boolean
|
|
293
|
+
*/
|
|
246
294
|
shouldCancelWhenOutside(value: boolean) {
|
|
247
295
|
this.config.shouldCancelWhenOutside = value;
|
|
248
296
|
return this;
|
|
249
297
|
}
|
|
250
298
|
|
|
299
|
+
/**
|
|
300
|
+
* This parameter enables control over what part of the connected view area can be used to begin recognizing the gesture.
|
|
301
|
+
* When a negative number is provided the bounds of the view will reduce the area by the given number of points in each of the sides evenly.
|
|
302
|
+
* @param hitSlop
|
|
303
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/pan-gesture#hitslopsettings
|
|
304
|
+
*/
|
|
251
305
|
hitSlop(hitSlop: HitSlop) {
|
|
252
306
|
this.config.hitSlop = hitSlop;
|
|
253
307
|
return this;
|
|
254
308
|
}
|
|
255
309
|
|
|
310
|
+
/**
|
|
311
|
+
* #### Web only
|
|
312
|
+
* This parameter allows to specify which `cursor` should be used when gesture activates.
|
|
313
|
+
* Supports all CSS cursor values (e.g. `"grab"`, `"zoom-in"`). Default value is set to `"auto"`.
|
|
314
|
+
* @param activeCursor
|
|
315
|
+
*/
|
|
256
316
|
activeCursor(activeCursor: ActiveCursor) {
|
|
257
317
|
this.config.activeCursor = activeCursor;
|
|
258
318
|
return this;
|
|
259
319
|
}
|
|
260
320
|
|
|
321
|
+
/**
|
|
322
|
+
* #### Web & Android only
|
|
323
|
+
* Allows users to choose which mouse button should handler respond to.
|
|
324
|
+
* Arguments can be combined using `|` operator, e.g. `mouseButton(MouseButton.LEFT | MouseButton.RIGHT)`.
|
|
325
|
+
* Default value is set to `MouseButton.LEFT`.
|
|
326
|
+
* @param mouseButton
|
|
327
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/pan-gesture#mousebuttonvalue-mousebutton-web--android-only
|
|
328
|
+
*/
|
|
261
329
|
mouseButton(mouseButton: MouseButton) {
|
|
262
330
|
this.config.mouseButton = mouseButton;
|
|
263
331
|
return this;
|
|
264
332
|
}
|
|
265
333
|
|
|
334
|
+
/**
|
|
335
|
+
* When `react-native-reanimated` is installed, the callbacks passed to the gestures are automatically workletized and run on the UI thread when called.
|
|
336
|
+
* This option allows for changing this behavior: when `true`, all the callbacks will be run on the JS thread instead of the UI thread, regardless of whether they are worklets or not.
|
|
337
|
+
* Defaults to `false`.
|
|
338
|
+
* @param runOnJS
|
|
339
|
+
*/
|
|
266
340
|
runOnJS(runOnJS: boolean) {
|
|
267
341
|
this.config.runOnJS = runOnJS;
|
|
268
342
|
return this;
|
|
269
343
|
}
|
|
270
344
|
|
|
345
|
+
/**
|
|
346
|
+
* Allows gestures across different components to be recognized simultaneously.
|
|
347
|
+
* @param gestures
|
|
348
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/fundamentals/gesture-composition/#simultaneouswithexternalgesture
|
|
349
|
+
*/
|
|
271
350
|
simultaneousWithExternalGesture(...gestures: Exclude<GestureRef, number>[]) {
|
|
272
351
|
for (const gesture of gestures) {
|
|
273
352
|
this.addDependency('simultaneousWith', gesture);
|
|
@@ -275,6 +354,11 @@ export abstract class BaseGesture<
|
|
|
275
354
|
return this;
|
|
276
355
|
}
|
|
277
356
|
|
|
357
|
+
/**
|
|
358
|
+
* Allows to delay activation of the handler until all handlers passed as arguments to this method fail (or don't begin at all).
|
|
359
|
+
* @param gestures
|
|
360
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/fundamentals/gesture-composition/#requireexternalgesturetofail
|
|
361
|
+
*/
|
|
278
362
|
requireExternalGestureToFail(...gestures: Exclude<GestureRef, number>[]) {
|
|
279
363
|
for (const gesture of gestures) {
|
|
280
364
|
this.addDependency('requireToFail', gesture);
|
|
@@ -282,6 +366,11 @@ export abstract class BaseGesture<
|
|
|
282
366
|
return this;
|
|
283
367
|
}
|
|
284
368
|
|
|
369
|
+
/**
|
|
370
|
+
* Works similarily to `requireExternalGestureToFail` but the direction of the relation is reversed - instead of being one-to-many relation, it's many-to-one.
|
|
371
|
+
* @param gestures
|
|
372
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/fundamentals/gesture-composition/#blocksexternalgesture
|
|
373
|
+
*/
|
|
285
374
|
blocksExternalGesture(...gestures: Exclude<GestureRef, number>[]) {
|
|
286
375
|
for (const gesture of gestures) {
|
|
287
376
|
this.addDependency('blocksHandlers', gesture);
|
|
@@ -289,11 +378,21 @@ export abstract class BaseGesture<
|
|
|
289
378
|
return this;
|
|
290
379
|
}
|
|
291
380
|
|
|
381
|
+
/**
|
|
382
|
+
* Sets a `testID` property for gesture object, allowing for querying for it in tests.
|
|
383
|
+
* @param id
|
|
384
|
+
*/
|
|
292
385
|
withTestId(id: string) {
|
|
293
386
|
this.config.testId = id;
|
|
294
387
|
return this;
|
|
295
388
|
}
|
|
296
389
|
|
|
390
|
+
/**
|
|
391
|
+
* #### iOS only
|
|
392
|
+
* When `true`, the handler will cancel touches for native UI components (`UIButton`, `UISwitch`, etc) it's attached to when it becomes `ACTIVE`.
|
|
393
|
+
* Default value is `true`.
|
|
394
|
+
* @param value
|
|
395
|
+
*/
|
|
297
396
|
cancelsTouchesInView(value: boolean) {
|
|
298
397
|
this.config.cancelsTouchesInView = value;
|
|
299
398
|
return this;
|
|
@@ -332,12 +431,21 @@ export abstract class ContinousBaseGesture<
|
|
|
332
431
|
EventPayloadT extends Record<string, unknown>,
|
|
333
432
|
EventChangePayloadT extends Record<string, unknown>
|
|
334
433
|
> extends BaseGesture<EventPayloadT> {
|
|
434
|
+
/**
|
|
435
|
+
* Set the callback that is being called every time the gesture receives an update while it's active.
|
|
436
|
+
* @param callback
|
|
437
|
+
*/
|
|
335
438
|
onUpdate(callback: (event: GestureUpdateEvent<EventPayloadT>) => void) {
|
|
336
439
|
this.handlers.onUpdate = callback;
|
|
337
440
|
this.handlers.isWorklet[CALLBACK_TYPE.UPDATE] = this.isWorklet(callback);
|
|
338
441
|
return this;
|
|
339
442
|
}
|
|
340
443
|
|
|
444
|
+
/**
|
|
445
|
+
* Set the callback that is being called every time the gesture receives an update while it's active.
|
|
446
|
+
* This callback will receive information about change in value in relation to the last received event.
|
|
447
|
+
* @param callback
|
|
448
|
+
*/
|
|
341
449
|
onChange(
|
|
342
450
|
callback: (
|
|
343
451
|
event: GestureUpdateEvent<EventPayloadT & EventChangePayloadT>
|
|
@@ -348,6 +456,11 @@ export abstract class ContinousBaseGesture<
|
|
|
348
456
|
return this;
|
|
349
457
|
}
|
|
350
458
|
|
|
459
|
+
/**
|
|
460
|
+
* When `true` the handler will not activate by itself even if its activation criteria are met.
|
|
461
|
+
* Instead you can manipulate its state using state manager.
|
|
462
|
+
* @param manualActivation
|
|
463
|
+
*/
|
|
351
464
|
manualActivation(manualActivation: boolean) {
|
|
352
465
|
this.config.manualActivation = manualActivation;
|
|
353
466
|
return this;
|
|
@@ -15,43 +15,97 @@ import { NativeGesture } from './nativeGesture';
|
|
|
15
15
|
import { ManualGesture } from './manualGesture';
|
|
16
16
|
import { HoverGesture } from './hoverGesture';
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* `Gesture` is the object that allows you to create and compose gestures.
|
|
20
|
+
*
|
|
21
|
+
* ### Remarks
|
|
22
|
+
* - Consider wrapping your gesture configurations with `useMemo`, as it will reduce the amount of work Gesture Handler has to do under the hood when updating gestures.
|
|
23
|
+
*
|
|
24
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/gesture
|
|
25
|
+
*/
|
|
18
26
|
export const GestureObjects = {
|
|
27
|
+
/**
|
|
28
|
+
* A discrete gesture that recognizes one or many taps.
|
|
29
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/tap-gesture
|
|
30
|
+
*/
|
|
19
31
|
Tap: () => {
|
|
20
32
|
return new TapGesture();
|
|
21
33
|
},
|
|
22
34
|
|
|
35
|
+
/**
|
|
36
|
+
* A continuous gesture that can recognize a panning (dragging) gesture and track its movement.
|
|
37
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/pan-gesture
|
|
38
|
+
*/
|
|
23
39
|
Pan: () => {
|
|
24
40
|
return new PanGesture();
|
|
25
41
|
},
|
|
26
42
|
|
|
43
|
+
/**
|
|
44
|
+
* A continuous gesture that recognizes pinch gesture. It allows for tracking the distance between two fingers and use that information to scale or zoom your content.
|
|
45
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/pinch-gesture
|
|
46
|
+
*/
|
|
27
47
|
Pinch: () => {
|
|
28
48
|
return new PinchGesture();
|
|
29
49
|
},
|
|
30
50
|
|
|
51
|
+
/**
|
|
52
|
+
* A continuous gesture that can recognize rotation and track its movement.
|
|
53
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/rotation-gesture
|
|
54
|
+
*/
|
|
31
55
|
Rotation: () => {
|
|
32
56
|
return new RotationGesture();
|
|
33
57
|
},
|
|
34
58
|
|
|
59
|
+
/**
|
|
60
|
+
* A discrete gesture that activates when the movement is sufficiently fast.
|
|
61
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/fling-gesture
|
|
62
|
+
*/
|
|
35
63
|
Fling: () => {
|
|
36
64
|
return new FlingGesture();
|
|
37
65
|
},
|
|
38
66
|
|
|
67
|
+
/**
|
|
68
|
+
* A discrete gesture that activates when the corresponding view is pressed for a sufficiently long time.
|
|
69
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/long-press-gesture
|
|
70
|
+
*/
|
|
39
71
|
LongPress: () => {
|
|
40
72
|
return new LongPressGesture();
|
|
41
73
|
},
|
|
42
74
|
|
|
75
|
+
/**
|
|
76
|
+
* #### iOS only
|
|
77
|
+
* A continuous gesture that recognizes force of a touch. It allows for tracking pressure of touch on some iOS devices.
|
|
78
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/force-touch-gesture
|
|
79
|
+
*/
|
|
43
80
|
ForceTouch: () => {
|
|
44
81
|
return new ForceTouchGesture();
|
|
45
82
|
},
|
|
46
83
|
|
|
84
|
+
/**
|
|
85
|
+
* A gesture that allows other touch handling components to participate in RNGH's gesture system.
|
|
86
|
+
* When used, the other component should be the direct child of a `GestureDetector`.
|
|
87
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/native-gesture
|
|
88
|
+
*/
|
|
47
89
|
Native: () => {
|
|
48
90
|
return new NativeGesture();
|
|
49
91
|
},
|
|
50
92
|
|
|
93
|
+
/**
|
|
94
|
+
* A plain gesture that has no specific activation criteria nor event data set.
|
|
95
|
+
* Its state has to be controlled manually using a state manager.
|
|
96
|
+
* It will not fail when all the pointers are lifted from the screen.
|
|
97
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/manual-gesture
|
|
98
|
+
*/
|
|
51
99
|
Manual: () => {
|
|
52
100
|
return new ManualGesture();
|
|
53
101
|
},
|
|
54
102
|
|
|
103
|
+
/**
|
|
104
|
+
* A continuous gesture that can recognize hovering above the view it's attached to.
|
|
105
|
+
* The hover effect may be activated by moving a mouse or a stylus over the view.
|
|
106
|
+
*
|
|
107
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/hover-gesture
|
|
108
|
+
*/
|
|
55
109
|
Hover: () => {
|
|
56
110
|
return new HoverGesture();
|
|
57
111
|
},
|
|
@@ -59,6 +113,7 @@ export const GestureObjects = {
|
|
|
59
113
|
/**
|
|
60
114
|
* Builds a composed gesture consisting of gestures provided as parameters.
|
|
61
115
|
* The first one that becomes active cancels the rest of gestures.
|
|
116
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/fundamentals/gesture-composition/#race
|
|
62
117
|
*/
|
|
63
118
|
Race: (...gestures: Gesture[]) => {
|
|
64
119
|
return new ComposedGesture(...gestures);
|
|
@@ -66,6 +121,7 @@ export const GestureObjects = {
|
|
|
66
121
|
|
|
67
122
|
/**
|
|
68
123
|
* Builds a composed gesture that allows all base gestures to run simultaneously.
|
|
124
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/fundamentals/gesture-composition/#simultaneous
|
|
69
125
|
*/
|
|
70
126
|
Simultaneous(...gestures: Gesture[]) {
|
|
71
127
|
return new SimultaneousGesture(...gestures);
|
|
@@ -77,6 +133,7 @@ export const GestureObjects = {
|
|
|
77
133
|
* than the second one, second one has higher priority than the third one, and so on.
|
|
78
134
|
* For example, to make a gesture that recognizes both single and double tap you need
|
|
79
135
|
* to call Exclusive(doubleTap, singleTap).
|
|
136
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/fundamentals/gesture-composition/#exclusive
|
|
80
137
|
*/
|
|
81
138
|
Exclusive(...gestures: Gesture[]) {
|
|
82
139
|
return new ExclusiveGesture(...gestures);
|
|
@@ -14,11 +14,21 @@ export class LongPressGesture extends BaseGesture<LongPressGestureHandlerEventPa
|
|
|
14
14
|
this.shouldCancelWhenOutside(true);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Minimum time, expressed in milliseconds, that a finger must remain pressed on the corresponding view.
|
|
19
|
+
* The default value is 500.
|
|
20
|
+
* @param duration
|
|
21
|
+
*/
|
|
17
22
|
minDuration(duration: number) {
|
|
18
23
|
this.config.minDurationMs = duration;
|
|
19
24
|
return this;
|
|
20
25
|
}
|
|
21
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Maximum distance, expressed in points, that defines how far the finger is allowed to travel during a long press gesture.
|
|
29
|
+
* @param distance
|
|
30
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/long-press-gesture#maxdistancevalue-number
|
|
31
|
+
*/
|
|
22
32
|
maxDistance(distance: number) {
|
|
23
33
|
this.config.maxDist = distance;
|
|
24
34
|
return this;
|
|
@@ -13,11 +13,19 @@ export class NativeGesture extends BaseGesture<NativeViewGestureHandlerPayload>
|
|
|
13
13
|
this.handlerName = 'NativeViewGestureHandler';
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* When true, underlying handler will activate unconditionally when in `BEGAN` or `UNDETERMINED` state.
|
|
18
|
+
* @param value
|
|
19
|
+
*/
|
|
16
20
|
shouldActivateOnStart(value: boolean) {
|
|
17
21
|
this.config.shouldActivateOnStart = value;
|
|
18
22
|
return this;
|
|
19
23
|
}
|
|
20
24
|
|
|
25
|
+
/**
|
|
26
|
+
* When true, cancels all other gesture handlers when this `NativeViewGestureHandler` receives an `ACTIVE` state event.
|
|
27
|
+
* @param value
|
|
28
|
+
*/
|
|
21
29
|
disallowInterruption(value: boolean) {
|
|
22
30
|
this.config.disallowInterruption = value;
|
|
23
31
|
return this;
|
|
@@ -43,7 +43,14 @@ export class PanGesture extends ContinousBaseGesture<
|
|
|
43
43
|
this.handlerName = 'PanGestureHandler';
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Range along Y axis (in points) where fingers travels without activation of gesture.
|
|
48
|
+
* @param offset
|
|
49
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/pan-gesture#activeoffsetyvalue-number--number
|
|
50
|
+
*/
|
|
51
|
+
activeOffsetY(
|
|
52
|
+
offset: number | [activeOffsetYStart: number, activeOffsetYEnd: number]
|
|
53
|
+
) {
|
|
47
54
|
if (Array.isArray(offset)) {
|
|
48
55
|
this.config.activeOffsetYStart = offset[0];
|
|
49
56
|
this.config.activeOffsetYEnd = offset[1];
|
|
@@ -55,7 +62,14 @@ export class PanGesture extends ContinousBaseGesture<
|
|
|
55
62
|
return this;
|
|
56
63
|
}
|
|
57
64
|
|
|
58
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Range along X axis (in points) where fingers travels without activation of gesture.
|
|
67
|
+
* @param offset
|
|
68
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/pan-gesture#activeoffsetxvalue-number--number
|
|
69
|
+
*/
|
|
70
|
+
activeOffsetX(
|
|
71
|
+
offset: number | [activeOffsetXStart: number, activeOffsetXEnd: number]
|
|
72
|
+
) {
|
|
59
73
|
if (Array.isArray(offset)) {
|
|
60
74
|
this.config.activeOffsetXStart = offset[0];
|
|
61
75
|
this.config.activeOffsetXEnd = offset[1];
|
|
@@ -67,7 +81,14 @@ export class PanGesture extends ContinousBaseGesture<
|
|
|
67
81
|
return this;
|
|
68
82
|
}
|
|
69
83
|
|
|
70
|
-
|
|
84
|
+
/**
|
|
85
|
+
* When the finger moves outside this range (in points) along Y axis and gesture hasn't yet activated it will fail recognizing the gesture.
|
|
86
|
+
* @param offset
|
|
87
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/pan-gesture#failoffsetyvalue-number--number
|
|
88
|
+
*/
|
|
89
|
+
failOffsetY(
|
|
90
|
+
offset: number | [failOffsetYStart: number, failOffsetYEnd: number]
|
|
91
|
+
) {
|
|
71
92
|
if (Array.isArray(offset)) {
|
|
72
93
|
this.config.failOffsetYStart = offset[0];
|
|
73
94
|
this.config.failOffsetYEnd = offset[1];
|
|
@@ -79,7 +100,14 @@ export class PanGesture extends ContinousBaseGesture<
|
|
|
79
100
|
return this;
|
|
80
101
|
}
|
|
81
102
|
|
|
82
|
-
|
|
103
|
+
/**
|
|
104
|
+
* When the finger moves outside this range (in points) along X axis and gesture hasn't yet activated it will fail recognizing the gesture.
|
|
105
|
+
* @param offset
|
|
106
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/pan-gesture#failoffsetxvalue-number--number
|
|
107
|
+
*/
|
|
108
|
+
failOffsetX(
|
|
109
|
+
offset: number | [failOffsetXStart: number, failOffsetXEnd: number]
|
|
110
|
+
) {
|
|
83
111
|
if (Array.isArray(offset)) {
|
|
84
112
|
this.config.failOffsetXStart = offset[0];
|
|
85
113
|
this.config.failOffsetXEnd = offset[1];
|
|
@@ -91,46 +119,89 @@ export class PanGesture extends ContinousBaseGesture<
|
|
|
91
119
|
return this;
|
|
92
120
|
}
|
|
93
121
|
|
|
122
|
+
/**
|
|
123
|
+
* A number of fingers that is required to be placed before gesture can activate. Should be a higher or equal to 0 integer.
|
|
124
|
+
* @param minPointers
|
|
125
|
+
*/
|
|
94
126
|
minPointers(minPointers: number) {
|
|
95
127
|
this.config.minPointers = minPointers;
|
|
96
128
|
return this;
|
|
97
129
|
}
|
|
98
130
|
|
|
131
|
+
/**
|
|
132
|
+
* When the given number of fingers is placed on the screen and gesture hasn't yet activated it will fail recognizing the gesture.
|
|
133
|
+
* Should be a higher or equal to 0 integer.
|
|
134
|
+
* @param maxPointers
|
|
135
|
+
*/
|
|
99
136
|
maxPointers(maxPointers: number) {
|
|
100
137
|
this.config.maxPointers = maxPointers;
|
|
101
138
|
return this;
|
|
102
139
|
}
|
|
103
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Minimum distance the finger (or multiple finger) need to travel before the gesture activates.
|
|
143
|
+
* Expressed in points.
|
|
144
|
+
* @param distance
|
|
145
|
+
*/
|
|
104
146
|
minDistance(distance: number) {
|
|
105
147
|
this.config.minDist = distance;
|
|
106
148
|
return this;
|
|
107
149
|
}
|
|
108
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Minimum velocity the finger has to reach in order to activate handler.
|
|
153
|
+
* @param velocity
|
|
154
|
+
*/
|
|
109
155
|
minVelocity(velocity: number) {
|
|
110
156
|
this.config.minVelocity = velocity;
|
|
111
157
|
return this;
|
|
112
158
|
}
|
|
113
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Minimum velocity along X axis the finger has to reach in order to activate handler.
|
|
162
|
+
* @param velocity
|
|
163
|
+
*/
|
|
114
164
|
minVelocityX(velocity: number) {
|
|
115
165
|
this.config.minVelocityX = velocity;
|
|
116
166
|
return this;
|
|
117
167
|
}
|
|
118
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Minimum velocity along Y axis the finger has to reach in order to activate handler.
|
|
171
|
+
* @param velocity
|
|
172
|
+
*/
|
|
119
173
|
minVelocityY(velocity: number) {
|
|
120
174
|
this.config.minVelocityY = velocity;
|
|
121
175
|
return this;
|
|
122
176
|
}
|
|
123
177
|
|
|
178
|
+
/**
|
|
179
|
+
* #### Android only
|
|
180
|
+
* Android, by default, will calculate translation values based on the position of the leading pointer (the first one that was placed on the screen).
|
|
181
|
+
* This modifier allows that behavior to be changed to the one that is default on iOS - the averaged position of all active pointers will be used to calculate the translation values.
|
|
182
|
+
* @param value
|
|
183
|
+
*/
|
|
124
184
|
averageTouches(value: boolean) {
|
|
125
185
|
this.config.avgTouches = value;
|
|
126
186
|
return this;
|
|
127
187
|
}
|
|
128
188
|
|
|
189
|
+
/**
|
|
190
|
+
* #### iOS only
|
|
191
|
+
* Enables two-finger gestures on supported devices, for example iPads with trackpads.
|
|
192
|
+
* @param value
|
|
193
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/pan-gesture/#enabletrackpadtwofingergesturevalue-boolean-ios-only
|
|
194
|
+
*/
|
|
129
195
|
enableTrackpadTwoFingerGesture(value: boolean) {
|
|
130
196
|
this.config.enableTrackpadTwoFingerGesture = value;
|
|
131
197
|
return this;
|
|
132
198
|
}
|
|
133
199
|
|
|
200
|
+
/**
|
|
201
|
+
* Duration in milliseconds of the LongPress gesture before Pan is allowed to activate.
|
|
202
|
+
* @param duration
|
|
203
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/pan-gesture/#activateafterlongpressduration-number
|
|
204
|
+
*/
|
|
134
205
|
activateAfterLongPress(duration: number) {
|
|
135
206
|
this.config.activateAfterLongPress = duration;
|
|
136
207
|
return this;
|
|
@@ -14,36 +14,71 @@ export class TapGesture extends BaseGesture<TapGestureHandlerEventPayload> {
|
|
|
14
14
|
this.shouldCancelWhenOutside(true);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Minimum number of pointers (fingers) required to be placed before the gesture activates.
|
|
19
|
+
* Should be a positive integer. The default value is 1.
|
|
20
|
+
* @param minPointers
|
|
21
|
+
*/
|
|
17
22
|
minPointers(minPointers: number) {
|
|
18
23
|
this.config.minPointers = minPointers;
|
|
19
24
|
return this;
|
|
20
25
|
}
|
|
21
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Number of tap gestures required to activate the gesture.
|
|
29
|
+
* The default value is 1.
|
|
30
|
+
* @param count
|
|
31
|
+
*/
|
|
22
32
|
numberOfTaps(count: number) {
|
|
23
33
|
this.config.numberOfTaps = count;
|
|
24
34
|
return this;
|
|
25
35
|
}
|
|
26
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Maximum distance, expressed in points, that defines how far the finger is allowed to travel during a tap gesture.
|
|
39
|
+
* @param maxDist
|
|
40
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/tap-gesture#maxdistancevalue-number
|
|
41
|
+
*/
|
|
27
42
|
maxDistance(maxDist: number) {
|
|
28
43
|
this.config.maxDist = maxDist;
|
|
29
44
|
return this;
|
|
30
45
|
}
|
|
31
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Maximum time, expressed in milliseconds, that defines how fast a finger must be released after a touch.
|
|
49
|
+
* The default value is 500.
|
|
50
|
+
* @param duration
|
|
51
|
+
*/
|
|
32
52
|
maxDuration(duration: number) {
|
|
33
53
|
this.config.maxDurationMs = duration;
|
|
34
54
|
return this;
|
|
35
55
|
}
|
|
36
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Maximum time, expressed in milliseconds, that can pass before the next tap — if many taps are required.
|
|
59
|
+
* The default value is 500.
|
|
60
|
+
* @param delay
|
|
61
|
+
*/
|
|
37
62
|
maxDelay(delay: number) {
|
|
38
63
|
this.config.maxDelayMs = delay;
|
|
39
64
|
return this;
|
|
40
65
|
}
|
|
41
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Maximum distance, expressed in points, that defines how far the finger is allowed to travel along the X axis during a tap gesture.
|
|
69
|
+
* @param delta
|
|
70
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/tap-gesture#maxdeltaxvalue-number
|
|
71
|
+
*/
|
|
42
72
|
maxDeltaX(delta: number) {
|
|
43
73
|
this.config.maxDeltaX = delta;
|
|
44
74
|
return this;
|
|
45
75
|
}
|
|
46
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Maximum distance, expressed in points, that defines how far the finger is allowed to travel along the Y axis during a tap gesture.
|
|
79
|
+
* @param delta
|
|
80
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/tap-gesture#maxdeltayvalue-number
|
|
81
|
+
*/
|
|
47
82
|
maxDeltaY(delta: number) {
|
|
48
83
|
this.config.maxDeltaY = delta;
|
|
49
84
|
return this;
|
package/src/utils.ts
CHANGED
|
@@ -18,7 +18,10 @@ export function withPrevAndCurrent<T, Transformed>(
|
|
|
18
18
|
const currentArr = [...array];
|
|
19
19
|
const transformedArr: Transformed[] = [];
|
|
20
20
|
currentArr.forEach((current, i) => {
|
|
21
|
-
|
|
21
|
+
// This type cast is fine and solves problem mentioned in https://github.com/software-mansion/react-native-gesture-handler/pull/2867 (namely that `previous` can be undefined).
|
|
22
|
+
// Unfortunately, linter on our CI does not allow this type of casting as it is unnecessary. To bypass that we use eslint-disable.
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
24
|
+
const previous = previousArr[i] as Transformed | null;
|
|
22
25
|
const transformed = mapFn(previous, current);
|
|
23
26
|
previousArr.push(transformed);
|
|
24
27
|
transformedArr.push(transformed);
|
|
@@ -50,5 +53,9 @@ export function isFabric(): boolean {
|
|
|
50
53
|
export function isRemoteDebuggingEnabled(): boolean {
|
|
51
54
|
// react-native-reanimated checks if in remote debugging in the same way
|
|
52
55
|
// @ts-ignore global is available but node types are not included
|
|
53
|
-
|
|
56
|
+
const localGlobal = global as any;
|
|
57
|
+
return (
|
|
58
|
+
(!localGlobal.nativeCallSyncHook || !!localGlobal.__REMOTEDEV__) &&
|
|
59
|
+
!localGlobal.RN$Bridgeless
|
|
60
|
+
);
|
|
54
61
|
}
|