react-native-gesture-handler 2.16.2 → 2.17.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. package/README.md +9 -3
  2. package/android/build.gradle +103 -0
  3. package/android/gradle.properties +7 -0
  4. package/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerDelegate.java +7 -7
  5. package/android/src/main/java/com/swmansion/gesturehandler/core/NativeViewGestureHandler.kt +16 -8
  6. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt +9 -5
  7. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerInteractionManager.kt +4 -0
  8. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt +1 -1
  9. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerTouchEvent.kt +1 -0
  10. package/apple/RNGestureHandlerButtonComponentView.mm +10 -0
  11. package/apple/RNGestureHandlerModule.mm +2 -3
  12. package/lib/commonjs/components/GestureButtons.js +27 -12
  13. package/lib/commonjs/components/GestureButtons.js.map +1 -1
  14. package/lib/commonjs/handlers/createHandler.js +1 -3
  15. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  16. package/lib/commonjs/handlers/gestureHandlerCommon.js +3 -3
  17. package/lib/commonjs/handlers/gestureHandlerCommon.js.map +1 -1
  18. package/lib/commonjs/handlers/gestures/GestureDetector/Wrap.js +42 -0
  19. package/lib/commonjs/handlers/gestures/GestureDetector/Wrap.js.map +1 -0
  20. package/lib/commonjs/handlers/gestures/GestureDetector/attachHandlers.js +83 -0
  21. package/lib/commonjs/handlers/gestures/GestureDetector/attachHandlers.js.map +1 -0
  22. package/lib/commonjs/handlers/gestures/GestureDetector/dropHandlers.js +25 -0
  23. package/lib/commonjs/handlers/gestures/GestureDetector/dropHandlers.js.map +1 -0
  24. package/lib/commonjs/handlers/gestures/GestureDetector/index.js +143 -0
  25. package/lib/commonjs/handlers/gestures/GestureDetector/index.js.map +1 -0
  26. package/lib/commonjs/handlers/gestures/GestureDetector/needsToReattach.js +25 -0
  27. package/lib/commonjs/handlers/gestures/GestureDetector/needsToReattach.js.map +1 -0
  28. package/lib/commonjs/handlers/gestures/GestureDetector/types.js +6 -0
  29. package/lib/commonjs/handlers/gestures/GestureDetector/types.js.map +1 -0
  30. package/lib/commonjs/handlers/gestures/GestureDetector/updateHandlers.js +80 -0
  31. package/lib/commonjs/handlers/gestures/GestureDetector/updateHandlers.js.map +1 -0
  32. package/lib/commonjs/handlers/gestures/GestureDetector/useAnimatedGesture.js +180 -0
  33. package/lib/commonjs/handlers/gestures/GestureDetector/useAnimatedGesture.js.map +1 -0
  34. package/lib/commonjs/handlers/gestures/GestureDetector/useDetectorUpdater.js +55 -0
  35. package/lib/commonjs/handlers/gestures/GestureDetector/useDetectorUpdater.js.map +1 -0
  36. package/lib/commonjs/handlers/gestures/GestureDetector/useViewRefHandler.js +47 -0
  37. package/lib/commonjs/handlers/gestures/GestureDetector/useViewRefHandler.js.map +1 -0
  38. package/lib/commonjs/handlers/gestures/GestureDetector/utils.js +176 -0
  39. package/lib/commonjs/handlers/gestures/GestureDetector/utils.js.map +1 -0
  40. package/lib/commonjs/handlers/gestures/gestureComposition.js +3 -1
  41. package/lib/commonjs/handlers/gestures/gestureComposition.js.map +1 -1
  42. package/lib/commonjs/handlers/gestures/gestureStateManager.js +8 -0
  43. package/lib/commonjs/handlers/gestures/gestureStateManager.js.map +1 -1
  44. package/lib/commonjs/handlers/gestures/reanimatedWrapper.js.map +1 -1
  45. package/lib/commonjs/utils.js +36 -0
  46. package/lib/commonjs/utils.js.map +1 -1
  47. package/lib/commonjs/web/detectors/RotationGestureDetector.js +6 -8
  48. package/lib/commonjs/web/detectors/RotationGestureDetector.js.map +1 -1
  49. package/lib/commonjs/web/detectors/ScaleGestureDetector.js +5 -6
  50. package/lib/commonjs/web/detectors/ScaleGestureDetector.js.map +1 -1
  51. package/lib/commonjs/web/handlers/FlingGestureHandler.js +1 -0
  52. package/lib/commonjs/web/handlers/FlingGestureHandler.js.map +1 -1
  53. package/lib/commonjs/web/handlers/GestureHandler.js +56 -64
  54. package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
  55. package/lib/commonjs/web/handlers/LongPressGestureHandler.js +1 -0
  56. package/lib/commonjs/web/handlers/LongPressGestureHandler.js.map +1 -1
  57. package/lib/commonjs/web/handlers/ManualGestureHandler.js +1 -0
  58. package/lib/commonjs/web/handlers/ManualGestureHandler.js.map +1 -1
  59. package/lib/commonjs/web/handlers/NativeViewGestureHandler.js +7 -4
  60. package/lib/commonjs/web/handlers/NativeViewGestureHandler.js.map +1 -1
  61. package/lib/commonjs/web/handlers/PanGestureHandler.js +28 -18
  62. package/lib/commonjs/web/handlers/PanGestureHandler.js.map +1 -1
  63. package/lib/commonjs/web/handlers/PinchGestureHandler.js +1 -0
  64. package/lib/commonjs/web/handlers/PinchGestureHandler.js.map +1 -1
  65. package/lib/commonjs/web/handlers/RotationGestureHandler.js +1 -0
  66. package/lib/commonjs/web/handlers/RotationGestureHandler.js.map +1 -1
  67. package/lib/commonjs/web/handlers/TapGestureHandler.js +18 -12
  68. package/lib/commonjs/web/handlers/TapGestureHandler.js.map +1 -1
  69. package/lib/commonjs/web/interfaces.js.map +1 -1
  70. package/lib/commonjs/web/tools/GestureHandlerOrchestrator.js +1 -6
  71. package/lib/commonjs/web/tools/GestureHandlerOrchestrator.js.map +1 -1
  72. package/lib/commonjs/web/tools/PointerEventManager.js +7 -2
  73. package/lib/commonjs/web/tools/PointerEventManager.js.map +1 -1
  74. package/lib/commonjs/web/tools/PointerTracker.js +89 -57
  75. package/lib/commonjs/web/tools/PointerTracker.js.map +1 -1
  76. package/lib/commonjs/web/tools/TouchEventManager.js +6 -2
  77. package/lib/commonjs/web/tools/TouchEventManager.js.map +1 -1
  78. package/lib/commonjs/web/tools/Vector.js +2 -1
  79. package/lib/commonjs/web/tools/Vector.js.map +1 -1
  80. package/lib/commonjs/web/utils.js +31 -0
  81. package/lib/commonjs/web/utils.js.map +1 -1
  82. package/lib/module/components/GestureButtons.js +24 -6
  83. package/lib/module/components/GestureButtons.js.map +1 -1
  84. package/lib/module/handlers/createHandler.js +2 -4
  85. package/lib/module/handlers/createHandler.js.map +1 -1
  86. package/lib/module/handlers/gestureHandlerCommon.js +1 -1
  87. package/lib/module/handlers/gestureHandlerCommon.js.map +1 -1
  88. package/lib/module/handlers/gestures/GestureDetector/Wrap.js +26 -0
  89. package/lib/module/handlers/gestures/GestureDetector/Wrap.js.map +1 -0
  90. package/lib/module/handlers/gestures/GestureDetector/attachHandlers.js +65 -0
  91. package/lib/module/handlers/gestures/GestureDetector/attachHandlers.js.map +1 -0
  92. package/lib/module/handlers/gestures/GestureDetector/dropHandlers.js +12 -0
  93. package/lib/module/handlers/gestures/GestureDetector/dropHandlers.js.map +1 -0
  94. package/lib/module/handlers/gestures/GestureDetector/index.js +115 -0
  95. package/lib/module/handlers/gestures/GestureDetector/index.js.map +1 -0
  96. package/lib/module/handlers/gestures/GestureDetector/needsToReattach.js +18 -0
  97. package/lib/module/handlers/gestures/GestureDetector/needsToReattach.js.map +1 -0
  98. package/lib/module/handlers/gestures/GestureDetector/types.js +2 -0
  99. package/lib/module/handlers/gestures/GestureDetector/types.js.map +1 -0
  100. package/lib/module/handlers/gestures/GestureDetector/updateHandlers.js +64 -0
  101. package/lib/module/handlers/gestures/GestureDetector/updateHandlers.js.map +1 -0
  102. package/lib/module/handlers/gestures/GestureDetector/useAnimatedGesture.js +165 -0
  103. package/lib/module/handlers/gestures/GestureDetector/useAnimatedGesture.js.map +1 -0
  104. package/lib/module/handlers/gestures/GestureDetector/useDetectorUpdater.js +41 -0
  105. package/lib/module/handlers/gestures/GestureDetector/useDetectorUpdater.js.map +1 -0
  106. package/lib/module/handlers/gestures/GestureDetector/useViewRefHandler.js +36 -0
  107. package/lib/module/handlers/gestures/GestureDetector/useViewRefHandler.js.map +1 -0
  108. package/lib/module/handlers/gestures/GestureDetector/utils.js +142 -0
  109. package/lib/module/handlers/gestures/GestureDetector/utils.js.map +1 -0
  110. package/lib/module/handlers/gestures/gestureComposition.js +3 -1
  111. package/lib/module/handlers/gestures/gestureComposition.js.map +1 -1
  112. package/lib/module/handlers/gestures/gestureStateManager.js +8 -0
  113. package/lib/module/handlers/gestures/gestureStateManager.js.map +1 -1
  114. package/lib/module/handlers/gestures/reanimatedWrapper.js.map +1 -1
  115. package/lib/module/utils.js +34 -0
  116. package/lib/module/utils.js.map +1 -1
  117. package/lib/module/web/detectors/RotationGestureDetector.js +6 -8
  118. package/lib/module/web/detectors/RotationGestureDetector.js.map +1 -1
  119. package/lib/module/web/detectors/ScaleGestureDetector.js +5 -6
  120. package/lib/module/web/detectors/ScaleGestureDetector.js.map +1 -1
  121. package/lib/module/web/handlers/FlingGestureHandler.js +1 -0
  122. package/lib/module/web/handlers/FlingGestureHandler.js.map +1 -1
  123. package/lib/module/web/handlers/GestureHandler.js +56 -64
  124. package/lib/module/web/handlers/GestureHandler.js.map +1 -1
  125. package/lib/module/web/handlers/LongPressGestureHandler.js +1 -0
  126. package/lib/module/web/handlers/LongPressGestureHandler.js.map +1 -1
  127. package/lib/module/web/handlers/ManualGestureHandler.js +1 -0
  128. package/lib/module/web/handlers/ManualGestureHandler.js.map +1 -1
  129. package/lib/module/web/handlers/NativeViewGestureHandler.js +7 -4
  130. package/lib/module/web/handlers/NativeViewGestureHandler.js.map +1 -1
  131. package/lib/module/web/handlers/PanGestureHandler.js +28 -18
  132. package/lib/module/web/handlers/PanGestureHandler.js.map +1 -1
  133. package/lib/module/web/handlers/PinchGestureHandler.js +1 -0
  134. package/lib/module/web/handlers/PinchGestureHandler.js.map +1 -1
  135. package/lib/module/web/handlers/RotationGestureHandler.js +1 -0
  136. package/lib/module/web/handlers/RotationGestureHandler.js.map +1 -1
  137. package/lib/module/web/handlers/TapGestureHandler.js +18 -12
  138. package/lib/module/web/handlers/TapGestureHandler.js.map +1 -1
  139. package/lib/module/web/interfaces.js.map +1 -1
  140. package/lib/module/web/tools/GestureHandlerOrchestrator.js +1 -6
  141. package/lib/module/web/tools/GestureHandlerOrchestrator.js.map +1 -1
  142. package/lib/module/web/tools/PointerEventManager.js +8 -3
  143. package/lib/module/web/tools/PointerEventManager.js.map +1 -1
  144. package/lib/module/web/tools/PointerTracker.js +89 -57
  145. package/lib/module/web/tools/PointerTracker.js.map +1 -1
  146. package/lib/module/web/tools/TouchEventManager.js +7 -3
  147. package/lib/module/web/tools/TouchEventManager.js.map +1 -1
  148. package/lib/module/web/tools/Vector.js +2 -1
  149. package/lib/module/web/tools/Vector.js.map +1 -1
  150. package/lib/module/web/utils.js +29 -0
  151. package/lib/module/web/utils.js.map +1 -1
  152. package/lib/typescript/components/GestureButtons.d.ts +3 -34
  153. package/lib/typescript/handlers/gestureHandlerCommon.d.ts +3 -2
  154. package/lib/typescript/handlers/gestures/GestureDetector/Wrap.d.ts +13 -0
  155. package/lib/typescript/handlers/gestures/GestureDetector/attachHandlers.d.ts +13 -0
  156. package/lib/typescript/handlers/gestures/GestureDetector/dropHandlers.d.ts +2 -0
  157. package/lib/typescript/handlers/gestures/{GestureDetector.d.ts → GestureDetector/index.d.ts} +4 -12
  158. package/lib/typescript/handlers/gestures/GestureDetector/needsToReattach.d.ts +3 -0
  159. package/lib/typescript/handlers/gestures/GestureDetector/types.d.ts +20 -0
  160. package/lib/typescript/handlers/gestures/GestureDetector/updateHandlers.d.ts +4 -0
  161. package/lib/typescript/handlers/gestures/GestureDetector/useAnimatedGesture.d.ts +2 -0
  162. package/lib/typescript/handlers/gestures/GestureDetector/useDetectorUpdater.d.ts +5 -0
  163. package/lib/typescript/handlers/gestures/GestureDetector/useViewRefHandler.d.ts +3 -0
  164. package/lib/typescript/handlers/gestures/GestureDetector/utils.d.ts +12 -0
  165. package/lib/typescript/handlers/gestures/reanimatedWrapper.d.ts +1 -1
  166. package/lib/typescript/utils.d.ts +10 -0
  167. package/lib/typescript/web/handlers/GestureHandler.d.ts +1 -0
  168. package/lib/typescript/web/interfaces.d.ts +1 -0
  169. package/lib/typescript/web/tools/PointerTracker.d.ts +34 -31
  170. package/lib/typescript/web/utils.d.ts +4 -0
  171. package/package.json +5 -5
  172. package/src/components/GestureButtons.tsx +36 -4
  173. package/src/handlers/createHandler.tsx +1 -3
  174. package/src/handlers/gestureHandlerCommon.ts +4 -1
  175. package/src/handlers/gestures/GestureDetector/Wrap.tsx +35 -0
  176. package/src/handlers/gestures/GestureDetector/attachHandlers.ts +112 -0
  177. package/src/handlers/gestures/GestureDetector/dropHandlers.ts +14 -0
  178. package/src/handlers/gestures/GestureDetector/index.tsx +187 -0
  179. package/src/handlers/gestures/GestureDetector/needsToReattach.ts +27 -0
  180. package/src/handlers/gestures/GestureDetector/types.ts +32 -0
  181. package/src/handlers/gestures/GestureDetector/updateHandlers.ts +94 -0
  182. package/src/handlers/gestures/GestureDetector/useAnimatedGesture.ts +206 -0
  183. package/src/handlers/gestures/GestureDetector/useDetectorUpdater.ts +69 -0
  184. package/src/handlers/gestures/GestureDetector/useViewRefHandler.ts +54 -0
  185. package/src/handlers/gestures/GestureDetector/utils.ts +185 -0
  186. package/src/handlers/gestures/gestureComposition.ts +2 -0
  187. package/src/handlers/gestures/gestureStateManager.ts +12 -4
  188. package/src/handlers/gestures/reanimatedWrapper.ts +19 -17
  189. package/src/utils.ts +39 -0
  190. package/src/web/detectors/RotationGestureDetector.ts +6 -8
  191. package/src/web/detectors/ScaleGestureDetector.ts +5 -6
  192. package/src/web/handlers/FlingGestureHandler.ts +2 -0
  193. package/src/web/handlers/GestureHandler.ts +53 -62
  194. package/src/web/handlers/LongPressGestureHandler.ts +2 -0
  195. package/src/web/handlers/ManualGestureHandler.ts +2 -0
  196. package/src/web/handlers/NativeViewGestureHandler.ts +8 -4
  197. package/src/web/handlers/PanGestureHandler.ts +32 -19
  198. package/src/web/handlers/PinchGestureHandler.ts +2 -0
  199. package/src/web/handlers/RotationGestureHandler.ts +2 -0
  200. package/src/web/handlers/TapGestureHandler.ts +20 -12
  201. package/src/web/interfaces.ts +1 -0
  202. package/src/web/tools/GestureHandlerOrchestrator.ts +1 -7
  203. package/src/web/tools/PointerEventManager.ts +10 -3
  204. package/src/web/tools/PointerTracker.ts +81 -74
  205. package/src/web/tools/TouchEventManager.ts +5 -3
  206. package/src/web/tools/Vector.ts +2 -4
  207. package/src/web/utils.ts +34 -0
  208. package/lib/commonjs/handlers/gestures/GestureDetector.js +0 -704
  209. package/lib/commonjs/handlers/gestures/GestureDetector.js.map +0 -1
  210. package/lib/module/handlers/gestures/GestureDetector.js +0 -654
  211. package/lib/module/handlers/gestures/GestureDetector.js.map +0 -1
  212. package/src/handlers/gestures/GestureDetector.tsx +0 -889
