react-native-gesture-handler 2.16.2 → 2.17.0

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 +105 -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
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useViewRefHandler.ts"],"names":["isFabric","tagMessage","getShadowNodeFromRef","useCallback","findNodeHandle","useViewRefHandler","state","updateAttachedGestures","refHandler","ref","viewRef","previousViewTag","firstRender","__DEV__","global","isFormsStackingContext","node","console","error"],"mappings":"AAAA,SAASA,QAAT,EAAmBC,UAAnB,QAAqC,gBAArC;AACA,SAASC,oBAAT,QAAqC,+BAArC;AAGA,SAAgBC,WAAhB,QAAmC,OAAnC;AACA,SAASC,cAAT,QAA+B,cAA/B;AAMA;AACA;AACA;AACA,OAAO,SAASC,iBAAT,CACLC,KADK,EAELC,sBAFK,EAGL;AACA,QAAMC,UAAU,GAAGL,WAAW,CAC3BM,GAAD,IAAiC;AAC/B,QAAIA,GAAG,KAAK,IAAZ,EAAkB;AAChB;AACD;;AAEDH,IAAAA,KAAK,CAACI,OAAN,GAAgBD,GAAhB,CAL+B,CAO/B;;AACA,QAAIH,KAAK,CAACK,eAAN,KAA0B,CAAC,CAA/B,EAAkC;AAChCL,MAAAA,KAAK,CAACK,eAAN,GAAwBP,cAAc,CAACE,KAAK,CAACI,OAAP,CAAtC;AACD,KAV8B,CAY/B;AACA;;;AACA,QAAI,CAACJ,KAAK,CAACM,WAAX,EAAwB;AACtBL,MAAAA,sBAAsB,CAAC,IAAD,CAAtB;AACD;;AAED,QAAIM,OAAO,IAAIb,QAAQ,EAAnB,IAAyBc,MAAM,CAACC,sBAApC,EAA4D;AAC1D,YAAMC,IAAI,GAAGd,oBAAoB,CAACO,GAAD,CAAjC;;AACA,UAAIK,MAAM,CAACC,sBAAP,CAA8BC,IAA9B,MAAwC,KAA5C,EAAmD;AACjDC,QAAAA,OAAO,CAACC,KAAR,CACEjB,UAAU,CACR,uEACE,kGAFM,CADZ;AAMD;AACF;AACF,GA9B2B,EA+B5B,CAACK,KAAD,EAAQC,sBAAR,CA/B4B,CAA9B;AAkCA,SAAOC,UAAP;AACD","sourcesContent":["import { isFabric, tagMessage } from '../../../utils';\nimport { getShadowNodeFromRef } from '../../../getShadowNodeFromRef';\n\nimport { GestureDetectorState } from './types';\nimport React, { useCallback } from 'react';\nimport { findNodeHandle } from 'react-native';\n\ndeclare const global: {\n isFormsStackingContext: (node: unknown) => boolean | null; // JSI function\n};\n\n// Ref handler for the Wrap component attached under the GestureDetector.\n// It's responsible for setting the viewRef on the state and triggering the reattaching of handlers\n// if the view has changed.\nexport function useViewRefHandler(\n state: GestureDetectorState,\n updateAttachedGestures: (skipConfigUpdate?: boolean) => void\n) {\n const refHandler = useCallback(\n (ref: React.Component | null) => {\n if (ref === null) {\n return;\n }\n\n state.viewRef = ref;\n\n // if it's the first render, also set the previousViewTag to prevent reattaching gestures when not needed\n if (state.previousViewTag === -1) {\n state.previousViewTag = findNodeHandle(state.viewRef) as number;\n }\n\n // Pass true as `skipConfigUpdate`. Here we only want to trigger the eventual reattaching of handlers\n // in case the view has changed. If the view doesn't change, the update will be handled by detector.\n if (!state.firstRender) {\n updateAttachedGestures(true);\n }\n\n if (__DEV__ && isFabric() && global.isFormsStackingContext) {\n const node = getShadowNodeFromRef(ref);\n if (global.isFormsStackingContext(node) === false) {\n console.error(\n tagMessage(\n 'GestureDetector has received a child that may get view-flattened. ' +\n '\\nTo prevent it from misbehaving you need to wrap the child with a `<View collapsable={false}>`.'\n )\n );\n }\n }\n },\n [state, updateAttachedGestures]\n );\n\n return refHandler;\n}\n"]}
@@ -0,0 +1,142 @@
1
+ import { Platform } from 'react-native';
2
+ import { tagMessage } from '../../../utils';
3
+ import { BaseGesture } from '../gesture';
4
+ import { flingGestureHandlerProps } from '../../FlingGestureHandler';
5
+ import { forceTouchGestureHandlerProps } from '../../ForceTouchGestureHandler';
6
+ import { longPressGestureHandlerProps } from '../../LongPressGestureHandler';
7
+ import { panGestureHandlerProps, panGestureHandlerCustomNativeProps } from '../../PanGestureHandler';
8
+ import { tapGestureHandlerProps } from '../../TapGestureHandler';
9
+ import { hoverGestureHandlerProps } from '../hoverGesture';
10
+ import { nativeViewGestureHandlerProps } from '../../NativeViewGestureHandler';
11
+ import { baseGestureHandlerWithDetectorProps } from '../../gestureHandlerCommon';
12
+ import { isNewWebImplementationEnabled } from '../../../EnableNewWebImplementation';
13
+ import { getReactNativeVersion } from '../../../getReactNativeVersion';
14
+ import { RNRenderer } from '../../../RNRenderer';
15
+ import { useCallback, useRef, useState } from 'react';
16
+ import { Reanimated } from '../reanimatedWrapper';
17
+ import { onGestureHandlerEvent } from '../eventReceiver';
18
+ export const ALLOWED_PROPS = [...baseGestureHandlerWithDetectorProps, ...tapGestureHandlerProps, ...panGestureHandlerProps, ...panGestureHandlerCustomNativeProps, ...longPressGestureHandlerProps, ...forceTouchGestureHandlerProps, ...flingGestureHandlerProps, ...hoverGestureHandlerProps, ...nativeViewGestureHandlerProps];
19
+
20
+ function convertToHandlerTag(ref) {
21
+ if (typeof ref === 'number') {
22
+ return ref;
23
+ } else if (ref instanceof BaseGesture) {
24
+ return ref.handlerTag;
25
+ } else {
26
+ var _ref$current$handlerT, _ref$current;
27
+
28
+ // @ts-ignore in this case it should be a ref either to gesture object or
29
+ // a gesture handler component, in both cases handlerTag property exists
30
+ return (_ref$current$handlerT = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.handlerTag) !== null && _ref$current$handlerT !== void 0 ? _ref$current$handlerT : -1;
31
+ }
32
+ }
33
+
34
+ function extractValidHandlerTags(interactionGroup) {
35
+ var _interactionGroup$map, _interactionGroup$map2;
36
+
37
+ return (_interactionGroup$map = interactionGroup === null || interactionGroup === void 0 ? void 0 : (_interactionGroup$map2 = interactionGroup.map(convertToHandlerTag)) === null || _interactionGroup$map2 === void 0 ? void 0 : _interactionGroup$map2.filter(tag => tag > 0)) !== null && _interactionGroup$map !== void 0 ? _interactionGroup$map : [];
38
+ }
39
+
40
+ export function extractGestureRelations(gesture) {
41
+ const requireToFail = extractValidHandlerTags(gesture.config.requireToFail);
42
+ const simultaneousWith = extractValidHandlerTags(gesture.config.simultaneousWith);
43
+ const blocksHandlers = extractValidHandlerTags(gesture.config.blocksHandlers);
44
+ return {
45
+ waitFor: requireToFail,
46
+ simultaneousHandlers: simultaneousWith,
47
+ blocksHandlers: blocksHandlers
48
+ };
49
+ }
50
+ export function checkGestureCallbacksForWorklets(gesture) {
51
+ if (!__DEV__) {
52
+ return;
53
+ } // if a gesture is explicitly marked to run on the JS thread there is no need to check
54
+ // if callbacks are worklets as the user is aware they will be ran on the JS thread
55
+
56
+
57
+ if (gesture.config.runOnJS) {
58
+ return;
59
+ }
60
+
61
+ const areSomeNotWorklets = gesture.handlers.isWorklet.includes(false);
62
+ const areSomeWorklets = gesture.handlers.isWorklet.includes(true); // if some of the callbacks are worklets and some are not, and the gesture is not
63
+ // explicitly marked with `.runOnJS(true)` show an error
64
+
65
+ if (areSomeNotWorklets && areSomeWorklets) {
66
+ console.error(tagMessage(`Some of the callbacks in the gesture are worklets and some are not. Either make sure that all calbacks are marked as 'worklet' if you wish to run them on the UI thread or use '.runOnJS(true)' modifier on the gesture explicitly to run all callbacks on the JS thread.`));
67
+ }
68
+
69
+ if (Reanimated === undefined) {
70
+ // if Reanimated is not available, we can't run worklets, so we shouldn't show the warning
71
+ return;
72
+ }
73
+
74
+ const areAllNotWorklets = !areSomeWorklets && areSomeNotWorklets; // if none of the callbacks are worklets and the gesture is not explicitly marked with
75
+ // `.runOnJS(true)` show a warning
76
+
77
+ if (areAllNotWorklets) {
78
+ console.warn(tagMessage(`None of the callbacks in the gesture are worklets. If you wish to run them on the JS thread use '.runOnJS(true)' modifier on the gesture to make this explicit. Otherwise, mark the callbacks as 'worklet' to run them on the UI thread.`));
79
+ }
80
+ } // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
+
82
+ export function validateDetectorChildren(ref) {
83
+ // finds the first native view under the Wrap component and traverses the fiber tree upwards
84
+ // to check whether there is more than one native view as a pseudo-direct child of GestureDetector
85
+ // i.e. this is not ok:
86
+ // Wrap
87
+ // |
88
+ // / \
89
+ // / \
90
+ // / \
91
+ // / \
92
+ // NativeView NativeView
93
+ //
94
+ // but this is fine:
95
+ // Wrap
96
+ // |
97
+ // NativeView
98
+ // |
99
+ // / \
100
+ // / \
101
+ // / \
102
+ // / \
103
+ // NativeView NativeView
104
+ if (__DEV__ && Platform.OS !== 'web') {
105
+ const REACT_NATIVE_VERSION = getReactNativeVersion(); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
106
+
107
+ const wrapType = REACT_NATIVE_VERSION.minor > 63 || REACT_NATIVE_VERSION.major > 0 ? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
108
+ ref._reactInternals.elementType : // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
109
+ ref._reactInternalFiber.elementType; // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
110
+
111
+ let instance = RNRenderer.findHostInstance_DEPRECATED(ref)._internalFiberInstanceHandleDEV; // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
112
+
113
+
114
+ while (instance && instance.elementType !== wrapType) {
115
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
116
+ if (instance.sibling) {
117
+ throw new Error('GestureDetector has more than one native view as its children. This can happen if you are using a custom component that renders multiple views, like React.Fragment. You should wrap content of GestureDetector with a <View> or <Animated.View>.');
118
+ } // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
119
+
120
+
121
+ instance = instance.return;
122
+ }
123
+ }
124
+ }
125
+ export function useForceRender() {
126
+ const [renderState, setRenderState] = useState(false);
127
+ const forceRender = useCallback(() => {
128
+ setRenderState(!renderState);
129
+ }, [renderState, setRenderState]);
130
+ return forceRender;
131
+ }
132
+ export function useWebEventHandlers() {
133
+ return useRef({
134
+ onGestureHandlerEvent: e => {
135
+ onGestureHandlerEvent(e.nativeEvent);
136
+ },
137
+ onGestureHandlerStateChange: isNewWebImplementationEnabled() ? e => {
138
+ onGestureHandlerEvent(e.nativeEvent);
139
+ } : undefined
140
+ });
141
+ }
142
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["utils.ts"],"names":["Platform","tagMessage","BaseGesture","flingGestureHandlerProps","forceTouchGestureHandlerProps","longPressGestureHandlerProps","panGestureHandlerProps","panGestureHandlerCustomNativeProps","tapGestureHandlerProps","hoverGestureHandlerProps","nativeViewGestureHandlerProps","baseGestureHandlerWithDetectorProps","isNewWebImplementationEnabled","getReactNativeVersion","RNRenderer","useCallback","useRef","useState","Reanimated","onGestureHandlerEvent","ALLOWED_PROPS","convertToHandlerTag","ref","handlerTag","current","extractValidHandlerTags","interactionGroup","map","filter","tag","extractGestureRelations","gesture","requireToFail","config","simultaneousWith","blocksHandlers","waitFor","simultaneousHandlers","checkGestureCallbacksForWorklets","__DEV__","runOnJS","areSomeNotWorklets","handlers","isWorklet","includes","areSomeWorklets","console","error","undefined","areAllNotWorklets","warn","validateDetectorChildren","OS","REACT_NATIVE_VERSION","wrapType","minor","major","_reactInternals","elementType","_reactInternalFiber","instance","findHostInstance_DEPRECATED","_internalFiberInstanceHandleDEV","sibling","Error","return","useForceRender","renderState","setRenderState","forceRender","useWebEventHandlers","e","nativeEvent","onGestureHandlerStateChange"],"mappings":"AAAA,SAASA,QAAT,QAAyB,cAAzB;AAEA,SAASC,UAAT,QAA2B,gBAA3B;AACA,SAAqBC,WA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AAD,IAAyC;AAC9DpD,MAAAA,qBAAqB,CAACoD,CAAC,CAACC,WAAH,CAArB;AACD,KAH4B;AAI7BC,IAAAA,2BAA2B,EAAE7D,6BAA6B,KACrD2D,CAAD,IAAyC;AACvCpD,MAAAA,qBAAqB,CAACoD,CAAC,CAACC,WAAH,CAArB;AACD,KAHqD,GAItDxB;AARyB,GAAlB,CAAb;AAUD","sourcesContent":["import { Platform } from 'react-native';\n\nimport { tagMessage } from '../../../utils';\nimport { GestureRef, BaseGesture, GestureType } from '../gesture';\n\nimport { flingGestureHandlerProps } from '../../FlingGestureHandler';\nimport { forceTouchGestureHandlerProps } from '../../ForceTouchGestureHandler';\nimport { longPressGestureHandlerProps } from '../../LongPressGestureHandler';\nimport {\n panGestureHandlerProps,\n panGestureHandlerCustomNativeProps,\n} from '../../PanGestureHandler';\nimport { tapGestureHandlerProps } from '../../TapGestureHandler';\nimport { hoverGestureHandlerProps } from '../hoverGesture';\nimport { nativeViewGestureHandlerProps } from '../../NativeViewGestureHandler';\nimport {\n HandlerStateChangeEvent,\n baseGestureHandlerWithDetectorProps,\n} from '../../gestureHandlerCommon';\nimport { isNewWebImplementationEnabled } from '../../../EnableNewWebImplementation';\nimport { getReactNativeVersion } from '../../../getReactNativeVersion';\nimport { RNRenderer } from '../../../RNRenderer';\nimport { useCallback, useRef, useState } from 'react';\nimport { Reanimated } from '../reanimatedWrapper';\nimport { onGestureHandlerEvent } from '../eventReceiver';\nimport { WebEventHandler } from './types';\n\nexport const ALLOWED_PROPS = [\n ...baseGestureHandlerWithDetectorProps,\n ...tapGestureHandlerProps,\n ...panGestureHandlerProps,\n ...panGestureHandlerCustomNativeProps,\n ...longPressGestureHandlerProps,\n ...forceTouchGestureHandlerProps,\n ...flingGestureHandlerProps,\n ...hoverGestureHandlerProps,\n ...nativeViewGestureHandlerProps,\n];\n\nfunction convertToHandlerTag(ref: GestureRef): number {\n if (typeof ref === 'number') {\n return ref;\n } else if (ref instanceof BaseGesture) {\n return ref.handlerTag;\n } else {\n // @ts-ignore in this case it should be a ref either to gesture object or\n // a gesture handler component, in both cases handlerTag property exists\n return ref.current?.handlerTag ?? -1;\n }\n}\n\nfunction extractValidHandlerTags(interactionGroup: GestureRef[] | undefined) {\n return (\n interactionGroup?.map(convertToHandlerTag)?.filter((tag) => tag > 0) ?? []\n );\n}\n\nexport function extractGestureRelations(gesture: GestureType) {\n const requireToFail = extractValidHandlerTags(gesture.config.requireToFail);\n const simultaneousWith = extractValidHandlerTags(\n gesture.config.simultaneousWith\n );\n const blocksHandlers = extractValidHandlerTags(gesture.config.blocksHandlers);\n\n return {\n waitFor: requireToFail,\n simultaneousHandlers: simultaneousWith,\n blocksHandlers: blocksHandlers,\n };\n}\n\nexport function checkGestureCallbacksForWorklets(gesture: GestureType) {\n if (!__DEV__) {\n return;\n }\n // if a gesture is explicitly marked to run on the JS thread there is no need to check\n // if callbacks are worklets as the user is aware they will be ran on the JS thread\n if (gesture.config.runOnJS) {\n return;\n }\n\n const areSomeNotWorklets = gesture.handlers.isWorklet.includes(false);\n const areSomeWorklets = gesture.handlers.isWorklet.includes(true);\n\n // if some of the callbacks are worklets and some are not, and the gesture is not\n // explicitly marked with `.runOnJS(true)` show an error\n if (areSomeNotWorklets && areSomeWorklets) {\n console.error(\n tagMessage(\n `Some of the callbacks in the gesture are worklets and some are not. Either make sure that all calbacks are marked as 'worklet' if you wish to run them on the UI thread or use '.runOnJS(true)' modifier on the gesture explicitly to run all callbacks on the JS thread.`\n )\n );\n }\n\n if (Reanimated === undefined) {\n // if Reanimated is not available, we can't run worklets, so we shouldn't show the warning\n return;\n }\n\n const areAllNotWorklets = !areSomeWorklets && areSomeNotWorklets;\n // if none of the callbacks are worklets and the gesture is not explicitly marked with\n // `.runOnJS(true)` show a warning\n if (areAllNotWorklets) {\n console.warn(\n tagMessage(\n `None of the callbacks in the gesture are worklets. If you wish to run them on the JS thread use '.runOnJS(true)' modifier on the gesture to make this explicit. Otherwise, mark the callbacks as 'worklet' to run them on the UI thread.`\n )\n );\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function validateDetectorChildren(ref: any) {\n // finds the first native view under the Wrap component and traverses the fiber tree upwards\n // to check whether there is more than one native view as a pseudo-direct child of GestureDetector\n // i.e. this is not ok:\n // Wrap\n // |\n // / \\\n // / \\\n // / \\\n // / \\\n // NativeView NativeView\n //\n // but this is fine:\n // Wrap\n // |\n // NativeView\n // |\n // / \\\n // / \\\n // / \\\n // / \\\n // NativeView NativeView\n if (__DEV__ && Platform.OS !== 'web') {\n const REACT_NATIVE_VERSION = getReactNativeVersion();\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const wrapType =\n REACT_NATIVE_VERSION.minor > 63 || REACT_NATIVE_VERSION.major > 0\n ? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n ref._reactInternals.elementType\n : // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n ref._reactInternalFiber.elementType;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n let instance =\n RNRenderer.findHostInstance_DEPRECATED(\n ref\n )._internalFiberInstanceHandleDEV;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n while (instance && instance.elementType !== wrapType) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (instance.sibling) {\n throw new Error(\n 'GestureDetector has more than one native view as its children. This can happen if you are using a custom component that renders multiple views, like React.Fragment. You should wrap content of GestureDetector with a <View> or <Animated.View>.'\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n instance = instance.return;\n }\n }\n}\n\nexport function useForceRender() {\n const [renderState, setRenderState] = useState(false);\n const forceRender = useCallback(() => {\n setRenderState(!renderState);\n }, [renderState, setRenderState]);\n\n return forceRender;\n}\n\nexport function useWebEventHandlers() {\n return useRef<WebEventHandler>({\n onGestureHandlerEvent: (e: HandlerStateChangeEvent<unknown>) => {\n onGestureHandlerEvent(e.nativeEvent);\n },\n onGestureHandlerStateChange: isNewWebImplementationEnabled()\n ? (e: HandlerStateChangeEvent<unknown>) => {\n onGestureHandlerEvent(e.nativeEvent);\n }\n : undefined,\n });\n}\n"]}
@@ -26,7 +26,9 @@ export class ComposedGesture extends Gesture {
26
26
  prepareSingleGesture(gesture, simultaneousGestures, requireGesturesToFail) {
27
27
  if (gesture instanceof BaseGesture) {
28
28
  const newConfig = { ...gesture.config
29
- };
29
+ }; // no need to extend `blocksHandlers` here, because it's not changed in composition
30
+ // the same effect is achieved by reversing the order of 2 gestures in `Exclusive`
31
+
30
32
  newConfig.simultaneousWith = extendRelation(newConfig.simultaneousWith, simultaneousGestures);
31
33
  newConfig.requireToFail = extendRelation(newConfig.requireToFail, requireGesturesToFail);
32
34
  gesture.config = newConfig;
@@ -1 +1 @@
1
- {"version":3,"sources":["gestureComposition.ts"],"names":["BaseGesture","Gesture","extendRelation","currentRelation","extendWith","undefined","ComposedGesture","constructor","gestures","prepareSingleGesture","gesture","simultaneousGestures","requireGesturesToFail","newConfig","config","simultaneousWith","requireToFail","prepare","initialize","toGestureArray","flatMap","SimultaneousGesture","simultaneousArrays","map","filter","x","i","length","ExclusiveGesture","gestureArrays","concat"],"mappings":";;AAAA,SAASA,WAAT,EAAsBC,OAAtB,QAA8D,WAA9D;;AAEA,SAASC,cAAT,CACEC,eADF,EAEEC,UAFF,EAGE;AACA,MAAID,eAAe,KAAKE,SAAxB,EAAmC;AACjC,WAAO,CAAC,GAAGD,UAAJ,CAAP;AACD,GAFD,MAEO;AACL,WAAO,CAAC,GAAGD,eAAJ,EAAqB,GAAGC,UAAxB,CAAP;AACD;AACF;;AAED,OAAO,MAAME,eAAN,SAA8BL,OAA9B,CAAsC;AAK3CM,EAAAA,WAAW,CAAC,GAAGC,QAAJ,EAAyB;AAClC;;AADkC,sCAJJ,EAII;;AAAA,kDAHY,EAGZ;;AAAA,mDAFa,EAEb;;AAElC,SAAKA,QAAL,GAAgBA,QAAhB;AACD;;AAESC,E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EGgB,MAFH,CAEWC,CAAD,IAAOA,CAAC,KAAKf,OAFvB,EAGE;AACA;AACA;AACA;AANF,KAOGU,OAPH,CAOYK,CAAD,IAAOA,CAAC,CAACN,cAAF,EAPlB,CAFyB,CAA3B;;AAYA,SAAK,IAAIO,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAG,KAAKlB,QAAL,CAAcmB,MAAlC,EAA0CD,CAAC,EAA3C,EAA+C;AAC7C,WAAKjB,oBAAL,CACE,KAAKD,QAAL,CAAckB,CAAd,CADF,EAEEJ,kBAAkB,CAACI,CAAD,CAFpB,EAGE,KAAKd,qBAHP;AAKD;AACF;;AAvBsD;AA0BzD,OAAO,MAAMgB,gBAAN,SAA+BtB,eAA/B,CAA+C;AACpDW,EAAAA,OAAO,GAAG;AACR;AACA;AACA,UAAMY,aAAa,GAAG,KAAKrB,QAAL,CAAce,GAAd,CAAmBb,OAAD,IACtCA,OAAO,CAACS,cAAR,EADoB,CAAtB;AAIA,QAAIH,aAA4B,GAAG,EAAnC;;AAEA,SAAK,IAAIU,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAG,KAAKlB,QAAL,CAAcmB,MAAlC,EAA0CD,CAAC,EAA3C,EAA+C;AAC7C,WAAKjB,oBAAL,CACE,KAAKD,QAAL,CAAckB,CAAd,CADF,EAEE,KAAKf,oBAFP,EAGE,KAAKC,qBAAL,CAA2BkB,MAA3B,CAAkCd,aAAlC,CAHF,EAD6C,CAO7C;;AACAA,MAAAA,aAAa,GAAGA,aAAa,CAACc,MAAd,CAAqBD,aAAa,CAACH,CAAD,CAAlC,CAAhB;AACD;AACF;;AApBmD","sourcesContent":["import { BaseGesture, Gesture, GestureRef, GestureType } from './gesture';\n\nfunction extendRelation(\n currentRelation: GestureRef[] | undefined,\n extendWith: GestureType[]\n) {\n if (currentRelation === undefined) {\n return [...extendWith];\n } else {\n return [...currentRelation, ...extendWith];\n }\n}\n\nexport class ComposedGesture extends Gesture {\n protected gestures: Gesture[] = [];\n protected simultaneousGestures: GestureType[] = [];\n protected requireGesturesToFail: GestureType[] = [];\n\n constructor(...gestures: Gesture[]) {\n super();\n this.gestures = gestures;\n }\n\n protected prepareSingleGesture(\n gesture: Gesture,\n simultaneousGestures: GestureType[],\n requireGesturesToFail: GestureType[]\n ) {\n if (gesture instanceof BaseGesture) {\n const newConfig = { ...gesture.config };\n\n newConfig.simultaneousWith = extendRelation(\n newConfig.simultaneousWith,\n simultaneousGestures\n );\n newConfig.requireToFail = extendRelation(\n newConfig.requireToFail,\n requireGesturesToFail\n );\n\n gesture.config = newConfig;\n } else if (gesture instanceof ComposedGesture) {\n gesture.simultaneousGestures = simultaneousGestures;\n gesture.requireGesturesToFail = requireGesturesToFail;\n gesture.prepare();\n }\n }\n\n prepare() {\n for (const gesture of this.gestures) {\n this.prepareSingleGesture(\n gesture,\n this.simultaneousGestures,\n this.requireGesturesToFail\n );\n }\n }\n\n initialize() {\n for (const gesture of this.gestures) {\n gesture.initialize();\n }\n }\n\n toGestureArray(): GestureType[] {\n return this.gestures.flatMap((gesture) => gesture.toGestureArray());\n }\n}\n\nexport class SimultaneousGesture extends ComposedGesture {\n prepare() {\n // this piece of magic works something like this:\n // for every gesture in the array\n const simultaneousArrays = this.gestures.map((gesture) =>\n // we take the array it's in\n this.gestures\n // and make a copy without it\n .filter((x) => x !== gesture)\n // then we flatmap the result to get list of raw (not composed) gestures\n // this way we don't make the gestures simultaneous with themselves, which is\n // important when the gesture is `ExclusiveGesture` - we don't want to make\n // exclusive gestures simultaneous\n .flatMap((x) => x.toGestureArray())\n );\n\n for (let i = 0; i < this.gestures.length; i++) {\n this.prepareSingleGesture(\n this.gestures[i],\n simultaneousArrays[i],\n this.requireGesturesToFail\n );\n }\n }\n}\n\nexport class ExclusiveGesture extends ComposedGesture {\n prepare() {\n // transforms the array of gestures into array of grouped raw (not composed) gestures\n // i.e. [gesture1, gesture2, ComposedGesture(gesture3, gesture4)] -> [[gesture1], [gesture2], [gesture3, gesture4]]\n const gestureArrays = this.gestures.map((gesture) =>\n gesture.toGestureArray()\n );\n\n let requireToFail: GestureType[] = [];\n\n for (let i = 0; i < this.gestures.length; i++) {\n this.prepareSingleGesture(\n this.gestures[i],\n this.simultaneousGestures,\n this.requireGesturesToFail.concat(requireToFail)\n );\n\n // every group gets to wait for all groups before it\n requireToFail = requireToFail.concat(gestureArrays[i]);\n }\n }\n}\n\nexport type ComposedGestureType = InstanceType<typeof ComposedGesture>;\nexport type RaceGestureType = ComposedGestureType;\nexport type SimultaneousGestureType = InstanceType<typeof SimultaneousGesture>;\nexport type ExclusiveGestureType = InstanceType<typeof ExclusiveGesture>;\n"]}
1
+ {"version":3,"sources":["gestureComposition.ts"],"names":["BaseGesture","Gesture","extendRelation","currentRelation","extendWith","undefined","ComposedGesture","constructor","gestures","prepareSingleGesture","gesture","simultaneousGestures","requireGesturesToFail","newConfig","config","simultaneousWith","requireToFail","prepare","initialize","toGestureArray","flatMap","SimultaneousGesture","simultaneousArrays","map","filter","x","i","length","ExclusiveGesture","gestureArrays","concat"],"mappings":";;AAAA,SAASA,WAAT,EAAsBC,OAAtB,QAA8D,WAA9D;;AAEA,SAASC,cAAT,CACEC,eADF,EAEEC,UAFF,EAGE;AACA,MAAID,eAAe,KAAKE,SAAxB,EAAmC;AACjC,WAAO,CAAC,GAAGD,UAAJ,CAAP;AACD,GAFD,MAEO;AACL,WAAO,CAAC,GAAGD,eAAJ,EAAqB,GAAGC,UAAxB,CAAP;AACD;AACF;;AAED,OAAO,MAAME,eAAN,SAA8BL,OAA9B,CAAsC;AAK3CM,EAAAA,WAAW,CAAC,GAAGC,QAAJ,EAAyB;AAClC;;AADkC,sCAJJ,EAII;;AAAA,kDAHY,EAGZ;;AAAA,mDAFa,EAEb;;AAElC,SAAKA,QAAL,GAAgBA,QAAhB;AACD;;AAESC,EAAAA,oBAAoB,CAC5BC,OAD4B,EAE5BC,oBAF4B,EAG5BC,qBAH4B,EAI5B;AACA,QAAIF,OAAO,YAAYV,WAAvB,EAAoC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,CAOYK,CAAD,IAAOA,CAAC,CAACN,cAAF,EAPlB,CAFyB,CAA3B;;AAYA,SAAK,IAAIO,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAG,KAAKlB,QAAL,CAAcmB,MAAlC,EAA0CD,CAAC,EAA3C,EAA+C;AAC7C,WAAKjB,oBAAL,CACE,KAAKD,QAAL,CAAckB,CAAd,CADF,EAEEJ,kBAAkB,CAACI,CAAD,CAFpB,EAGE,KAAKd,qBAHP;AAKD;AACF;;AAvBsD;AA0BzD,OAAO,MAAMgB,gBAAN,SAA+BtB,eAA/B,CAA+C;AACpDW,EAAAA,OAAO,GAAG;AACR;AACA;AACA,UAAMY,aAAa,GAAG,KAAKrB,QAAL,CAAce,GAAd,CAAmBb,OAAD,IACtCA,OAAO,CAACS,cAAR,EADoB,CAAtB;AAIA,QAAIH,aAA4B,GAAG,EAAnC;;AAEA,SAAK,IAAIU,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAG,KAAKlB,QAAL,CAAcmB,MAAlC,EAA0CD,CAAC,EAA3C,EAA+C;AAC7C,WAAKjB,oBAAL,CACE,KAAKD,QAAL,CAAckB,CAAd,CADF,EAEE,KAAKf,oBAFP,EAGE,KAAKC,qBAAL,CAA2BkB,MAA3B,CAAkCd,aAAlC,CAHF,EAD6C,CAO7C;;AACAA,MAAAA,aAAa,GAAGA,aAAa,CAACc,MAAd,CAAqBD,aAAa,CAACH,CAAD,CAAlC,CAAhB;AACD;AACF;;AApBmD","sourcesContent":["import { BaseGesture, Gesture, GestureRef, GestureType } from './gesture';\n\nfunction extendRelation(\n currentRelation: GestureRef[] | undefined,\n extendWith: GestureType[]\n) {\n if (currentRelation === undefined) {\n return [...extendWith];\n } else {\n return [...currentRelation, ...extendWith];\n }\n}\n\nexport class ComposedGesture extends Gesture {\n protected gestures: Gesture[] = [];\n protected simultaneousGestures: GestureType[] = [];\n protected requireGesturesToFail: GestureType[] = [];\n\n constructor(...gestures: Gesture[]) {\n super();\n this.gestures = gestures;\n }\n\n protected prepareSingleGesture(\n gesture: Gesture,\n simultaneousGestures: GestureType[],\n requireGesturesToFail: GestureType[]\n ) {\n if (gesture instanceof BaseGesture) {\n const newConfig = { ...gesture.config };\n\n // no need to extend `blocksHandlers` here, because it's not changed in composition\n // the same effect is achieved by reversing the order of 2 gestures in `Exclusive`\n newConfig.simultaneousWith = extendRelation(\n newConfig.simultaneousWith,\n simultaneousGestures\n );\n newConfig.requireToFail = extendRelation(\n newConfig.requireToFail,\n requireGesturesToFail\n );\n\n gesture.config = newConfig;\n } else if (gesture instanceof ComposedGesture) {\n gesture.simultaneousGestures = simultaneousGestures;\n gesture.requireGesturesToFail = requireGesturesToFail;\n gesture.prepare();\n }\n }\n\n prepare() {\n for (const gesture of this.gestures) {\n this.prepareSingleGesture(\n gesture,\n this.simultaneousGestures,\n this.requireGesturesToFail\n );\n }\n }\n\n initialize() {\n for (const gesture of this.gestures) {\n gesture.initialize();\n }\n }\n\n toGestureArray(): GestureType[] {\n return this.gestures.flatMap((gesture) => gesture.toGestureArray());\n }\n}\n\nexport class SimultaneousGesture extends ComposedGesture {\n prepare() {\n // this piece of magic works something like this:\n // for every gesture in the array\n const simultaneousArrays = this.gestures.map((gesture) =>\n // we take the array it's in\n this.gestures\n // and make a copy without it\n .filter((x) => x !== gesture)\n // then we flatmap the result to get list of raw (not composed) gestures\n // this way we don't make the gestures simultaneous with themselves, which is\n // important when the gesture is `ExclusiveGesture` - we don't want to make\n // exclusive gestures simultaneous\n .flatMap((x) => x.toGestureArray())\n );\n\n for (let i = 0; i < this.gestures.length; i++) {\n this.prepareSingleGesture(\n this.gestures[i],\n simultaneousArrays[i],\n this.requireGesturesToFail\n );\n }\n }\n}\n\nexport class ExclusiveGesture extends ComposedGesture {\n prepare() {\n // transforms the array of gestures into array of grouped raw (not composed) gestures\n // i.e. [gesture1, gesture2, ComposedGesture(gesture3, gesture4)] -> [[gesture1], [gesture2], [gesture3, gesture4]]\n const gestureArrays = this.gestures.map((gesture) =>\n gesture.toGestureArray()\n );\n\n let requireToFail: GestureType[] = [];\n\n for (let i = 0; i < this.gestures.length; i++) {\n this.prepareSingleGesture(\n this.gestures[i],\n this.simultaneousGestures,\n this.requireGesturesToFail.concat(requireToFail)\n );\n\n // every group gets to wait for all groups before it\n requireToFail = requireToFail.concat(gestureArrays[i]);\n }\n }\n}\n\nexport type ComposedGestureType = InstanceType<typeof ComposedGesture>;\nexport type RaceGestureType = ComposedGestureType;\nexport type SimultaneousGestureType = InstanceType<typeof SimultaneousGesture>;\nexport type ExclusiveGestureType = InstanceType<typeof ExclusiveGesture>;\n"]}
@@ -15,6 +15,8 @@ function create(handlerTag) {
15
15
  'worklet';
16
16
 
17
17
  if (REANIMATED_AVAILABLE) {
18
+ // When Reanimated is available, setGestureState should be defined
19
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
18
20
  setGestureState(handlerTag, State.BEGAN);
19
21
  } else {
20
22
  console.warn(warningMessage);
@@ -24,6 +26,8 @@ function create(handlerTag) {
24
26
  'worklet';
25
27
 
26
28
  if (REANIMATED_AVAILABLE) {
29
+ // When Reanimated is available, setGestureState should be defined
30
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
27
31
  setGestureState(handlerTag, State.ACTIVE);
28
32
  } else {
29
33
  console.warn(warningMessage);
@@ -33,6 +37,8 @@ function create(handlerTag) {
33
37
  'worklet';
34
38
 
35
39
  if (REANIMATED_AVAILABLE) {
40
+ // When Reanimated is available, setGestureState should be defined
41
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
36
42
  setGestureState(handlerTag, State.FAILED);
37
43
  } else {
38
44
  console.warn(warningMessage);
@@ -42,6 +48,8 @@ function create(handlerTag) {
42
48
  'worklet';
43
49
 
44
50
  if (REANIMATED_AVAILABLE) {
51
+ // When Reanimated is available, setGestureState should be defined
52
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
45
53
  setGestureState(handlerTag, State.END);
46
54
  } else {
47
55
  console.warn(warningMessage);
@@ -1 +1 @@
1
- {"version":3,"sources":["gestureStateManager.ts"],"names":["Reanimated","State","tagMessage","warningMessage","REANIMATED_AVAILABLE","useSharedValue","undefined","setGestureState","create","handlerTag","begin","BEGAN","console","warn","activate","ACTIVE","fail","FAILED","end","END","GestureStateManager"],"mappings":"AAAA,SAASA,UAAT,QAA2B,qBAA3B;AACA,SAASC,KAAT,QAAsB,aAAtB;AACA,SAASC,UAAT,QAA2B,aAA3B;AASA,MAAMC,cAAc,GAAGD,UAAU,CAC/B,kFAD+B,CAAjC,C,CAIA;AACA;;AACA,MAAME,oBAAoB,GAAG,CAAAJ,UAAU,SAAV,IAAAA,UAAU,WAAV,YAAAA,UAAU,CAAEK,cAAZ,MAA+BC,SAA5D;AACA,MAAMC,eAAe,GAAGP,UAAH,aAAGA,UAAH,uBAAGA,UAAU,CAAEO,eAApC;;AAEA,SAASC,MAAT,CAAgBC,UAAhB,EAA6D;AAC3D;;AACA,SAAO;AACLC,IAAAA,KAAK,EAAE,MAAM;AACX;;AACA,UAAIN,oBAAJ,EAA0B;AACxBG,QAAAA,eAAe,CAACE,UAAD,EAAaR,KAAK,CAACU,KAAnB,CAAf;AACD,OAFD,MAEO;AACLC,QAAAA,OAAO,CAACC,IAAR,CAAaV,cAAb;AACD;AACF,KARI;AAULW,IAAAA,QAAQ,EAAE,MAAM;AACd;;AACA,UAAIV,oBAAJ,EAA0B;AACxBG,QAAAA,eAAe,CAACE,UAAD,EAAaR,KAAK,CAACc,MAAnB,CAAf;AACD,OAFD,MAEO;AACLH,QAAAA,OAAO,CAACC,IAAR,CAAaV,cAAb;AACD;AACF,KAjBI;AAmBLa,IAAAA,IAAI,EAAE,MAAM;AACV;;AACA,UAAIZ,oBAAJ,EAA0B;AACxBG,QAAAA,eAAe,CAACE,UAAD,EAAaR,KAAK,CAACgB,MAAnB,CAAf;AACD,OAFD,MAEO;AACLL,QAAAA,OAAO,CAACC,IAAR,CAAaV,cAAb;AACD;AACF,KA1BI;AA4BLe,IAAAA,GAAG,EAAE,MAAM;AACT;;AACA,UAAId,oBAAJ,EAA0B;AACxBG,QAAAA,eAAe,CAACE,UAAD,EAAaR,KAAK,CAACkB,GAAnB,CAAf;AACD,OAFD,MAEO;AACLP,QAAAA,OAAO,CAACC,IAAR,CAAaV,cAAb;AACD;AACF;AAnCI,GAAP;AAqCD;;AAED,OAAO,MAAMiB,mBAAmB,GAAG;AACjCZ,EAAAA;AADiC,CAA5B","sourcesContent":["import { Reanimated } from './reanimatedWrapper';\nimport { State } from '../../State';\nimport { tagMessage } from '../../utils';\n\nexport interface GestureStateManagerType {\n begin: () => void;\n activate: () => void;\n fail: () => void;\n end: () => void;\n}\n\nconst warningMessage = tagMessage(\n 'react-native-reanimated is required in order to use synchronous state management'\n);\n\n// check if reanimated module is available, but look for useSharedValue as conditional\n// require of reanimated can sometimes return content of `utils.ts` file (?)\nconst REANIMATED_AVAILABLE = Reanimated?.useSharedValue !== undefined;\nconst setGestureState = Reanimated?.setGestureState;\n\nfunction create(handlerTag: number): GestureStateManagerType {\n 'worklet';\n return {\n begin: () => {\n 'worklet';\n if (REANIMATED_AVAILABLE) {\n setGestureState(handlerTag, State.BEGAN);\n } else {\n console.warn(warningMessage);\n }\n },\n\n activate: () => {\n 'worklet';\n if (REANIMATED_AVAILABLE) {\n setGestureState(handlerTag, State.ACTIVE);\n } else {\n console.warn(warningMessage);\n }\n },\n\n fail: () => {\n 'worklet';\n if (REANIMATED_AVAILABLE) {\n setGestureState(handlerTag, State.FAILED);\n } else {\n console.warn(warningMessage);\n }\n },\n\n end: () => {\n 'worklet';\n if (REANIMATED_AVAILABLE) {\n setGestureState(handlerTag, State.END);\n } else {\n console.warn(warningMessage);\n }\n },\n };\n}\n\nexport const GestureStateManager = {\n create,\n};\n"]}
1
+ {"version":3,"sources":["gestureStateManager.ts"],"names":["Reanimated","State","tagMessage","warningMessage","REANIMATED_AVAILABLE","useSharedValue","undefined","setGestureState","create","handlerTag","begin","BEGAN","console","warn","activate","ACTIVE","fail","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Af;AACD,OAJD,MAIO;AACLP,QAAAA,OAAO,CAACC,IAAR,CAAaV,cAAb;AACD;AACF;AA3CI,GAAP;AA6CD;;AAED,OAAO,MAAMiB,mBAAmB,GAAG;AACjCZ,EAAAA;AADiC,CAA5B","sourcesContent":["import { Reanimated } from './reanimatedWrapper';\nimport { State } from '../../State';\nimport { tagMessage } from '../../utils';\n\nexport interface GestureStateManagerType {\n begin: () => void;\n activate: () => void;\n fail: () => void;\n end: () => void;\n}\n\nconst warningMessage = tagMessage(\n 'react-native-reanimated is required in order to use synchronous state management'\n);\n\n// check if reanimated module is available, but look for useSharedValue as conditional\n// require of reanimated can sometimes return content of `utils.ts` file (?)\nconst REANIMATED_AVAILABLE = Reanimated?.useSharedValue !== undefined;\nconst setGestureState = Reanimated?.setGestureState;\n\nfunction create(handlerTag: number): GestureStateManagerType {\n 'worklet';\n return {\n begin: () => {\n 'worklet';\n if (REANIMATED_AVAILABLE) {\n // When Reanimated is available, setGestureState should be defined\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n setGestureState!(handlerTag, State.BEGAN);\n } else {\n console.warn(warningMessage);\n }\n },\n\n activate: () => {\n 'worklet';\n if (REANIMATED_AVAILABLE) {\n // When Reanimated is available, setGestureState should be defined\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n setGestureState!(handlerTag, State.ACTIVE);\n } else {\n console.warn(warningMessage);\n }\n },\n\n fail: () => {\n 'worklet';\n if (REANIMATED_AVAILABLE) {\n // When Reanimated is available, setGestureState should be defined\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n setGestureState!(handlerTag, State.FAILED);\n } else {\n console.warn(warningMessage);\n }\n },\n\n end: () => {\n 'worklet';\n if (REANIMATED_AVAILABLE) {\n // When Reanimated is available, setGestureState should be defined\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n setGestureState!(handlerTag, State.END);\n } else {\n console.warn(warningMessage);\n }\n },\n };\n}\n\nexport const GestureStateManager = {\n create,\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["reanimatedWrapper.ts"],"names":["tagMessage","Reanimated","require","e","undefined","useSharedValue","setGestureState","console","warn"],"mappings":";;AAKA,SAASA,UAAT,QAA2B,aAA3B;AAMA,IAAIC,UAAJ;;AAkBA,IAAI;AACFA,EAAAA,UAAU,GAAGC,OAAO,CAAC,yBAAD,CAApB;AACD,CAFD,CAEE,OAAOC,CAAP,EAAU;AACV;AACA;AACAF,EAAAA,UAAU,GAAGG,SAAb;AACD;;AAED,IAAI,iBAACH,UAAD,wCAAC,YAAYI,cAAb,CAAJ,EAAiC;AAC/B;AACA;AACAJ,EAAAA,UAAU,GAAGG,SAAb;AACD;;AAED,IAAIH,UAAU,KAAKG,SAAf,IAA4B,CAACH,UAAU,CAACK,eAA5C,EAA6D;AAC3D;AACAL,EAAAA,UAAU,CAACK,eAAX,GAA6B,MAAM;AACjC;;AACAC,IAAAA,OAAO,CAACC,IAAR,CACER,UAAU,CACR,gGADQ,CADZ;AAKD,GAPD;AAQD;;AAED,SAASC,UAAT","sourcesContent":["import { ComponentClass } from 'react';\nimport {\n GestureUpdateEvent,\n GestureStateChangeEvent,\n} from '../gestureHandlerCommon';\nimport { tagMessage } from '../../utils';\n\nexport interface SharedValue<T> {\n value: T;\n}\n\nlet Reanimated: {\n default: {\n // Slightly modified definition copied from 'react-native-reanimated'\n // eslint-disable-next-line @typescript-eslint/ban-types\n createAnimatedComponent<P extends object>(\n component: ComponentClass<P>,\n options?: unknown\n ): ComponentClass<P>;\n };\n useEvent: (\n callback: (event: GestureUpdateEvent | GestureStateChangeEvent) => void,\n events: string[],\n rebuild: boolean\n ) => unknown;\n useSharedValue: <T>(value: T) => SharedValue<T>;\n setGestureState: (handlerTag: number, newState: number) => void;\n};\n\ntry {\n Reanimated = require('react-native-reanimated');\n} catch (e) {\n // When 'react-native-reanimated' is not available we want to quietly continue\n // @ts-ignore TS demands the variable to be initialized\n Reanimated = undefined;\n}\n\nif (!Reanimated?.useSharedValue) {\n // @ts-ignore Make sure the loaded module is actually Reanimated, if it's not\n // reset the module to undefined so we can fallback to the default implementation\n Reanimated = undefined;\n}\n\nif (Reanimated !== undefined && !Reanimated.setGestureState) {\n // The loaded module is Reanimated but it doesn't have the setGestureState defined\n Reanimated.setGestureState = () => {\n 'worklet';\n console.warn(\n tagMessage(\n 'Please use newer version of react-native-reanimated in order to control state of the gestures.'\n )\n );\n };\n}\n\nexport { Reanimated };\n"]}
1
+ {"version":3,"sources":["reanimatedWrapper.ts"],"names":["tagMessage","Reanimated","require","e","undefined","useSharedValue","setGestureState","console","warn"],"mappings":";;AAKA,SAASA,UAAT,QAA2B,aAA3B;AAMA,IAAIC,UAAJ;;AAoBA,IAAI;AACFA,EAAAA,UAAU,GAAGC,OAAO,CAAC,yBAAD,CAApB;AACD,CAFD,CAEE,OAAOC,CAAP,EAAU;AACV;AACA;AACAF,EAAAA,UAAU,GAAGG,SAAb;AACD;;AAED,IAAI,iBAACH,UAAD,wCAAC,YAAYI,cAAb,CAAJ,EAAiC;AAC/B;AACA;AACAJ,EAAAA,UAAU,GAAGG,SAAb;AACD;;AAED,IAAIH,UAAU,KAAKG,SAAf,IAA4B,CAACH,UAAU,CAACK,eAA5C,EAA6D;AAC3D;AACAL,EAAAA,UAAU,CAACK,eAAX,GAA6B,MAAM;AACjC;;AACAC,IAAAA,OAAO,CAACC,IAAR,CACER,UAAU,CACR,gGADQ,CADZ;AAKD,GAPD;AAQD;;AAED,SAASC,UAAT","sourcesContent":["import { ComponentClass } from 'react';\nimport {\n GestureUpdateEvent,\n GestureStateChangeEvent,\n} from '../gestureHandlerCommon';\nimport { tagMessage } from '../../utils';\n\nexport interface SharedValue<T> {\n value: T;\n}\n\nlet Reanimated:\n | {\n default: {\n // Slightly modified definition copied from 'react-native-reanimated'\n // eslint-disable-next-line @typescript-eslint/ban-types\n createAnimatedComponent<P extends object>(\n component: ComponentClass<P>,\n options?: unknown\n ): ComponentClass<P>;\n };\n useEvent: (\n callback: (event: GestureUpdateEvent | GestureStateChangeEvent) => void,\n events: string[],\n rebuild: boolean\n ) => unknown;\n useSharedValue: <T>(value: T) => SharedValue<T>;\n setGestureState: (handlerTag: number, newState: number) => void;\n }\n | undefined;\n\ntry {\n Reanimated = require('react-native-reanimated');\n} catch (e) {\n // When 'react-native-reanimated' is not available we want to quietly continue\n // @ts-ignore TS demands the variable to be initialized\n Reanimated = undefined;\n}\n\nif (!Reanimated?.useSharedValue) {\n // @ts-ignore Make sure the loaded module is actually Reanimated, if it's not\n // reset the module to undefined so we can fallback to the default implementation\n Reanimated = undefined;\n}\n\nif (Reanimated !== undefined && !Reanimated.setGestureState) {\n // The loaded module is Reanimated but it doesn't have the setGestureState defined\n Reanimated.setGestureState = () => {\n 'worklet';\n console.warn(\n tagMessage(\n 'Please use newer version of react-native-reanimated in order to control state of the gestures.'\n )\n );\n };\n}\n\nexport { Reanimated };\n"]}
@@ -45,4 +45,38 @@ export function isRemoteDebuggingEnabled() {
45
45
  const localGlobal = global;
46
46
  return (!localGlobal.nativeCallSyncHook || !!localGlobal.__REMOTEDEV__) && !localGlobal.RN$Bridgeless;
47
47
  }
48
+ /**
49
+ * Recursively compares two objects for deep equality.
50
+ *
51
+ * **Note:** This function does not support cyclic references.
52
+ *
53
+ * @param obj1 - The first object to compare.
54
+ * @param obj2 - The second object to compare.
55
+ * @returns `true` if the objects are deeply equal, `false` otherwise.
56
+ */
57
+
58
+ export function deepEqual(obj1, obj2) {
59
+ if (obj1 === obj2) {
60
+ return true;
61
+ }
62
+
63
+ if (typeof obj1 !== 'object' || typeof obj2 !== 'object' || obj1 === null || obj2 === null) {
64
+ return false;
65
+ }
66
+
67
+ const keys1 = Object.keys(obj1);
68
+ const keys2 = Object.keys(obj2);
69
+
70
+ if (keys1.length !== keys2.length) {
71
+ return false;
72
+ }
73
+
74
+ for (const key of keys1) {
75
+ if (!keys2.includes(key) || !deepEqual(obj1[key], obj2[key])) {
76
+ return false;
77
+ }
78
+ }
79
+
80
+ return true;
81
+ }
48
82
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["utils.ts"],"names":["toArray","object","Array","isArray","withPrevAndCurrent","array","mapFn","previousArr","currentArr","transformedArr","forEach","current","i","previous","transformed","push","hasProperty","key","Object","prototype","hasOwnProperty","call","isJestEnv","global","process","env","JEST_WORKER_ID","tagMessage","msg","isFabric","nativeFabricUIManager","isRemoteDebuggingEnabled","localGlobal","nativeCallSyncHook","__REMOTEDEV__","RN$Bridgeless"],"mappings":"AAAA,OAAO,SAASA,OAAT,CAAoBC,MAApB,EAA0C;AAC/C,MAAI,CAACC,KAAK,CAACC,OAAN,CAAcF,MAAd,CAAL,EAA4B;AAC1B,WAAO,CAACA,MAAD,CAAP;AACD;;AAED,SAAOA,MAAP;AACD;AAMD,OAAO,SAASG,kBAAT,CACLC,KADK,EAELC,KAFK,EAGU;AACf,QAAMC,WAAmC,GAAG,CAAC,IAAD,CAA5C;AACA,QAAMC,UAAU,GAAG,CAAC,GAAGH,KAAJ,CAAnB;AACA,QAAMI,cAA6B,GAAG,EAAtC;AACAD,EAAAA,UAAU,CAACE,OAAX,CAAmB,CAACC,OAAD,EAAUC,CAAV,KAAgB;AACjC;AACA;AACA;AACA,UAAMC,QAAQ,GAAGN,WAAW,CAACK,CAAD,CAA5B;AACA,UAAME,WAAW,GAAGR,KAAK,CAACO,QAAD,EAAWF,OAAX,CAAzB;AACAJ,IAAAA,WAAW,CAACQ,IAAZ,CAAiBD,WAAjB;AACAL,IAAAA,cAAc,CAACM,IAAf,CAAoBD,WAApB;AACD,GARD;AASA,SAAOL,cAAP;AACD,C,CAED;;AACA,OAAO,SAASO,WAAT,CAAqBf,MAArB,EAAqCgB,GAArC,EAAkD;AACvD,SAAOC,MAAM,CAACC,SAAP,CAAiBC,cAAjB,CAAgCC,IAAhC,CAAqCpB,MAArC,EAA6CgB,GAA7C,CAAP;AACD;AAED,OAAO,SAASK,SAAT,GAA8B;AACnC;AACA,SAAON,WAAW,CAACO,MAAD,EAAS,SAAT,CAAX,IAAkC,CAAC,CAACC,OAAO,CAACC,GAAR,CAAYC,cAAvD;AACD;AAED,OAAO,SAASC,UAAT,CAAoBC,GAApB,EAAiC;AACtC,SAAQ,kCAAiCA,GAAI,EAA7C;AACD,C,CAED;AACA;;AACA,OAAO,SAASC,QAAT,GAA6B;AAAA;;AAClC;AACA,SAAO,CAAC,aAACN,MAAD,oCAAC,QAAQO,qBAAT,CAAR;AACD;AAED,OAAO,SAASC,wBAAT,GAA6C;AAClD;AACA;AACA,QAAMC,WAAW,GAAGT,MAApB;AACA,SACE,CAAC,CAACS,WAAW,CAACC,kBAAb,IAAmC,CAAC,CAACD,WAAW,CAACE,aAAlD,KACA,CAACF,WAAW,CAACG,aAFf;AAID","sourcesContent":["export function toArray<T>(object: T | T[]): T[] {\n if (!Array.isArray(object)) {\n return [object];\n }\n\n return object;\n}\n\nexport type withPrevAndCurrentMapFn<T, Transformed> = (\n previous: Transformed | null,\n current: T\n) => Transformed;\nexport function withPrevAndCurrent<T, Transformed>(\n array: T[],\n mapFn: withPrevAndCurrentMapFn<T, Transformed>\n): Transformed[] {\n const previousArr: (null | Transformed)[] = [null];\n const currentArr = [...array];\n const transformedArr: Transformed[] = [];\n currentArr.forEach((current, i) => {\n // 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).\n // Unfortunately, linter on our CI does not allow this type of casting as it is unnecessary. To bypass that we use eslint-disable.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n const previous = previousArr[i] as Transformed | null;\n const transformed = mapFn(previous, current);\n previousArr.push(transformed);\n transformedArr.push(transformed);\n });\n return transformedArr;\n}\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport function hasProperty(object: object, key: string) {\n return Object.prototype.hasOwnProperty.call(object, key);\n}\n\nexport function isJestEnv(): boolean {\n // @ts-ignore Do not use `@types/node` because it will prioritise Node types over RN types which breaks the types (ex. setTimeout) in React Native projects.\n return hasProperty(global, 'process') && !!process.env.JEST_WORKER_ID;\n}\n\nexport function tagMessage(msg: string) {\n return `[react-native-gesture-handler] ${msg}`;\n}\n\n// helper method to check whether Fabric is enabled, however global.nativeFabricUIManager\n// may not be initialized before the first render\nexport function isFabric(): boolean {\n // @ts-expect-error nativeFabricUIManager is not yet included in the RN types\n return !!global?.nativeFabricUIManager;\n}\n\nexport function isRemoteDebuggingEnabled(): boolean {\n // react-native-reanimated checks if in remote debugging in the same way\n // @ts-ignore global is available but node types are not included\n const localGlobal = global as any;\n return (\n (!localGlobal.nativeCallSyncHook || !!localGlobal.__REMOTEDEV__) &&\n !localGlobal.RN$Bridgeless\n );\n}\n"]}
1
+ {"version":3,"sources":["utils.ts"],"names":["toArray","object","Array","isArray","withPrevAndCurrent","array","mapFn","previousArr","currentArr","transformedArr","forEach","current","i","previous","transformed","push","hasProperty","key","Object","prototype","hasOwnProperty","call","isJestEnv","global","process","env","JEST_WORKER_ID","tagMessage","msg","isFabric","nativeFabricUIManager","isRemoteDebuggingEnabled","localGlobal","nativeCallSyncHook","__REMOTEDEV__","RN$Bridgeless","deepEqual","obj1","obj2","keys1","keys","keys2","length","includes"],"mappings":"AAAA,OAAO,SAASA,OAAT,CAAoBC,MAApB,EAA0C;AAC/C,MAAI,CAACC,KAAK,CAACC,OAAN,CAAcF,MAAd,CAAL,EAA4B;AAC1B,WAAO,CAACA,MAAD,CAAP;AACD;;AAED,SAAOA,MAAP;AACD;AAMD,OAAO,SAASG,kBAAT,CACLC,KADK,EAELC,KAFK,EAGU;AACf,QAAMC,WAAmC,GAAG,CAAC,IAAD,CAA5C;AACA,QAAMC,UAAU,GAAG,CAAC,GAAGH,KAAJ,CAAnB;AACA,QAAMI,cAA6B,GAAG,EAAtC;AACAD,EAAAA,UAAU,CAACE,OAAX,CAAmB,CAACC,OAAD,EAAUC,CAAV,KAAgB;AACjC;AACA;AACA;AACA,UAAMC,QAAQ,GAAGN,WAAW,CAACK,CAAD,CAA5B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GAAGrB,MAAM,CAACsB,IAAP,CAAYH,IAAZ,CAAd;AACA,QAAMI,KAAK,GAAGvB,MAAM,CAACsB,IAAP,CAAYF,IAAZ,CAAd;;AAEA,MAAIC,KAAK,CAACG,MAAN,KAAiBD,KAAK,CAACC,MAA3B,EAAmC;AACjC,WAAO,KAAP;AACD;;AAED,OAAK,MAAMzB,GAAX,IAAkBsB,KAAlB,EAAyB;AACvB,QAAI,CAACE,KAAK,CAACE,QAAN,CAAe1B,GAAf,CAAD,IAAwB,CAACmB,SAAS,CAACC,IAAI,CAACpB,GAAD,CAAL,EAAYqB,IAAI,CAACrB,GAAD,CAAhB,CAAtC,EAA8D;AAC5D,aAAO,KAAP;AACD;AACF;;AAED,SAAO,IAAP;AACD","sourcesContent":["export function toArray<T>(object: T | T[]): T[] {\n if (!Array.isArray(object)) {\n return [object];\n }\n\n return object;\n}\n\nexport type withPrevAndCurrentMapFn<T, Transformed> = (\n previous: Transformed | null,\n current: T\n) => Transformed;\nexport function withPrevAndCurrent<T, Transformed>(\n array: T[],\n mapFn: withPrevAndCurrentMapFn<T, Transformed>\n): Transformed[] {\n const previousArr: (null | Transformed)[] = [null];\n const currentArr = [...array];\n const transformedArr: Transformed[] = [];\n currentArr.forEach((current, i) => {\n // 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).\n // Unfortunately, linter on our CI does not allow this type of casting as it is unnecessary. To bypass that we use eslint-disable.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n const previous = previousArr[i] as Transformed | null;\n const transformed = mapFn(previous, current);\n previousArr.push(transformed);\n transformedArr.push(transformed);\n });\n return transformedArr;\n}\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport function hasProperty(object: object, key: string) {\n return Object.prototype.hasOwnProperty.call(object, key);\n}\n\nexport function isJestEnv(): boolean {\n // @ts-ignore Do not use `@types/node` because it will prioritise Node types over RN types which breaks the types (ex. setTimeout) in React Native projects.\n return hasProperty(global, 'process') && !!process.env.JEST_WORKER_ID;\n}\n\nexport function tagMessage(msg: string) {\n return `[react-native-gesture-handler] ${msg}`;\n}\n\n// helper method to check whether Fabric is enabled, however global.nativeFabricUIManager\n// may not be initialized before the first render\nexport function isFabric(): boolean {\n // @ts-expect-error nativeFabricUIManager is not yet included in the RN types\n return !!global?.nativeFabricUIManager;\n}\n\nexport function isRemoteDebuggingEnabled(): boolean {\n // react-native-reanimated checks if in remote debugging in the same way\n // @ts-ignore global is available but node types are not included\n const localGlobal = global as any;\n return (\n (!localGlobal.nativeCallSyncHook || !!localGlobal.__REMOTEDEV__) &&\n !localGlobal.RN$Bridgeless\n );\n}\n\n/**\n * Recursively compares two objects for deep equality.\n *\n * **Note:** This function does not support cyclic references.\n *\n * @param obj1 - The first object to compare.\n * @param obj2 - The second object to compare.\n * @returns `true` if the objects are deeply equal, `false` otherwise.\n */\nexport function deepEqual(obj1: any, obj2: any) {\n if (obj1 === obj2) {\n return true;\n }\n\n if (\n typeof obj1 !== 'object' ||\n typeof obj2 !== 'object' ||\n obj1 === null ||\n obj2 === null\n ) {\n return false;\n }\n\n const keys1 = Object.keys(obj1);\n const keys2 = Object.keys(obj2);\n\n if (keys1.length !== keys2.length) {\n return false;\n }\n\n for (const key of keys1) {\n if (!keys2.includes(key) || !deepEqual(obj1[key], obj2[key])) {\n return false;\n }\n }\n\n return true;\n}\n"]}
@@ -34,14 +34,12 @@ export default class RotationGestureDetector {
34
34
  this.previousTime = this.currentTime;
35
35
  this.currentTime = event.time;
36
36
  const [firstPointerID, secondPointerID] = this.keyPointers;
37
- const firstPointerX = tracker.getLastX(firstPointerID);
38
- const firstPointerY = tracker.getLastY(firstPointerID);
39
- const secondPointerX = tracker.getLastX(secondPointerID);
40
- const secondPointerY = tracker.getLastY(secondPointerID);
41
- const vectorX = secondPointerX - firstPointerX;
42
- const vectorY = secondPointerY - firstPointerY;
43
- this.anchorX = (firstPointerX + secondPointerX) / 2;
44
- this.anchorY = (firstPointerY + secondPointerY) / 2; //Angle diff should be positive when rotating in clockwise direction
37
+ const firstPointerCoords = tracker.getLastAbsoluteCoords(firstPointerID);
38
+ const secondPointerCoords = tracker.getLastAbsoluteCoords(secondPointerID);
39
+ const vectorX = secondPointerCoords.x - firstPointerCoords.x;
40
+ const vectorY = secondPointerCoords.y - firstPointerCoords.y;
41
+ this.anchorX = (firstPointerCoords.x + secondPointerCoords.x) / 2;
42
+ this.anchorY = (firstPointerCoords.y + secondPointerCoords.y) / 2; //Angle diff should be positive when rotating in clockwise direction
45
43
 
46
44
  const angle = -Math.atan2(vectorY, vectorX);
47
45
  this.rotation = Number.isNaN(this.previousAngle) ? 0 : this.previousAngle - angle;
@@ -1 +1 @@
1
- {"version":3,"sources":["RotationGestureDetector.ts"],"names":["EventTypes","RotationGestureDetector","constructor","callbacks","NaN","onRotationBegin","onRotation","onRotationEnd","updateCurrent","event","tracker","previousTime","currentTime","time","firstPointerID","secondPointerID","keyPointers","firstPointerX","getLastX","firstPointerY","getLastY","secondPointerX","secondPointerY","vectorX","vectorY","anchorX","anchorY","angle","Math","atan2","rotation","Number","isNaN","previousAngle","PI","finish","isInProgress","setKeyPointers","pointerIDs","getData","keys","next","value","onTouchEvent","eventType","DOWN","ADDITIONAL_POINTER_DOWN","MOVE","ADDITIONAL_POINTER_UP","indexOf","pointerId","UP","getTimeDelta","getAnchorX","getAnchorY","getRotation","reset"],"mappings":";;AAAA,SAAuBA,UAAvB,QAAyC,eAAzC;AASA,eAAe,MAAMC,uBAAN,CAEf;AAkBEC,EAAAA,WAAW,CAACC,SAAD,EAAqC;AAAA;;AAAA;;AAAA;;AAAA,yCAb1B,CAa0B;;AAAA,0CAZzB,CAYyB;;AAAA,2CAVxB,CAUwB;;AAAA,sCAT7B,CAS6B;;AAAA,qCAP9B,CAO8B;;AAAA,qCAN9B,CAM8B;;AAAA,0CAJzB,KAIyB;;AAAA,yCAFhB,CAACC,GAAD,EAAMA,GAAN,CAEgB;;AAC9C,SAAKC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AKzB,YAAL,GAAoBF,KAAK,CAACI,IAA1B;AACA,aAAKoB,aAAL,GAAqB7B,GAArB;AAEA,aAAKiC,cAAL,CAAoB3B,OAApB;AAEA,aAAKF,aAAL,CAAmBC,KAAnB,EAA0BC,OAA1B;AACA,aAAKL,eAAL,CAAqB,IAArB;AACA;;AAEF,WAAKL,UAAU,CAAC+C,IAAhB;AACE,YAAI,CAAC,KAAKX,YAAV,EAAwB;AACtB;AACD;;AAED,aAAK5B,aAAL,CAAmBC,KAAnB,EAA0BC,OAA1B;AACA,aAAKJ,UAAL,CAAgB,IAAhB;AAEA;;AAEF,WAAKN,UAAU,CAACgD,qBAAhB;AACE,YAAI,CAAC,KAAKZ,YAAV,EAAwB;AACtB;AACD;;AAED,YAAI,KAAKpB,WAAL,CAAiBiC,OAAjB,CAAyBxC,KAAK,CAACyC,SAA/B,KAA6C,CAAjD,EAAoD;AAClD,eAAKf,MAAL;AACD;;AAED;;AAEF,WAAKnC,UAAU,CAACmD,EAAhB;AACE,YAAI,KAAKf,YAAT,EAAuB;AACrB,eAAKD,MAAL;AACD;;AACD;AA7CJ;;AAgDA,WAAO,IAAP;AACD;;AAEMiB,EAAAA,YAAY,GAAW;AAC5B,WAAO,KAAKxC,WAAL,GAAmB,KAAKD,YAA/B;AACD;;AAEM0C,EAAAA,UAAU,GAAW;AAC1B,WAAO,KAAK5B,OAAZ;AACD;;AAEM6B,EAAAA,UAAU,GAAW;AAC1B,WAAO,KAAK5B,OAAZ;AACD;;AAEM6B,EAAAA,WAAW,GAAW;AAC3B,WAAO,KAAKzB,QAAZ;AACD;;AAEM0B,EAAAA,KAAK,GAAS;AACnB,SAAKxC,WAAL,GAAmB,CAACZ,GAAD,EAAMA,GAAN,CAAnB;AACA,SAAKgC,YAAL,GAAoB,KAApB;AACD;;AA3JH","sourcesContent":["import { AdaptedEvent, EventTypes } from '../interfaces';\nimport PointerTracker from '../tools/PointerTracker';\n\nexport interface RotationGestureListener {\n onRotationBegin: (detector: RotationGestureDetector) => boolean;\n onRotation: (detector: RotationGestureDetector) => boolean;\n onRotationEnd: (detector: RotationGestureDetector) => void;\n}\n\nexport default class RotationGestureDetector\n implements RotationGestureListener\n{\n onRotationBegin: (detector: RotationGestureDetector) => boolean;\n onRotation: (detector: RotationGestureDetector) => boolean;\n onRotationEnd: (detector: RotationGestureDetector) => void;\n\n private currentTime = 0;\n private previousTime = 0;\n\n private previousAngle = 0;\n private rotation = 0;\n\n private anchorX = 0;\n private anchorY = 0;\n\n private isInProgress = false;\n\n private keyPointers: number[] = [NaN, NaN];\n\n constructor(callbacks: RotationGestureListener) {\n this.onRotationBegin = callbacks.onRotationBegin;\n this.onRotation = callbacks.onRotation;\n this.onRotationEnd = callbacks.onRotationEnd;\n }\n\n private updateCurrent(event: AdaptedEvent, tracker: PointerTracker): void {\n this.previousTime = this.currentTime;\n this.currentTime = event.time;\n\n const [firstPointerID, secondPointerID] = this.keyPointers;\n\n const firstPointerX: number = tracker.getLastX(firstPointerID);\n const firstPointerY: number = tracker.getLastY(firstPointerID);\n const secondPointerX: number = tracker.getLastX(secondPointerID);\n const secondPointerY: number = tracker.getLastY(secondPointerID);\n\n const vectorX: number = secondPointerX - firstPointerX;\n const vectorY: number = secondPointerY - firstPointerY;\n\n this.anchorX = (firstPointerX + secondPointerX) / 2;\n this.anchorY = (firstPointerY + secondPointerY) / 2;\n\n //Angle diff should be positive when rotating in clockwise direction\n const angle: number = -Math.atan2(vectorY, vectorX);\n\n this.rotation = Number.isNaN(this.previousAngle)\n ? 0\n : this.previousAngle - angle;\n\n this.previousAngle = angle;\n\n if (this.rotation > Math.PI) {\n this.rotation -= Math.PI;\n } else if (this.rotation < -Math.PI) {\n this.rotation += Math.PI;\n }\n\n if (this.rotation > Math.PI / 2) {\n this.rotation -= Math.PI;\n } else if (this.rotation < -Math.PI / 2) {\n this.rotation += Math.PI;\n }\n }\n\n private finish(): void {\n if (!this.isInProgress) {\n return;\n }\n\n this.isInProgress = false;\n this.keyPointers = [NaN, NaN];\n this.onRotationEnd(this);\n }\n\n private setKeyPointers(tracker: PointerTracker): void {\n if (this.keyPointers[0] && this.keyPointers[1]) {\n return;\n }\n\n const pointerIDs: IterableIterator<number> = tracker.getData().keys();\n\n this.keyPointers[0] = pointerIDs.next().value as number;\n this.keyPointers[1] = pointerIDs.next().value as number;\n }\n\n public onTouchEvent(event: AdaptedEvent, tracker: PointerTracker): boolean {\n switch (event.eventType) {\n case EventTypes.DOWN:\n this.isInProgress = false;\n break;\n\n case EventTypes.ADDITIONAL_POINTER_DOWN:\n if (this.isInProgress) {\n break;\n }\n this.isInProgress = true;\n\n this.previousTime = event.time;\n this.previousAngle = NaN;\n\n this.setKeyPointers(tracker);\n\n this.updateCurrent(event, tracker);\n this.onRotationBegin(this);\n break;\n\n case EventTypes.MOVE:\n if (!this.isInProgress) {\n break;\n }\n\n this.updateCurrent(event, tracker);\n this.onRotation(this);\n\n break;\n\n case EventTypes.ADDITIONAL_POINTER_UP:\n if (!this.isInProgress) {\n break;\n }\n\n if (this.keyPointers.indexOf(event.pointerId) >= 0) {\n this.finish();\n }\n\n break;\n\n case EventTypes.UP:\n if (this.isInProgress) {\n this.finish();\n }\n break;\n }\n\n return true;\n }\n\n public getTimeDelta(): number {\n return this.currentTime + this.previousTime;\n }\n\n public getAnchorX(): number {\n return this.anchorX;\n }\n\n public getAnchorY(): number {\n return this.anchorY;\n }\n\n public getRotation(): number {\n return this.rotation;\n }\n\n public reset(): void {\n this.keyPointers = [NaN, NaN];\n this.isInProgress = false;\n }\n}\n"]}
1
+ {"version":3,"sources":["RotationGestureDetector.ts"],"names":["EventTypes","RotationGestureDetector","constructor","callbacks","NaN","onRotationBegin","onRotation","onRotationEnd","updateCurrent","event","tracker","previousTime","currentTime","time","firstPointerID","secondPointerID","keyPointers","firstPointerCoords","getLastAbsoluteCoords","secondPointerCoords","vectorX","x","vectorY","y","anchorX","anchorY","angle","Math","atan2","rotation","Number","isNaN","previousAngle","PI","finish","isInProgress","setKeyPointers","pointerIDs","getData","keys","next","value","onTouchEvent","eventType","DOWN","ADDITIONAL_POINTER_DOWN","MOVE","ADDITIONAL_POINTER_UP","indexOf","pointerId","UP","getTimeDelta","getAnchorX","getAnchorY","getRotation","reset"],"mappings":";;AAAA,SAAuBA,UAAvB,QAAyC,eAAzC;AASA,eAAe,MAAMC,uBAAN,CAEf;AAkBEC,EAAAA,WAAW,CAACC,SAAD,EAAqC;AAAA;;AAAA;;AAAA;;AAAA,yCAb1B,CAa0B;;AAAA,0CAZzB,CAYyB;;AAAA,2CAVxB,CAUwB;;AAAA,sCAT7B,CAS6B;;AAAA,qCAP9B,CAO8B;;AAAA,qCAN9B,CAM8B;;AAAA,0CAJzB,KAIyB;;AAAA,yCAFhB,CAACC,GAAD,EAAMA,GAAN,CAEgB;;AAC9C,SAAKC,eAAL,GAAuBF,SAAS,CAACE,eAAjC;AACA,SAAKC,UAAL,GAAkBH,SAAS,CAACG,UAA5B;AACA,SAAKC,aAAL,GAAqBJ,SAAS,CAACI,aAA/B;AACD;;AAEOC,EAAAA,aAAa,CAACC,KAAD,EAAsBC,OAAtB,EAAqD;AACxE,SAAKC,YAAL,GAAoB,KAAKC,WAAzB;AACA,SAAKA,WAAL,GAAmBH,KAAK,CAACI,IAAzB;AAEA,UAAM,CAACC,cAAD,EAAiBC,eAAjB,IAAoC,KAAKC,WAA/C;AAEA,UAAMC,kBAAkB,GAAGP,OAAO,CAACQ,qBAAR,CAA8BJ,cAA9B,CAA3B;AACA,UAAMK,mBAAmB,GAAGT,OAAO,CAACQ,qBAAR,CAA8BH,eAA9B,CAA5B;AAEA,UAAMK,OAAe,GAAGD,mBAAmB,CAACE,CAApB,GAAwBJ,kBAAkB,CAACI,CAAnE;AACA,UAAMC,OAAe,GAAGH,mBAAmB,CAACI,CAApB,GAAwBN,kBAAkB,CAACM,CAAnE;AAEA,SAAKC,OAAL,GAAe,CAACP,kBAAkB,CAACI,CAAnB,GAAuBF,mBAAmB,CAACE,CAA5C,IAAiD,CAAh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AW;AAC5B,WAAO,KAAKvC,WAAL,GAAmB,KAAKD,YAA/B;AACD;;AAEMyC,EAAAA,UAAU,GAAW;AAC1B,WAAO,KAAK5B,OAAZ;AACD;;AAEM6B,EAAAA,UAAU,GAAW;AAC1B,WAAO,KAAK5B,OAAZ;AACD;;AAEM6B,EAAAA,WAAW,GAAW;AAC3B,WAAO,KAAKzB,QAAZ;AACD;;AAEM0B,EAAAA,KAAK,GAAS;AACnB,SAAKvC,WAAL,GAAmB,CAACZ,GAAD,EAAMA,GAAN,CAAnB;AACA,SAAK+B,YAAL,GAAoB,KAApB;AACD;;AAzJH","sourcesContent":["import { AdaptedEvent, EventTypes } from '../interfaces';\nimport PointerTracker from '../tools/PointerTracker';\n\nexport interface RotationGestureListener {\n onRotationBegin: (detector: RotationGestureDetector) => boolean;\n onRotation: (detector: RotationGestureDetector) => boolean;\n onRotationEnd: (detector: RotationGestureDetector) => void;\n}\n\nexport default class RotationGestureDetector\n implements RotationGestureListener\n{\n onRotationBegin: (detector: RotationGestureDetector) => boolean;\n onRotation: (detector: RotationGestureDetector) => boolean;\n onRotationEnd: (detector: RotationGestureDetector) => void;\n\n private currentTime = 0;\n private previousTime = 0;\n\n private previousAngle = 0;\n private rotation = 0;\n\n private anchorX = 0;\n private anchorY = 0;\n\n private isInProgress = false;\n\n private keyPointers: number[] = [NaN, NaN];\n\n constructor(callbacks: RotationGestureListener) {\n this.onRotationBegin = callbacks.onRotationBegin;\n this.onRotation = callbacks.onRotation;\n this.onRotationEnd = callbacks.onRotationEnd;\n }\n\n private updateCurrent(event: AdaptedEvent, tracker: PointerTracker): void {\n this.previousTime = this.currentTime;\n this.currentTime = event.time;\n\n const [firstPointerID, secondPointerID] = this.keyPointers;\n\n const firstPointerCoords = tracker.getLastAbsoluteCoords(firstPointerID);\n const secondPointerCoords = tracker.getLastAbsoluteCoords(secondPointerID);\n\n const vectorX: number = secondPointerCoords.x - firstPointerCoords.x;\n const vectorY: number = secondPointerCoords.y - firstPointerCoords.y;\n\n this.anchorX = (firstPointerCoords.x + secondPointerCoords.x) / 2;\n this.anchorY = (firstPointerCoords.y + secondPointerCoords.y) / 2;\n\n //Angle diff should be positive when rotating in clockwise direction\n const angle: number = -Math.atan2(vectorY, vectorX);\n\n this.rotation = Number.isNaN(this.previousAngle)\n ? 0\n : this.previousAngle - angle;\n\n this.previousAngle = angle;\n\n if (this.rotation > Math.PI) {\n this.rotation -= Math.PI;\n } else if (this.rotation < -Math.PI) {\n this.rotation += Math.PI;\n }\n\n if (this.rotation > Math.PI / 2) {\n this.rotation -= Math.PI;\n } else if (this.rotation < -Math.PI / 2) {\n this.rotation += Math.PI;\n }\n }\n\n private finish(): void {\n if (!this.isInProgress) {\n return;\n }\n\n this.isInProgress = false;\n this.keyPointers = [NaN, NaN];\n this.onRotationEnd(this);\n }\n\n private setKeyPointers(tracker: PointerTracker): void {\n if (this.keyPointers[0] && this.keyPointers[1]) {\n return;\n }\n\n const pointerIDs: IterableIterator<number> = tracker.getData().keys();\n\n this.keyPointers[0] = pointerIDs.next().value as number;\n this.keyPointers[1] = pointerIDs.next().value as number;\n }\n\n public onTouchEvent(event: AdaptedEvent, tracker: PointerTracker): boolean {\n switch (event.eventType) {\n case EventTypes.DOWN:\n this.isInProgress = false;\n break;\n\n case EventTypes.ADDITIONAL_POINTER_DOWN:\n if (this.isInProgress) {\n break;\n }\n this.isInProgress = true;\n\n this.previousTime = event.time;\n this.previousAngle = NaN;\n\n this.setKeyPointers(tracker);\n\n this.updateCurrent(event, tracker);\n this.onRotationBegin(this);\n break;\n\n case EventTypes.MOVE:\n if (!this.isInProgress) {\n break;\n }\n\n this.updateCurrent(event, tracker);\n this.onRotation(this);\n\n break;\n\n case EventTypes.ADDITIONAL_POINTER_UP:\n if (!this.isInProgress) {\n break;\n }\n\n if (this.keyPointers.indexOf(event.pointerId) >= 0) {\n this.finish();\n }\n\n break;\n\n case EventTypes.UP:\n if (this.isInProgress) {\n this.finish();\n }\n break;\n }\n\n return true;\n }\n\n public getTimeDelta(): number {\n return this.currentTime + this.previousTime;\n }\n\n public getAnchorX(): number {\n return this.anchorX;\n }\n\n public getAnchorY(): number {\n return this.anchorY;\n }\n\n public getRotation(): number {\n return this.rotation;\n }\n\n public reset(): void {\n this.keyPointers = [NaN, NaN];\n this.isInProgress = false;\n }\n}\n"]}
@@ -60,10 +60,9 @@ export default class ScaleGestureDetector {
60
60
  const ignoredPointer = pointerUp ? event.pointerId : undefined; //Determine focal point
61
61
 
62
62
  const div = pointerUp ? numOfPointers - 1 : numOfPointers;
63
- const sumX = tracker.getSumX(ignoredPointer);
64
- const sumY = tracker.getSumY(ignoredPointer);
65
- const focusX = sumX / div;
66
- const focusY = sumY / div; //Determine average deviation from focal point
63
+ const coordsSum = tracker.getAbsoluteCoordsSum();
64
+ const focusX = coordsSum.x / div;
65
+ const focusY = coordsSum.y / div; //Determine average deviation from focal point
67
66
 
68
67
  let devSumX = 0;
69
68
  let devSumY = 0;
@@ -72,8 +71,8 @@ export default class ScaleGestureDetector {
72
71
  return;
73
72
  }
74
73
 
75
- devSumX += Math.abs(value.lastX - focusX);
76
- devSumY += Math.abs(value.lastY - focusY);
74
+ devSumX += Math.abs(value.abosoluteCoords.x - focusX);
75
+ devSumY += Math.abs(value.abosoluteCoords.y - focusY);
77
76
  });
78
77
  const devX = devSumX / div;
79
78
  const devY = devSumY / div;
@@ -1 +1 @@
1
- {"version":3,"sources":["ScaleGestureDetector.ts"],"names":["DEFAULT_TOUCH_SLOP","EventTypes","ScaleGestureDetector","constructor","callbacks","onScaleBegin","onScale","onScaleEnd","spanSlop","minSpan","onTouchEvent","event","tracker","currentTime","time","action","eventType","numOfPointers","getTrackedPointersCount","streamComplete","UP","ADDITIONAL_POINTER_UP","CANCEL","DOWN","inProgress","initialSpan","configChanged","ADDITIONAL_POINTER_DOWN","pointerUp","ignoredPointer","pointerId","undefined","div","sumX","getSumX","sumY","getSumY","focusX","focusY","devSumX","devSumY","getData","forEach","value","key","Math","abs","lastX","lastY","devX","devY","spanX","spanY","span","hypot","wasInProgress","prevSpan","currentSpan","prevTime","MOVE","getCurrentSpan","getFocusX","getFocusY","getTimeDelta","getScaleFactor"],"mappings":";;AAAA,SAASA,kBAAT,QAAmC,cAAnC;AACA,SAAuBC,UAAvB,QAAyC,eAAzC;AAUA,eAAe,MAAMC,oBAAN,CAA2D;AAoBjEC,EAAAA,WAAW,CAACC,SAAD,EAAkC;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA,wCAL/B,KAK+B;;AAAA;;AAAA;;AAClD,SAAKC,YAAL,GAAoBD,SAAS,CAACC,YAA9B;AACA,SAAKC,OAAL,GAAeF,SAAS,CAACE,OAAzB;AACA,SAAKC,UAAL,GAAkBH,SAAS,CAACG,UAA5B;AAEA,SAAKC,QAAL,GAAgBR,kBAAkB,GAAG,CAArC;AACA,SAAKS,OAAL,GAAe,CAAf;AACD;;AAEMC,EAAAA,YAAY,CAACC,KAAD,EAAsBC,OAAtB,EAAwD;AACzE,SAAKC,WAAL,GAAmBF,KAAK,CAACG,IAAzB;AAEA,UAAMC,MAAkB,GAAGJ,KAAK,CAACK,SAAjC;AACA,UAAMC,aAAa,GAAGL,OAAO,CAACM,uBAAR,EAAtB;AAEA,UAAMC,cAAuB,GAC3BJ,MAAM,KAAKd,UAAU,CAACmB,EAAtB,IACAL,MAAM,KAAKd,UAAU,CAACoB,qBADtB,IAEAN,MAAM,KAAKd,UAAU,CAACqB,MAHxB;;AAKA,QAAIP,MAAM,KAAKd,UAAU,CAACsB,IAAtB,IAA8BJ,cAAlC,EAAkD;AAChD,UAAI,KAAKK,UAAT,EAAqB;AACnB,aAAKjB,UAAL,CAAgB,IAAhB;AACA,aAAKiB,UAAL,GAAkB,KAAlB;AACA,aAAKC,WAAL,GAAmB,CAAnB;AACD;;AAED,UAAIN,cAAJ,EAAoB;AAClB,eAAO,IAAP;AACD;AACF;;AAED,UAAMO,aAAsB,GAC1BX,MA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,WAAO,KAAKxB,MAAZ;AACD;;AAEMyB,EAAAA,SAAS,GAAW;AACzB,WAAO,KAAKxB,MAAZ;AACD;;AAEMyB,EAAAA,YAAY,GAAW;AAC5B,WAAO,KAAKlD,WAAL,GAAmB,KAAK6C,QAA/B;AACD;;AAEMM,EAAAA,cAAc,CAAC/C,aAAD,EAAgC;AACnD,QAAIA,aAAa,GAAG,CAApB,EAAuB;AACrB,aAAO,CAAP;AACD;;AAED,WAAO,KAAKuC,QAAL,GAAgB,CAAhB,GAAoB,KAAKC,WAAL,GAAmB,KAAKD,QAA5C,GAAuD,CAA9D;AACD;;AA/JuE","sourcesContent":["import { DEFAULT_TOUCH_SLOP } from '../constants';\nimport { AdaptedEvent, EventTypes } from '../interfaces';\n\nimport PointerTracker from '../tools/PointerTracker';\n\nexport interface ScaleGestureListener {\n onScaleBegin: (detector: ScaleGestureDetector) => boolean;\n onScale: (detector: ScaleGestureDetector) => boolean;\n onScaleEnd: (detector: ScaleGestureDetector) => void;\n}\n\nexport default class ScaleGestureDetector implements ScaleGestureListener {\n public onScaleBegin: (detector: ScaleGestureDetector) => boolean;\n public onScale: (detector: ScaleGestureDetector) => boolean;\n public onScaleEnd: (detector: ScaleGestureDetector) => void;\n\n private focusX!: number;\n private focusY!: number;\n\n private currentSpan!: number;\n private prevSpan!: number;\n private initialSpan!: number;\n\n private currentTime!: number;\n private prevTime!: number;\n\n private inProgress = false;\n\n private spanSlop: number;\n private minSpan: number;\n\n public constructor(callbacks: ScaleGestureListener) {\n this.onScaleBegin = callbacks.onScaleBegin;\n this.onScale = callbacks.onScale;\n this.onScaleEnd = callbacks.onScaleEnd;\n\n this.spanSlop = DEFAULT_TOUCH_SLOP * 2;\n this.minSpan = 0;\n }\n\n public onTouchEvent(event: AdaptedEvent, tracker: PointerTracker): boolean {\n this.currentTime = event.time;\n\n const action: EventTypes = event.eventType;\n const numOfPointers = tracker.getTrackedPointersCount();\n\n const streamComplete: boolean =\n action === EventTypes.UP ||\n action === EventTypes.ADDITIONAL_POINTER_UP ||\n action === EventTypes.CANCEL;\n\n if (action === EventTypes.DOWN || streamComplete) {\n if (this.inProgress) {\n this.onScaleEnd(this);\n this.inProgress = false;\n this.initialSpan = 0;\n }\n\n if (streamComplete) {\n return true;\n }\n }\n\n const configChanged: boolean =\n action === EventTypes.DOWN ||\n action === EventTypes.ADDITIONAL_POINTER_UP ||\n action === EventTypes.ADDITIONAL_POINTER_DOWN;\n\n const pointerUp = action === EventTypes.ADDITIONAL_POINTER_UP;\n\n const ignoredPointer: number | undefined = pointerUp\n ? event.pointerId\n : undefined;\n\n //Determine focal point\n\n const div: number = pointerUp ? numOfPointers - 1 : numOfPointers;\n\n const sumX = tracker.getSumX(ignoredPointer);\n const sumY = tracker.getSumY(ignoredPointer);\n\n const focusX = sumX / div;\n const focusY = sumY / div;\n\n //Determine average deviation from focal point\n\n let devSumX = 0;\n let devSumY = 0;\n\n tracker.getData().forEach((value, key) => {\n if (key === ignoredPointer) {\n return;\n }\n\n devSumX += Math.abs(value.lastX - focusX);\n devSumY += Math.abs(value.lastY - focusY);\n });\n\n const devX: number = devSumX / div;\n const devY: number = devSumY / div;\n\n const spanX: number = devX * 2;\n const spanY: number = devY * 2;\n\n const span = Math.hypot(spanX, spanY);\n\n //Begin/end events\n const wasInProgress: boolean = this.inProgress;\n this.focusX = focusX;\n this.focusY = focusY;\n\n if (this.inProgress && (span < this.minSpan || configChanged)) {\n this.onScaleEnd(this);\n this.inProgress = false;\n this.initialSpan = span;\n }\n\n if (configChanged) {\n this.initialSpan = this.prevSpan = this.currentSpan = span;\n }\n\n if (\n !this.inProgress &&\n span >= this.minSpan &&\n (wasInProgress || Math.abs(span - this.initialSpan) > this.spanSlop)\n ) {\n this.prevSpan = this.currentSpan = span;\n this.prevTime = this.currentTime;\n this.inProgress = this.onScaleBegin(this);\n }\n\n //Handle motion\n if (action !== EventTypes.MOVE) {\n return true;\n }\n\n this.currentSpan = span;\n\n if (this.inProgress && !this.onScale(this)) {\n return true;\n }\n\n this.prevSpan = this.currentSpan;\n this.prevTime = this.currentTime;\n\n return true;\n }\n\n public getCurrentSpan(): number {\n return this.currentSpan;\n }\n\n public getFocusX(): number {\n return this.focusX;\n }\n\n public getFocusY(): number {\n return this.focusY;\n }\n\n public getTimeDelta(): number {\n return this.currentTime - this.prevTime;\n }\n\n public getScaleFactor(numOfPointers: number): number {\n if (numOfPointers < 2) {\n return 1;\n }\n\n return this.prevSpan > 0 ? this.currentSpan / this.prevSpan : 1;\n }\n}\n"]}
1
+ {"version":3,"sources":["ScaleGestureDetector.ts"],"names":["DEFAULT_TOUCH_SLOP","EventTypes","ScaleGestureDetector","constructor","callbacks","onScaleBegin","onScale","onScaleEnd","spanSlop","minSpan","onTouchEvent","event","tracker","currentTime","time","action","eventType","numOfPointers","getTrackedPointersCount","streamComplete","UP","ADDITIONAL_POINTER_UP","CANCEL","DOWN","inProgress","initialSpan","configChanged","ADDITIONAL_POINTER_DOWN","pointerUp","ignoredPointer","pointerId","undefined","div","coordsSum","getAbsoluteCoordsSum","focusX","x","focusY","y","devSumX","devSumY","getData","forEach","value","key","Math","abs","abosoluteCoords","devX","devY","spanX","spanY","span","hypot","wasInProgress","prevSpan","currentSpan","prevTime","MOVE","getCurrentSpan","getFocusX","getFocusY","getTimeDelta","getScaleFactor"],"mappings":";;AAAA,SAASA,kBAAT,QAAmC,cAAnC;AACA,SAAuBC,UAAvB,QAAyC,eAAzC;AAUA,eAAe,MAAMC,oBAAN,CAA2D;AAoBjEC,EAAAA,WAAW,CAACC,SAAD,EAAkC;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA,wCAL/B,KAK+B;;AAAA;;AAAA;;AAClD,SAAKC,YAAL,GAAoBD,SAAS,CAACC,YAA9B;AACA,SAAKC,OAAL,GAAeF,SAAS,CAACE,OAAzB;AACA,SAAKC,UAAL,GAAkBH,SAAS,CAACG,UAA5B;AAEA,SAAKC,QAAL,GAA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IAAI,CAACC,GAAL,CAASM,IAAI,GAAG,KAAK3B,WAArB,IAAoC,KAAKjB,QAF3D,CADF,EAIE;AACA,WAAK+C,QAAL,GAAgB,KAAKC,WAAL,GAAmBJ,IAAnC;AACA,WAAKK,QAAL,GAAgB,KAAK5C,WAArB;AACA,WAAKW,UAAL,GAAkB,KAAKnB,YAAL,CAAkB,IAAlB,CAAlB;AACD,KAxFwE,CA0FzE;;;AACA,QAAIU,MAAM,KAAKd,UAAU,CAACyD,IAA1B,EAAgC;AAC9B,aAAO,IAAP;AACD;;AAED,SAAKF,WAAL,GAAmBJ,IAAnB;;AAEA,QAAI,KAAK5B,UAAL,IAAmB,CAAC,KAAKlB,OAAL,CAAa,IAAb,CAAxB,EAA4C;AAC1C,aAAO,IAAP;AACD;;AAED,SAAKiD,QAAL,GAAgB,KAAKC,WAArB;AACA,SAAKC,QAAL,GAAgB,KAAK5C,WAArB;AAEA,WAAO,IAAP;AACD;;AAEM8C,EAAAA,cAAc,GAAW;AAC9B,WAAO,KAAKH,WAAZ;AACD;;AAEMI,EAAAA,SAAS,GAAW;AACzB,WAAO,KAAKzB,MAAZ;AACD;;AAEM0B,EAAAA,SAAS,GAAW;AACzB,WAAO,KAAKxB,MAAZ;AACD;;AAEMyB,EAAAA,YAAY,GAAW;AAC5B,WAAO,KAAKjD,WAAL,GAAmB,KAAK4C,QAA/B;AACD;;AAEMM,EAAAA,cAAc,CAAC9C,aAAD,EAAgC;AACnD,QAAIA,aAAa,GAAG,CAApB,EAAuB;AACrB,aAAO,CAAP;AACD;;AAED,WAAO,KAAKsC,QAAL,GAAgB,CAAhB,GAAoB,KAAKC,WAAL,GAAmB,KAAKD,QAA5C,GAAuD,CAA9D;AACD;;AA9JuE","sourcesContent":["import { DEFAULT_TOUCH_SLOP } from '../constants';\nimport { AdaptedEvent, EventTypes } from '../interfaces';\n\nimport PointerTracker from '../tools/PointerTracker';\n\nexport interface ScaleGestureListener {\n onScaleBegin: (detector: ScaleGestureDetector) => boolean;\n onScale: (detector: ScaleGestureDetector) => boolean;\n onScaleEnd: (detector: ScaleGestureDetector) => void;\n}\n\nexport default class ScaleGestureDetector implements ScaleGestureListener {\n public onScaleBegin: (detector: ScaleGestureDetector) => boolean;\n public onScale: (detector: ScaleGestureDetector) => boolean;\n public onScaleEnd: (detector: ScaleGestureDetector) => void;\n\n private focusX!: number;\n private focusY!: number;\n\n private currentSpan!: number;\n private prevSpan!: number;\n private initialSpan!: number;\n\n private currentTime!: number;\n private prevTime!: number;\n\n private inProgress = false;\n\n private spanSlop: number;\n private minSpan: number;\n\n public constructor(callbacks: ScaleGestureListener) {\n this.onScaleBegin = callbacks.onScaleBegin;\n this.onScale = callbacks.onScale;\n this.onScaleEnd = callbacks.onScaleEnd;\n\n this.spanSlop = DEFAULT_TOUCH_SLOP * 2;\n this.minSpan = 0;\n }\n\n public onTouchEvent(event: AdaptedEvent, tracker: PointerTracker): boolean {\n this.currentTime = event.time;\n\n const action: EventTypes = event.eventType;\n const numOfPointers = tracker.getTrackedPointersCount();\n\n const streamComplete: boolean =\n action === EventTypes.UP ||\n action === EventTypes.ADDITIONAL_POINTER_UP ||\n action === EventTypes.CANCEL;\n\n if (action === EventTypes.DOWN || streamComplete) {\n if (this.inProgress) {\n this.onScaleEnd(this);\n this.inProgress = false;\n this.initialSpan = 0;\n }\n\n if (streamComplete) {\n return true;\n }\n }\n\n const configChanged: boolean =\n action === EventTypes.DOWN ||\n action === EventTypes.ADDITIONAL_POINTER_UP ||\n action === EventTypes.ADDITIONAL_POINTER_DOWN;\n\n const pointerUp = action === EventTypes.ADDITIONAL_POINTER_UP;\n\n const ignoredPointer: number | undefined = pointerUp\n ? event.pointerId\n : undefined;\n\n //Determine focal point\n\n const div: number = pointerUp ? numOfPointers - 1 : numOfPointers;\n\n const coordsSum = tracker.getAbsoluteCoordsSum();\n\n const focusX = coordsSum.x / div;\n const focusY = coordsSum.y / div;\n\n //Determine average deviation from focal point\n\n let devSumX = 0;\n let devSumY = 0;\n\n tracker.getData().forEach((value, key) => {\n if (key === ignoredPointer) {\n return;\n }\n\n devSumX += Math.abs(value.abosoluteCoords.x - focusX);\n devSumY += Math.abs(value.abosoluteCoords.y - focusY);\n });\n\n const devX: number = devSumX / div;\n const devY: number = devSumY / div;\n\n const spanX: number = devX * 2;\n const spanY: number = devY * 2;\n\n const span = Math.hypot(spanX, spanY);\n\n //Begin/end events\n const wasInProgress: boolean = this.inProgress;\n this.focusX = focusX;\n this.focusY = focusY;\n\n if (this.inProgress && (span < this.minSpan || configChanged)) {\n this.onScaleEnd(this);\n this.inProgress = false;\n this.initialSpan = span;\n }\n\n if (configChanged) {\n this.initialSpan = this.prevSpan = this.currentSpan = span;\n }\n\n if (\n !this.inProgress &&\n span >= this.minSpan &&\n (wasInProgress || Math.abs(span - this.initialSpan) > this.spanSlop)\n ) {\n this.prevSpan = this.currentSpan = span;\n this.prevTime = this.currentTime;\n this.inProgress = this.onScaleBegin(this);\n }\n\n //Handle motion\n if (action !== EventTypes.MOVE) {\n return true;\n }\n\n this.currentSpan = span;\n\n if (this.inProgress && !this.onScale(this)) {\n return true;\n }\n\n this.prevSpan = this.currentSpan;\n this.prevTime = this.currentTime;\n\n return true;\n }\n\n public getCurrentSpan(): number {\n return this.currentSpan;\n }\n\n public getFocusX(): number {\n return this.focusX;\n }\n\n public getFocusY(): number {\n return this.focusY;\n }\n\n public getTimeDelta(): number {\n return this.currentTime - this.prevTime;\n }\n\n public getScaleFactor(numOfPointers: number): number {\n if (numOfPointers < 2) {\n return 1;\n }\n\n return this.prevSpan > 0 ? this.currentSpan / this.prevSpan : 1;\n }\n}\n"]}
@@ -98,6 +98,7 @@ export default class FlingGestureHandler extends GestureHandler {
98
98
  this.keyPointer = event.pointerId;
99
99
  super.onPointerDown(event);
100
100
  this.newPointerAction();
101
+ this.tryToSendTouchEvent(event);
101
102
  }
102
103
 
103
104
  onPointerAdd(event) {
@@ -1 +1 @@
1
- {"version":3,"sources":["FlingGestureHandler.ts"],"names":["State","DiagonalDirections","Directions","GestureHandler","Vector","coneToDeviation","DEFAULT_MAX_DURATION_MS","DEFAULT_MIN_VELOCITY","DEFAULT_ALIGNMENT_CONE","DEFAULT_DIRECTION","RIGHT","DEFAULT_NUMBER_OF_TOUCHES_REQUIRED","AXIAL_DEVIATION_COSINE","DIAGONAL_DEVIATION_COSINE","FlingGestureHandler","NaN","init","ref","propsRef","updateGestureConfig","enabled","props","config","direction","numberOfPointers","numberOfPointersRequired","startFling","begin","maxNumberOfPointersSimultaneously","delayTimeout","setTimeout","fail","maxDurationMs","tryEndFling","velocityVector","fromVelocity","tracker","keyPointer","getAlignment","minimalAlignmentCosine","isSimilar","fromDirection","axialDirectionsList","Object","values","diagonalDirectionsList","axialAlignmentList","map","diagonalAlignmentList","isAligned","some","Boolean","isFast","magnitude","minVelocity","clearTimeout","activate","endFling","onPointerDown","event","isButtonInConfig","button","addToTracker","pointerId","newPointerAction","onPointerAdd","currentState","UNDETERMINED","BEGAN","getTrackedPointersCount","pointerMoveAction","track","onPointerMove","onPointerOutOfBounds","onPointerUp","onUp","onPointerRemove","removeFromTracker","force","end","resetConfig"],"mappings":";;AAAA,SAASA,KAAT,QAAsB,aAAtB;AACA,SAASC,kBAAT,EAA6BC,UAA7B,QAA+C,kBAA/C;AAGA,OAAOC,cAAP,MAA2B,kBAA3B;AACA,OAAOC,MAAP,MAAmB,iBAAnB;AACA,SAASC,eAAT,QAAgC,UAAhC;AAEA,MAAMC,uBAAuB,GAAG,GAAhC;AACA,MAAMC,oBAAoB,GAAG,GAA7B;AACA,MAAMC,sBAAsB,GAAG,EAA/B;AACA,MAAMC,iBAAiB,GAAGP,UAAU,CAACQ,KAArC;AACA,MAAMC,kCAAkC,GAAG,CAA3C;AAEA,MAAMC,sBAAsB,GAAGP,eAAe,CAACG,sBAAD,CAA9C;AACA,MAAMK,yBAAyB,GAAGR,eAAe,CAAC,KAAKG,sBAAN,CAAjD;AAEA,eAAe,MAAMM,mBAAN,SAAkCX,cAAlC,CAA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KX,QAAL;AACD;;AAED,SAAKrB,OAAL,CAAayC,iBAAb,CAA+BlB,KAAK,CAACI,SAArC;AACD;;AAEMP,EAAAA,QAAQ,CAACsB,KAAD,EAAwB;AACrC,UAAMtB,QAAN,CAAesB,KAAf;AACA,SAAKC,GAAL;AACD;;AAESC,EAAAA,WAAW,GAAS;AAC5B,UAAMA,WAAN;AACA,SAAKvD,wBAAL,GAAgCd,kCAAhC;AACA,SAAKY,SAAL,GAAiBd,iBAAjB;AACD;;AAhL6D","sourcesContent":["import { State } from '../../State';\nimport { DiagonalDirections, Directions } from '../../Directions';\nimport { AdaptedEvent, Config } from '../interfaces';\n\nimport GestureHandler from './GestureHandler';\nimport Vector from '../tools/Vector';\nimport { coneToDeviation } from '../utils';\n\nconst DEFAULT_MAX_DURATION_MS = 800;\nconst DEFAULT_MIN_VELOCITY = 700;\nconst DEFAULT_ALIGNMENT_CONE = 30;\nconst DEFAULT_DIRECTION = Directions.RIGHT;\nconst DEFAULT_NUMBER_OF_TOUCHES_REQUIRED = 1;\n\nconst AXIAL_DEVIATION_COSINE = coneToDeviation(DEFAULT_ALIGNMENT_CONE);\nconst DIAGONAL_DEVIATION_COSINE = coneToDeviation(90 - DEFAULT_ALIGNMENT_CONE);\n\nexport default class FlingGestureHandler extends GestureHandler {\n private numberOfPointersRequired = DEFAULT_NUMBER_OF_TOUCHES_REQUIRED;\n private direction: Directions = DEFAULT_DIRECTION;\n\n private maxDurationMs = DEFAULT_MAX_DURATION_MS;\n private minVelocity = DEFAULT_MIN_VELOCITY;\n private delayTimeout!: number;\n\n private maxNumberOfPointersSimultaneously = 0;\n private keyPointer = NaN;\n\n public init(ref: number, propsRef: React.RefObject<unknown>): void {\n super.init(ref, propsRef);\n }\n\n public updateGestureConfig({ enabled = true, ...props }: Config): void {\n super.updateGestureConfig({ enabled: enabled, ...props });\n\n if (this.config.direction) {\n this.direction = this.config.direction;\n }\n\n if (this.config.numberOfPointers) {\n this.numberOfPointersRequired = this.config.numberOfPointers;\n }\n }\n\n private startFling(): void {\n this.begin();\n\n this.maxNumberOfPointersSimultaneously = 1;\n\n this.delayTimeout = setTimeout(() => this.fail(), this.maxDurationMs);\n }\n\n private tryEndFling(): boolean {\n const velocityVector = Vector.fromVelocity(this.tracker, this.keyPointer);\n\n const getAlignment = (\n direction: Directions | DiagonalDirections,\n minimalAlignmentCosine: number\n ) => {\n return (\n (direction & this.direction) === direction &&\n velocityVector.isSimilar(\n Vector.fromDirection(direction),\n minimalAlignmentCosine\n )\n );\n };\n\n const axialDirectionsList = Object.values(Directions);\n const diagonalDirectionsList = Object.values(DiagonalDirections);\n\n // list of alignments to all activated directions\n const axialAlignmentList = axialDirectionsList.map((direction) =>\n getAlignment(direction, AXIAL_DEVIATION_COSINE)\n );\n\n const diagonalAlignmentList = diagonalDirectionsList.map((direction) =>\n getAlignment(direction, DIAGONAL_DEVIATION_COSINE)\n );\n\n const isAligned =\n axialAlignmentList.some(Boolean) || diagonalAlignmentList.some(Boolean);\n\n const isFast = velocityVector.magnitude > this.minVelocity;\n\n if (\n this.maxNumberOfPointersSimultaneously ===\n this.numberOfPointersRequired &&\n isAligned &&\n isFast\n ) {\n clearTimeout(this.delayTimeout);\n this.activate();\n\n return true;\n }\n\n return false;\n }\n\n private endFling() {\n if (!this.tryEndFling()) {\n this.fail();\n }\n }\n\n protected onPointerDown(event: AdaptedEvent): void {\n if (!this.isButtonInConfig(event.button)) {\n return;\n }\n\n this.tracker.addToTracker(event);\n this.keyPointer = event.pointerId;\n\n super.onPointerDown(event);\n this.newPointerAction();\n }\n\n protected onPointerAdd(event: AdaptedEvent): void {\n this.tracker.addToTracker(event);\n super.onPointerAdd(event);\n this.newPointerAction();\n }\n\n private newPointerAction(): void {\n if (this.currentState === State.UNDETERMINED) {\n this.startFling();\n }\n\n if (this.currentState !== State.BEGAN) {\n return;\n }\n\n this.tryEndFling();\n\n if (\n this.tracker.getTrackedPointersCount() >\n this.maxNumberOfPointersSimultaneously\n ) {\n this.maxNumberOfPointersSimultaneously =\n this.tracker.getTrackedPointersCount();\n }\n }\n\n private pointerMoveAction(event: AdaptedEvent): void {\n this.tracker.track(event);\n\n if (this.currentState !== State.BEGAN) {\n return;\n }\n\n this.tryEndFling();\n }\n\n protected onPointerMove(event: AdaptedEvent): void {\n this.pointerMoveAction(event);\n super.onPointerMove(event);\n }\n\n protected onPointerOutOfBounds(event: AdaptedEvent): void {\n this.pointerMoveAction(event);\n super.onPointerOutOfBounds(event);\n }\n\n protected onPointerUp(event: AdaptedEvent): void {\n super.onPointerUp(event);\n this.onUp(event);\n\n this.keyPointer = NaN;\n }\n\n protected onPointerRemove(event: AdaptedEvent): void {\n super.onPointerRemove(event);\n this.onUp(event);\n }\n\n private onUp(event: AdaptedEvent): void {\n if (this.currentState === State.BEGAN) {\n this.endFling();\n }\n\n this.tracker.removeFromTracker(event.pointerId);\n }\n\n public activate(force?: boolean): void {\n super.activate(force);\n this.end();\n }\n\n protected resetConfig(): void {\n super.resetConfig();\n this.numberOfPointersRequired = DEFAULT_NUMBER_OF_TOUCHES_REQUIRED;\n this.direction = DEFAULT_DIRECTION;\n }\n}\n"]}
1
+ {"version":3,"sources":["FlingGestureHandler.ts"],"names":["State","DiagonalDirections","Directions","GestureHandler","Vector","coneToDeviation","DEFAULT_MAX_DURATION_MS","DEFAULT_MIN_VELOCITY","DEFAULT_ALIGNMENT_CONE","DEFAULT_DIRECTION","RIGHT","DEFAULT_NUMBER_OF_TOUCHES_REQUIRED","AXIAL_DEVIATION_COSINE","DIAGONAL_DEVIATION_COSINE","FlingGestureHandler","NaN","init","ref","propsRef","updateGestureConfig","enabled","props","config","direction","numberOfPointers","numberOfPointersRequired","startFling","begin","maxNumberOfPointersSimultaneously","delayTimeout","setTimeout","fail","maxDurationMs","tryEndFling","velocityVector","fromVelocity","tracker","keyPointer","getAlignment","minimalAlignmentCosine","isSimilar","fromDirection","axialDirectionsList","Object","values","diagonalDirectionsList","axialAlignmentList","map","diagonalAlignmentList","isAligned","some","Boolean","isFast","magnitude","minVelocity","clearTimeout","activate","endFling","onPointerDown","event","isButtonInConfig","button","addToTracker","pointerId","newPointerAction","tryToSendTouchEvent","onPointerAdd","currentState","UNDETERMINED","BEGAN","getTrackedPointersCount","pointerMoveAction","track","onPointerMove","onPointerOutOfBounds","onPointerUp","onUp","onPointerRemove","removeFromTracker","force","end","resetConfig"],"mappings":";;AAAA,SAASA,KAAT,QAAsB,aAAtB;AACA,SAASC,kBAAT,EAA6BC,UAA7B,QAA+C,kBAA/C;AAGA,OAAOC,cAAP,MAA2B,kBAA3B;AACA,OAAOC,MAAP,MAAmB,iBAAnB;AACA,SAASC,eAAT,QAAgC,UAAhC;AAEA,MAAMC,uBAAuB,GAAG,GAAhC;AACA,MAAMC,oBAAoB,GAAG,GAA7B;AACA,MAAMC,sBAAsB,GAAG,EAA/B;AACA,MAAMC,iBAAiB,GAAGP,UAAU,CAACQ,KAArC;AACA,MAAMC,kCAAkC,GAAG,CAA3C;AAEA,MAAMC,sBAAsB,GAAGP,eAAe,CAACG,sBAAD,CAA9C;AACA,MAAMK,yBAAyB,GAAGR,eAAe,CAAC,KAAKG,sBAAN,CAAjD;AAEA,eAAe,MAAMM,mBAAN,SAAkCX,cAAlC,CAAiD;AAAA;AAAA;;AAAA,sDAC3BQ,kCAD2B;;AAAA,uCAE9BF,iBAF8B;;AAAA,2CAItCH,uBAJsC;;AAAA,yCAKxCC,oBALwC;;AAAA;;AAAA,+DAQlB,CARkB;;AAAA,wCASzCQ,GATyC;AAAA;;AAWvDC,EAAAA,IAAI,CAACC,GAAD,EAAcC,QAAd,EAAwD;AACjE,UAAMF,IAAN,CAAWC,GAAX,EAAgBC,QAAhB;AACD;;AAEMC,EAAAA,mBAAmB,CAAC;AAAEC,IAAAA,OAAO,GAAG,IAAZ;AAAkB,OAAGC;AAArB,GAAD,EAA6C;AACrE,UAAMF,mBAAN,CAA0B;AAAEC,MAAAA,OAAO,EAAEA,OAAX;AAAoB,SAAGC;AAAvB,KAA1B;;AA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AiB,CAACZ,KAAD,EAA4B;AACnD,SAAKvB,OAAL,CAAaoC,KAAb,CAAmBb,KAAnB;;AAEA,QAAI,KAAKQ,YAAL,KAAsBnE,KAAK,CAACqE,KAAhC,EAAuC;AACrC;AACD;;AAED,SAAKpC,WAAL;AACD;;AAESwC,EAAAA,aAAa,CAACd,KAAD,EAA4B;AACjD,SAAKY,iBAAL,CAAuBZ,KAAvB;AACA,UAAMc,aAAN,CAAoBd,KAApB;AACD;;AAESe,EAAAA,oBAAoB,CAACf,KAAD,EAA4B;AACxD,SAAKY,iBAAL,CAAuBZ,KAAvB;AACA,UAAMe,oBAAN,CAA2Bf,KAA3B;AACD;;AAESgB,EAAAA,WAAW,CAAChB,KAAD,EAA4B;AAC/C,UAAMgB,WAAN,CAAkBhB,KAAlB;AACA,SAAKiB,IAAL,CAAUjB,KAAV;AAEA,SAAKtB,UAAL,GAAkBtB,GAAlB;AACD;;AAES8D,EAAAA,eAAe,CAAClB,KAAD,EAA4B;AACnD,UAAMkB,eAAN,CAAsBlB,KAAtB;AACA,SAAKiB,IAAL,CAAUjB,KAAV;AACD;;AAEOiB,EAAAA,IAAI,CAACjB,KAAD,EAA4B;AACtC,QAAI,KAAKQ,YAAL,KAAsBnE,KAAK,CAACqE,KAAhC,EAAuC;AACrC,WAAKZ,QAAL;AACD;;AAED,SAAKrB,OAAL,CAAa0C,iBAAb,CAA+BnB,KAAK,CAACI,SAArC;AACD;;AAEMP,EAAAA,QAAQ,CAACuB,KAAD,EAAwB;AACrC,UAAMvB,QAAN,CAAeuB,KAAf;AACA,SAAKC,GAAL;AACD;;AAESC,EAAAA,WAAW,GAAS;AAC5B,UAAMA,WAAN;AACA,SAAKxD,wBAAL,GAAgCd,kCAAhC;AACA,SAAKY,SAAL,GAAiBd,iBAAjB;AACD;;AAlL6D","sourcesContent":["import { State } from '../../State';\nimport { DiagonalDirections, Directions } from '../../Directions';\nimport { AdaptedEvent, Config } from '../interfaces';\n\nimport GestureHandler from './GestureHandler';\nimport Vector from '../tools/Vector';\nimport { coneToDeviation } from '../utils';\n\nconst DEFAULT_MAX_DURATION_MS = 800;\nconst DEFAULT_MIN_VELOCITY = 700;\nconst DEFAULT_ALIGNMENT_CONE = 30;\nconst DEFAULT_DIRECTION = Directions.RIGHT;\nconst DEFAULT_NUMBER_OF_TOUCHES_REQUIRED = 1;\n\nconst AXIAL_DEVIATION_COSINE = coneToDeviation(DEFAULT_ALIGNMENT_CONE);\nconst DIAGONAL_DEVIATION_COSINE = coneToDeviation(90 - DEFAULT_ALIGNMENT_CONE);\n\nexport default class FlingGestureHandler extends GestureHandler {\n private numberOfPointersRequired = DEFAULT_NUMBER_OF_TOUCHES_REQUIRED;\n private direction: Directions = DEFAULT_DIRECTION;\n\n private maxDurationMs = DEFAULT_MAX_DURATION_MS;\n private minVelocity = DEFAULT_MIN_VELOCITY;\n private delayTimeout!: number;\n\n private maxNumberOfPointersSimultaneously = 0;\n private keyPointer = NaN;\n\n public init(ref: number, propsRef: React.RefObject<unknown>): void {\n super.init(ref, propsRef);\n }\n\n public updateGestureConfig({ enabled = true, ...props }: Config): void {\n super.updateGestureConfig({ enabled: enabled, ...props });\n\n if (this.config.direction) {\n this.direction = this.config.direction;\n }\n\n if (this.config.numberOfPointers) {\n this.numberOfPointersRequired = this.config.numberOfPointers;\n }\n }\n\n private startFling(): void {\n this.begin();\n\n this.maxNumberOfPointersSimultaneously = 1;\n\n this.delayTimeout = setTimeout(() => this.fail(), this.maxDurationMs);\n }\n\n private tryEndFling(): boolean {\n const velocityVector = Vector.fromVelocity(this.tracker, this.keyPointer);\n\n const getAlignment = (\n direction: Directions | DiagonalDirections,\n minimalAlignmentCosine: number\n ) => {\n return (\n (direction & this.direction) === direction &&\n velocityVector.isSimilar(\n Vector.fromDirection(direction),\n minimalAlignmentCosine\n )\n );\n };\n\n const axialDirectionsList = Object.values(Directions);\n const diagonalDirectionsList = Object.values(DiagonalDirections);\n\n // list of alignments to all activated directions\n const axialAlignmentList = axialDirectionsList.map((direction) =>\n getAlignment(direction, AXIAL_DEVIATION_COSINE)\n );\n\n const diagonalAlignmentList = diagonalDirectionsList.map((direction) =>\n getAlignment(direction, DIAGONAL_DEVIATION_COSINE)\n );\n\n const isAligned =\n axialAlignmentList.some(Boolean) || diagonalAlignmentList.some(Boolean);\n\n const isFast = velocityVector.magnitude > this.minVelocity;\n\n if (\n this.maxNumberOfPointersSimultaneously ===\n this.numberOfPointersRequired &&\n isAligned &&\n isFast\n ) {\n clearTimeout(this.delayTimeout);\n this.activate();\n\n return true;\n }\n\n return false;\n }\n\n private endFling() {\n if (!this.tryEndFling()) {\n this.fail();\n }\n }\n\n protected onPointerDown(event: AdaptedEvent): void {\n if (!this.isButtonInConfig(event.button)) {\n return;\n }\n\n this.tracker.addToTracker(event);\n this.keyPointer = event.pointerId;\n\n super.onPointerDown(event);\n this.newPointerAction();\n\n this.tryToSendTouchEvent(event);\n }\n\n protected onPointerAdd(event: AdaptedEvent): void {\n this.tracker.addToTracker(event);\n super.onPointerAdd(event);\n this.newPointerAction();\n }\n\n private newPointerAction(): void {\n if (this.currentState === State.UNDETERMINED) {\n this.startFling();\n }\n\n if (this.currentState !== State.BEGAN) {\n return;\n }\n\n this.tryEndFling();\n\n if (\n this.tracker.getTrackedPointersCount() >\n this.maxNumberOfPointersSimultaneously\n ) {\n this.maxNumberOfPointersSimultaneously =\n this.tracker.getTrackedPointersCount();\n }\n }\n\n private pointerMoveAction(event: AdaptedEvent): void {\n this.tracker.track(event);\n\n if (this.currentState !== State.BEGAN) {\n return;\n }\n\n this.tryEndFling();\n }\n\n protected onPointerMove(event: AdaptedEvent): void {\n this.pointerMoveAction(event);\n super.onPointerMove(event);\n }\n\n protected onPointerOutOfBounds(event: AdaptedEvent): void {\n this.pointerMoveAction(event);\n super.onPointerOutOfBounds(event);\n }\n\n protected onPointerUp(event: AdaptedEvent): void {\n super.onPointerUp(event);\n this.onUp(event);\n\n this.keyPointer = NaN;\n }\n\n protected onPointerRemove(event: AdaptedEvent): void {\n super.onPointerRemove(event);\n this.onUp(event);\n }\n\n private onUp(event: AdaptedEvent): void {\n if (this.currentState === State.BEGAN) {\n this.endFling();\n }\n\n this.tracker.removeFromTracker(event.pointerId);\n }\n\n public activate(force?: boolean): void {\n super.activate(force);\n this.end();\n }\n\n protected resetConfig(): void {\n super.resetConfig();\n this.numberOfPointersRequired = DEFAULT_NUMBER_OF_TOUCHES_REQUIRED;\n this.direction = DEFAULT_DIRECTION;\n }\n}\n"]}