@@ -76,11 +76,10 @@ export default class ScaleGestureDetector implements ScaleGestureListener {
76
76
 
77
77
  const div: number = pointerUp ? numOfPointers - 1 : numOfPointers;
78
78
 
79
- const sumX = tracker.getSumX(ignoredPointer);
80
- const sumY = tracker.getSumY(ignoredPointer);
79
+ const coordsSum = tracker.getAbsoluteCoordsSum();
81
80
 
82
- const focusX = sumX / div;
83
- const focusY = sumY / div;
81
+ const focusX = coordsSum.x / div;
82
+ const focusY = coordsSum.y / div;
84
83
 
85
84
  //Determine average deviation from focal point
86
85
 
@@ -92,8 +91,8 @@ export default class ScaleGestureDetector implements ScaleGestureListener {
92
91
  return;
93
92
  }
94
93
 
95
- devSumX += Math.abs(value.lastX - focusX);
96
- devSumY += Math.abs(value.lastY - focusY);
94
+ devSumX += Math.abs(value.abosoluteCoords.x - focusX);
95
+ devSumY += Math.abs(value.abosoluteCoords.y - focusY);
97
96
  });
98
97
 
99
98
  const devX: number = devSumX / div;
@@ -114,6 +114,8 @@ export default class FlingGestureHandler extends GestureHandler {
114
114
 
115
115
  super.onPointerDown(event);
116
116
  this.newPointerAction();
117
+
118
+ this.tryToSendTouchEvent(event);
117
119
  }
118
120
 
119
121
  protected onPointerAdd(event: AdaptedEvent): void {
@@ -289,32 +289,21 @@ export default abstract class GestureHandler implements IGestureHandler {
289
289
  GestureHandlerOrchestrator.getInstance().cancelMouseAndPenGestures(this);
290
290
  }
291
291
 
292
- if (this.config.needsPointerData) {
293
- this.sendTouchEvent(event);
294
- }
292
+ // TODO: Bring back touch events along with introducing `handleDown` method that will handle handler specific stuff
295
293
  }
296
294
  // Adding another pointer to existing ones
297
295
  protected onPointerAdd(event: AdaptedEvent): void {
298
- if (this.config.needsPointerData) {
299
- this.sendTouchEvent(event);
300
- }
296
+ this.tryToSendTouchEvent(event);
301
297
  }
302
298
  protected onPointerUp(event: AdaptedEvent): void {
303
- if (this.config.needsPointerData) {
304
- this.sendTouchEvent(event);
305
- }
299
+ this.tryToSendTouchEvent(event);
306
300
  }
307
301
  // Removing pointer, when there is more than one pointers
308
302
  protected onPointerRemove(event: AdaptedEvent): void {
309
- if (this.config.needsPointerData) {
310
- this.sendTouchEvent(event);
311
- }
303
+ this.tryToSendTouchEvent(event);
312
304
  }
313
305
  protected onPointerMove(event: AdaptedEvent): void {
314
- this.tryToSendMoveEvent(false);
315
- if (this.config.needsPointerData) {
316
- this.sendTouchEvent(event);
317
- }
306
+ this.tryToSendMoveEvent(false, event);
318
307
  }
319
308
  protected onPointerLeave(event: AdaptedEvent): void {
320
309
  if (this.shouldCancelWhenOutside) {
@@ -329,28 +318,19 @@ export default abstract class GestureHandler implements IGestureHandler {
329
318
  return;
330
319
  }
331
320
 
332
- if (this.config.needsPointerData) {
333
- this.sendTouchEvent(event);
334
- }
321
+ this.tryToSendTouchEvent(event);
335
322
  }
336
323
  protected onPointerEnter(event: AdaptedEvent): void {
337
- if (this.config.needsPointerData) {
338
- this.sendTouchEvent(event);
339
- }
324
+ this.tryToSendTouchEvent(event);
340
325
  }
341
326
  protected onPointerCancel(event: AdaptedEvent): void {
342
- if (this.config.needsPointerData) {
343
- this.sendTouchEvent(event);
344
- }
327
+ this.tryToSendTouchEvent(event);
345
328
 
346
329
  this.cancel();
347
330
  this.reset();
348
331
  }
349
332
  protected onPointerOutOfBounds(event: AdaptedEvent): void {
350
- this.tryToSendMoveEvent(true);
351
- if (this.config.needsPointerData) {
352
- this.sendTouchEvent(event);
353
- }
333
+ this.tryToSendMoveEvent(true, event);
354
334
  }
355
335
  protected onPointerMoveOver(_event: AdaptedEvent): void {
356
336
  // used only by hover gesture handler atm
@@ -358,14 +338,22 @@ export default abstract class GestureHandler implements IGestureHandler {
358
338
  protected onPointerMoveOut(_event: AdaptedEvent): void {
359
339
  // used only by hover gesture handler atm
360
340
  }
361
- private tryToSendMoveEvent(out: boolean): void {
362
- if (
363
- this.enabled &&
364
- this.active &&
365
- (!out || (out && !this.shouldCancelWhenOutside))
366
- ) {
341
+ private tryToSendMoveEvent(out: boolean, event: AdaptedEvent): void {
342
+ if ((out && this.shouldCancelWhenOutside) || !this.enabled) {
343
+ return;
344
+ }
345
+
346
+ if (this.active) {
367
347
  this.sendEvent(this.currentState, this.currentState);
368
348
  }
349
+
350
+ this.tryToSendTouchEvent(event);
351
+ }
352
+
353
+ protected tryToSendTouchEvent(event: AdaptedEvent): void {
354
+ if (this.config.needsPointerData) {
355
+ this.sendTouchEvent(event);
356
+ }
369
357
  }
370
358
 
371
359
  public sendTouchEvent(event: AdaptedEvent): void {
@@ -417,10 +405,9 @@ export default abstract class GestureHandler implements IGestureHandler {
417
405
  nativeEvent: {
418
406
  numberOfPointers: this.tracker.getTrackedPointersCount(),
419
407
  state: newState,
420
- pointerInside: this.delegate.isPointerInBounds({
421
- x: this.tracker.getLastAvgX(),
422
- y: this.tracker.getLastAvgY(),
423
- }),
408
+ pointerInside: this.delegate.isPointerInBounds(
409
+ this.tracker.getAbsoluteCoordsAverage()
410
+ ),
424
411
  ...this.transformNativeEvent(),
425
412
  handlerTag: this.handlerTag,
426
413
  target: this.viewRef,
@@ -454,10 +441,10 @@ export default abstract class GestureHandler implements IGestureHandler {
454
441
 
455
442
  all.push({
456
443
  id: id,
457
- x: element.lastX - rect.pageX,
458
- y: element.lastY - rect.pageY,
459
- absoluteX: element.lastX,
460
- absoluteY: element.lastY,
444
+ x: element.abosoluteCoords.x - rect.pageX,
445
+ y: element.abosoluteCoords.y - rect.pageY,
446
+ absoluteX: element.abosoluteCoords.x,
447
+ absoluteY: element.abosoluteCoords.y,
461
448
  });
462
449
  });
463
450
 
@@ -477,10 +464,10 @@ export default abstract class GestureHandler implements IGestureHandler {
477
464
 
478
465
  changed.push({
479
466
  id: id,
480
- x: element.lastX - rect.pageX,
481
- y: element.lastY - rect.pageY,
482
- absoluteX: element.lastX,
483
- absoluteY: element.lastY,
467
+ x: element.abosoluteCoords.x - rect.pageX,
468
+ y: element.abosoluteCoords.y - rect.pageY,
469
+ absoluteX: element.abosoluteCoords.x,
470
+ absoluteY: element.abosoluteCoords.y,
484
471
  });
485
472
  });
486
473
  }
@@ -524,6 +511,7 @@ export default abstract class GestureHandler implements IGestureHandler {
524
511
  changedTouches: changed,
525
512
  allTouches: all,
526
513
  numberOfTouches: numberOfTouches,
514
+ pointerType: this.pointerType,
527
515
  },
528
516
  timeStamp: Date.now(),
529
517
  };
@@ -546,18 +534,18 @@ export default abstract class GestureHandler implements IGestureHandler {
546
534
 
547
535
  all.push({
548
536
  id: id,
549
- x: element.lastX - rect.pageX,
550
- y: element.lastY - rect.pageY,
551
- absoluteX: element.lastX,
552
- absoluteY: element.lastY,
537
+ x: element.abosoluteCoords.x - rect.pageX,
538
+ y: element.abosoluteCoords.y - rect.pageY,
539
+ absoluteX: element.abosoluteCoords.x,
540
+ absoluteY: element.abosoluteCoords.y,
553
541
  });
554
542
 
555
543
  changed.push({
556
544
  id: id,
557
- x: element.lastX - rect.pageX,
558
- y: element.lastY - rect.pageY,
559
- absoluteX: element.lastX,
560
- absoluteY: element.lastY,
545
+ x: element.abosoluteCoords.x - rect.pageX,
546
+ y: element.abosoluteCoords.y - rect.pageY,
547
+ absoluteX: element.abosoluteCoords.x,
548
+ absoluteY: element.abosoluteCoords.y,
561
549
  });
562
550
  });
563
551
 
@@ -569,6 +557,7 @@ export default abstract class GestureHandler implements IGestureHandler {
569
557
  changedTouches: changed,
570
558
  allTouches: all,
571
559
  numberOfTouches: all.length,
560
+ pointerType: this.pointerType,
572
561
  },
573
562
  timeStamp: Date.now(),
574
563
  };
@@ -581,13 +570,14 @@ export default abstract class GestureHandler implements IGestureHandler {
581
570
 
582
571
  protected transformNativeEvent(): Record<string, unknown> {
583
572
  // those properties are shared by most handlers and if not this method will be overriden
584
- const rect = this.delegate.measureView();
573
+ const lastCoords = this.tracker.getAbsoluteCoordsAverage();
574
+ const lastRelativeCoords = this.tracker.getRelativeCoordsAverage();
585
575
 
586
576
  return {
587
- x: this.tracker.getLastAvgX() - rect.pageX,
588
- y: this.tracker.getLastAvgY() - rect.pageY,
589
- absoluteX: this.tracker.getLastAvgX(),
590
- absoluteY: this.tracker.getLastAvgY(),
577
+ x: lastRelativeCoords.x,
578
+ y: lastRelativeCoords.y,
579
+ absoluteX: lastCoords.x,
580
+ absoluteY: lastCoords.y,
591
581
  };
592
582
  }
593
583
 
@@ -732,8 +722,9 @@ export default abstract class GestureHandler implements IGestureHandler {
732
722
  }
733
723
 
734
724
  const rect = this.delegate.measureView();
735
- const offsetX: number = this.tracker.getLastX() - rect.pageX;
736
- const offsetY: number = this.tracker.getLastY() - rect.pageY;
725
+ const { x, y } = this.tracker.getLastAbsoluteCoords();
726
+ const offsetX: number = x - rect.pageX;
727
+ const offsetY: number = y - rect.pageY;
737
728
 
738
729
  if (
739
730
  offsetX >= left &&
@@ -67,6 +67,8 @@ export default class LongPressGestureHandler extends GestureHandler {
67
67
  this.tryBegin(event);
68
68
  this.tryActivate();
69
69
  this.checkDistanceFail(event);
70
+
71
+ this.tryToSendTouchEvent(event);
70
72
  }
71
73
 
72
74
  protected onPointerMove(event: AdaptedEvent): void {
@@ -14,6 +14,8 @@ export default class ManualGestureHandler extends GestureHandler {
14
14
  this.tracker.addToTracker(event);
15
15
  super.onPointerDown(event);
16
16
  this.begin();
17
+
18
+ this.tryToSendTouchEvent(event);
17
19
  }
18
20
 
19
21
  protected onPointerAdd(event: AdaptedEvent): void {
@@ -53,6 +53,8 @@ export default class NativeViewGestureHandler extends GestureHandler {
53
53
  this.tracker.addToTracker(event);
54
54
  super.onPointerDown(event);
55
55
  this.newPointerAction();
56
+
57
+ this.tryToSendTouchEvent(event);
56
58
  }
57
59
 
58
60
  protected onPointerAdd(event: AdaptedEvent): void {
@@ -62,8 +64,9 @@ export default class NativeViewGestureHandler extends GestureHandler {
62
64
  }
63
65
 
64
66
  private newPointerAction(): void {
65
- this.startX = this.tracker.getLastAvgX();
66
- this.startY = this.tracker.getLastAvgY();
67
+ const lastCoords = this.tracker.getAbsoluteCoordsAverage();
68
+ this.startX = lastCoords.x;
69
+ this.startY = lastCoords.y;
67
70
 
68
71
  if (this.currentState !== State.UNDETERMINED) {
69
72
  return;
@@ -78,8 +81,9 @@ export default class NativeViewGestureHandler extends GestureHandler {
78
81
  protected onPointerMove(event: AdaptedEvent): void {
79
82
  this.tracker.track(event);
80
83
 
81
- const dx = this.startX - this.tracker.getLastAvgX();
82
- const dy = this.startY - this.tracker.getLastAvgY();
84
+ const lastCoords = this.tracker.getAbsoluteCoordsAverage();
85
+ const dx = this.startX - lastCoords.x;
86
+ const dy = this.startY - lastCoords.y;
83
87
  const distSq = dx * dx + dy * dy;
84
88
 
85
89
  if (distSq >= this.minDistSq) {
@@ -219,14 +219,17 @@ export default class PanGestureHandler extends GestureHandler {
219
219
  this.tracker.addToTracker(event);
220
220
  super.onPointerDown(event);
221
221
 
222
- this.lastX = this.tracker.getLastAvgX();
223
- this.lastY = this.tracker.getLastAvgY();
222
+ const lastCoords = this.tracker.getAbsoluteCoordsAverage();
223
+ this.lastX = lastCoords.x;
224
+ this.lastY = lastCoords.y;
224
225
 
225
226
  this.startX = this.lastX;
226
227
  this.startY = this.lastY;
227
228
 
228
229
  this.tryBegin(event);
229
230
  this.checkBegan();
231
+
232
+ this.tryToSendTouchEvent(event);
230
233
  }
231
234
 
232
235
  protected onPointerAdd(event: AdaptedEvent): void {
@@ -237,8 +240,9 @@ export default class PanGestureHandler extends GestureHandler {
237
240
  this.offsetX += this.lastX - this.startX;
238
241
  this.offsetY += this.lastY - this.startY;
239
242
 
240
- this.lastX = this.tracker.getLastAvgX();
241
- this.lastY = this.tracker.getLastAvgY();
243
+ const lastCoords = this.tracker.getAbsoluteCoordsAverage();
244
+ this.lastX = lastCoords.x;
245
+ this.lastY = lastCoords.y;
242
246
 
243
247
  this.startX = this.lastX;
244
248
  this.startY = this.lastY;
@@ -256,10 +260,10 @@ export default class PanGestureHandler extends GestureHandler {
256
260
 
257
261
  protected onPointerUp(event: AdaptedEvent): void {
258
262
  super.onPointerUp(event);
259
-
260
263
  if (this.currentState === State.ACTIVE) {
261
- this.lastX = this.tracker.getLastAvgX();
262
- this.lastY = this.tracker.getLastAvgY();
264
+ const lastCoords = this.tracker.getAbsoluteCoordsAverage();
265
+ this.lastX = lastCoords.x;
266
+ this.lastY = lastCoords.y;
263
267
  }
264
268
 
265
269
  this.tracker.removeFromTracker(event.pointerId);
@@ -271,6 +275,7 @@ export default class PanGestureHandler extends GestureHandler {
271
275
  this.fail();
272
276
  }
273
277
  }
278
+
274
279
  protected onPointerRemove(event: AdaptedEvent): void {
275
280
  super.onPointerRemove(event);
276
281
  this.tracker.removeFromTracker(event.pointerId);
@@ -278,8 +283,9 @@ export default class PanGestureHandler extends GestureHandler {
278
283
  this.offsetX += this.lastX - this.startX;
279
284
  this.offsetY += this.lastY - this.startY;
280
285
 
281
- this.lastX = this.tracker.getLastAvgX();
282
- this.lastY = this.tracker.getLastAvgY();
286
+ const lastCoords = this.tracker.getAbsoluteCoordsAverage();
287
+ this.lastX = lastCoords.x;
288
+ this.lastY = lastCoords.y;
283
289
 
284
290
  this.startX = this.lastX;
285
291
  this.startY = this.lastY;
@@ -297,10 +303,13 @@ export default class PanGestureHandler extends GestureHandler {
297
303
  protected onPointerMove(event: AdaptedEvent): void {
298
304
  this.tracker.track(event);
299
305
 
300
- this.lastX = this.tracker.getLastAvgX();
301
- this.lastY = this.tracker.getLastAvgY();
302
- this.velocityX = this.tracker.getVelocityX(event.pointerId);
303
- this.velocityY = this.tracker.getVelocityY(event.pointerId);
306
+ const lastCoords = this.tracker.getAbsoluteCoordsAverage();
307
+ this.lastX = lastCoords.x;
308
+ this.lastY = lastCoords.y;
309
+
310
+ const velocity = this.tracker.getVelocity(event.pointerId);
311
+ this.velocityX = velocity.x;
312
+ this.velocityY = velocity.y;
304
313
 
305
314
  this.checkBegan();
306
315
 
@@ -314,10 +323,13 @@ export default class PanGestureHandler extends GestureHandler {
314
323
 
315
324
  this.tracker.track(event);
316
325
 
317
- this.lastX = this.tracker.getLastAvgX();
318
- this.lastY = this.tracker.getLastAvgY();
319
- this.velocityX = this.tracker.getVelocityX(event.pointerId);
320
- this.velocityY = this.tracker.getVelocityY(event.pointerId);
326
+ const lastCoords = this.tracker.getAbsoluteCoordsAverage();
327
+ this.lastX = lastCoords.x;
328
+ this.lastY = lastCoords.y;
329
+
330
+ const velocity = this.tracker.getVelocity(event.pointerId);
331
+ this.velocityX = velocity.x;
332
+ this.velocityY = velocity.y;
321
333
 
322
334
  this.checkBegan();
323
335
 
@@ -451,8 +463,9 @@ export default class PanGestureHandler extends GestureHandler {
451
463
  }, this.activateAfterLongPress);
452
464
  }
453
465
  } else {
454
- this.velocityX = this.tracker.getVelocityX(event.pointerId);
455
- this.velocityY = this.tracker.getVelocityY(event.pointerId);
466
+ const velocity = this.tracker.getVelocity(event.pointerId);
467
+ this.velocityX = velocity.x;
468
+ this.velocityY = velocity.y;
456
469
  }
457
470
  }
458
471
 
@@ -71,6 +71,8 @@ export default class PinchGestureHandler extends GestureHandler {
71
71
  protected onPointerDown(event: AdaptedEvent): void {
72
72
  this.tracker.addToTracker(event);
73
73
  super.onPointerDown(event);
74
+
75
+ this.tryToSendTouchEvent(event);
74
76
  }
75
77
 
76
78
  protected onPointerAdd(event: AdaptedEvent): void {
@@ -78,6 +78,8 @@ export default class RotationGestureHandler extends GestureHandler {
78
78
  protected onPointerDown(event: AdaptedEvent): void {
79
79
  this.tracker.addToTracker(event);
80
80
  super.onPointerDown(event);
81
+
82
+ this.tryToSendTouchEvent(event);
81
83
  }
82
84
 
83
85
  protected onPointerAdd(event: AdaptedEvent): void {
@@ -121,6 +121,8 @@ export default class TapGestureHandler extends GestureHandler {
121
121
  this.lastY = event.y;
122
122
 
123
123
  this.updateState(event);
124
+
125
+ this.tryToSendTouchEvent(event);
124
126
  }
125
127
 
126
128
  protected onPointerAdd(event: AdaptedEvent): void {
@@ -131,19 +133,22 @@ export default class TapGestureHandler extends GestureHandler {
131
133
  this.offsetX += this.lastX - this.startX;
132
134
  this.offsetY += this.lastY - this.startY;
133
135
 
134
- this.lastX = this.tracker.getLastAvgX();
135
- this.lastY = this.tracker.getLastAvgY();
136
+ const lastCoords = this.tracker.getAbsoluteCoordsAverage();
137
+ this.lastX = lastCoords.x;
138
+ this.lastY = lastCoords.y;
136
139
 
137
- this.startX = this.tracker.getLastAvgX();
138
- this.startY = this.tracker.getLastAvgY();
140
+ this.startX = lastCoords.x;
141
+ this.startY = lastCoords.y;
139
142
 
140
143
  this.updateState(event);
141
144
  }
142
145
 
143
146
  protected onPointerUp(event: AdaptedEvent): void {
144
147
  super.onPointerUp(event);
145
- this.lastX = this.tracker.getLastAvgX();
146
- this.lastY = this.tracker.getLastAvgY();
148
+
149
+ const lastCoords = this.tracker.getAbsoluteCoordsAverage();
150
+ this.lastX = lastCoords.x;
151
+ this.lastY = lastCoords.y;
147
152
 
148
153
  this.tracker.removeFromTracker(event.pointerId);
149
154
 
@@ -157,8 +162,9 @@ export default class TapGestureHandler extends GestureHandler {
157
162
  this.offsetX += this.lastX - this.startX;
158
163
  this.offsetY += this.lastY = this.startY;
159
164
 
160
- this.lastX = this.tracker.getLastAvgX();
161
- this.lastY = this.tracker.getLastAvgY();
165
+ const lastCoords = this.tracker.getAbsoluteCoordsAverage();
166
+ this.lastX = lastCoords.x;
167
+ this.lastY = lastCoords.y;
162
168
 
163
169
  this.startX = this.lastX;
164
170
  this.startY = this.lastY;
@@ -170,8 +176,9 @@ export default class TapGestureHandler extends GestureHandler {
170
176
  this.trySettingPosition(event);
171
177
  this.tracker.track(event);
172
178
 
173
- this.lastX = this.tracker.getLastAvgX();
174
- this.lastY = this.tracker.getLastAvgY();
179
+ const lastCoords = this.tracker.getAbsoluteCoordsAverage();
180
+ this.lastX = lastCoords.x;
181
+ this.lastY = lastCoords.y;
175
182
 
176
183
  this.updateState(event);
177
184
 
@@ -182,8 +189,9 @@ export default class TapGestureHandler extends GestureHandler {
182
189
  this.trySettingPosition(event);
183
190
  this.tracker.track(event);
184
191
 
185
- this.lastX = this.tracker.getLastAvgX();
186
- this.lastY = this.tracker.getLastAvgY();
192
+ const lastCoords = this.tracker.getAbsoluteCoordsAverage();
193
+ this.lastX = lastCoords.x;
194
+ this.lastY = lastCoords.y;
187
195
 
188
196
  this.updateState(event);
189
197
 
@@ -113,6 +113,7 @@ interface NativeTouchEvent extends Record<string, TouchNativeArgs> {
113
113
  changedTouches: PointerData[];
114
114
  allTouches: PointerData[];
115
115
  numberOfTouches: number;
116
+ pointerType: PointerType;
116
117
  }
117
118
 
118
119
  export interface ResultEvent extends Record<string, NativeEvent | number> {
@@ -335,13 +335,7 @@ export default class GestureHandlerOrchestrator {
335
335
  // TODO: Find better way to handle that issue, for example by activation order and handler cancelling
336
336
 
337
337
  const isPointerWithinBothBounds = (pointer: number) => {
338
- const handlerX: number = handler.getTracker().getLastX(pointer);
339
- const handlerY: number = handler.getTracker().getLastY(pointer);
340
-
341
- const point = {
342
- x: handlerX,
343
- y: handlerY,
344
- };
338
+ const point = handler.getTracker().getLastAbsoluteCoords(pointer);
345
339
 
346
340
  return (
347
341
  handler.getDelegate().isPointerInBounds(point) &&
@@ -1,7 +1,11 @@
1
1
  import EventManager from './EventManager';
2
2
  import { MouseButton } from '../../handlers/gestureHandlerCommon';
3
3
  import { AdaptedEvent, EventTypes, Point } from '../interfaces';
4
- import { PointerTypeMapping, isPointerInBounds } from '../utils';
4
+ import {
5
+ PointerTypeMapping,
6
+ calculateViewScale,
7
+ isPointerInBounds,
8
+ } from '../utils';
5
9
  import { PointerType } from '../../PointerType';
6
10
 
7
11
  const POINTER_CAPTURE_EXCLUDE_LIST = new Set<string>(['SELECT', 'INPUT']);
@@ -234,11 +238,14 @@ export default class PointerEventManager extends EventManager<HTMLElement> {
234
238
  }
235
239
 
236
240
  protected mapEvent(event: PointerEvent, eventType: EventTypes): AdaptedEvent {
241
+ const rect = this.view.getBoundingClientRect();
242
+ const { scaleX, scaleY } = calculateViewScale(this.view);
243
+
237
244
  return {
238
245
  x: event.clientX,
239
246
  y: event.clientY,
240
- offsetX: event.offsetX,
241
- offsetY: event.offsetY,
247
+ offsetX: (event.clientX - rect.left) / scaleX,
248
+ offsetY: (event.clientY - rect.top) / scaleY,
242
249
  pointerId: event.pointerId,
243
250
  eventType: eventType,
244
251
  pointerType: