react-native-gesture-handler 2.14.1 → 2.16.0-rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (229) hide show
  1. package/README.md +1 -0
  2. package/RNGestureHandler.podspec +3 -24
  3. package/android/build.gradle +1 -1
  4. package/android/paper/src/main/java/com/swmansion/gesturehandler/NativeRNGestureHandlerModuleSpec.java +55 -0
  5. package/android/src/main/java/com/swmansion/gesturehandler/RNGestureHandlerPackage.kt +69 -4
  6. package/android/src/main/java/com/swmansion/gesturehandler/core/FlingGestureHandler.kt +4 -0
  7. package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt +69 -0
  8. package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +37 -21
  9. package/android/src/main/java/com/swmansion/gesturehandler/core/LongPressGestureHandler.kt +5 -1
  10. package/android/src/main/java/com/swmansion/gesturehandler/core/PanGestureHandler.kt +5 -1
  11. package/android/src/main/java/com/swmansion/gesturehandler/core/TapGestureHandler.kt +7 -3
  12. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt +61 -24
  13. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt +3 -2
  14. package/android/src/main/java/com/swmansion/gesturehandler/react/eventbuilders/GestureHandlerEventDataBuilder.kt +3 -0
  15. package/android/src/main/jni/cpp-adapter.cpp +18 -22
  16. package/{ios → apple}/Handlers/RNFlingHandler.m +29 -8
  17. package/{ios → apple}/Handlers/RNForceTouchHandler.m +28 -8
  18. package/{ios → apple}/Handlers/RNHoverHandler.m +28 -2
  19. package/{ios → apple}/Handlers/RNLongPressHandler.m +27 -5
  20. package/{ios → apple}/Handlers/RNManualHandler.m +25 -4
  21. package/{ios → apple}/Handlers/RNNativeViewHandler.mm +51 -13
  22. package/{ios → apple}/Handlers/RNPanHandler.m +106 -16
  23. package/apple/Handlers/RNPinchHandler.m +175 -0
  24. package/apple/Handlers/RNRotationHandler.m +169 -0
  25. package/{ios → apple}/Handlers/RNTapHandler.m +98 -26
  26. package/apple/RNGHUIKit.h +27 -0
  27. package/{ios → apple}/RNGestureHandler.h +12 -3
  28. package/{ios → apple}/RNGestureHandler.m +68 -7
  29. package/{ios → apple}/RNGestureHandlerButton.h +4 -1
  30. package/{ios → apple}/RNGestureHandlerButton.m +12 -4
  31. package/{ios → apple}/RNGestureHandlerButtonManager.m +4 -2
  32. package/{ios → apple}/RNGestureHandlerEvents.h +19 -10
  33. package/{ios → apple}/RNGestureHandlerEvents.m +29 -11
  34. package/{ios → apple}/RNGestureHandlerManager.h +7 -2
  35. package/{ios → apple}/RNGestureHandlerManager.mm +78 -17
  36. package/apple/RNGestureHandlerModule.h +19 -0
  37. package/{ios → apple}/RNGestureHandlerModule.mm +69 -69
  38. package/{ios → apple}/RNGestureHandlerPointerTracker.h +5 -5
  39. package/{ios → apple}/RNGestureHandlerPointerTracker.m +19 -14
  40. package/apple/RNGestureHandlerPointerType.h +8 -0
  41. package/{ios → apple}/RNGestureHandlerRegistry.h +1 -1
  42. package/{ios → apple}/RNGestureHandlerRegistry.m +1 -1
  43. package/{ios → apple}/RNManualActivationRecognizer.h +8 -0
  44. package/{ios → apple}/RNManualActivationRecognizer.m +27 -7
  45. package/{ios → apple}/RNRootViewGestureRecognizer.m +72 -4
  46. package/lib/commonjs/PointerType.js +16 -0
  47. package/lib/commonjs/PointerType.js.map +1 -0
  48. package/lib/commonjs/RNGestureHandlerModule.js +5 -18
  49. package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
  50. package/lib/commonjs/RNGestureHandlerModule.windows.js +10 -102
  51. package/lib/commonjs/RNGestureHandlerModule.windows.js.map +1 -1
  52. package/lib/commonjs/components/DrawerLayout.js +2 -0
  53. package/lib/commonjs/components/DrawerLayout.js.map +1 -1
  54. package/lib/commonjs/components/GestureHandlerRootView.android.js +17 -2
  55. package/lib/commonjs/components/GestureHandlerRootView.android.js.map +1 -1
  56. package/lib/commonjs/components/GestureHandlerRootView.js +15 -2
  57. package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
  58. package/lib/commonjs/components/GestureHandlerRootView.web.js +15 -2
  59. package/lib/commonjs/components/GestureHandlerRootView.web.js.map +1 -1
  60. package/lib/commonjs/getShadowNodeFromRef.js +19 -2
  61. package/lib/commonjs/getShadowNodeFromRef.js.map +1 -1
  62. package/lib/commonjs/handlers/createHandler.js +5 -0
  63. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  64. package/lib/commonjs/handlers/gestureHandlerCommon.js +1 -1
  65. package/lib/commonjs/handlers/gestureHandlerCommon.js.map +1 -1
  66. package/lib/commonjs/handlers/gestures/GestureDetector.js +11 -1
  67. package/lib/commonjs/handlers/gestures/GestureDetector.js.map +1 -1
  68. package/lib/commonjs/handlers/gestures/gesture.js +5 -0
  69. package/lib/commonjs/handlers/gestures/gesture.js.map +1 -1
  70. package/lib/commonjs/index.js +16 -0
  71. package/lib/commonjs/index.js.map +1 -1
  72. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js +13 -0
  73. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -0
  74. package/lib/commonjs/web/handlers/FlingGestureHandler.js +4 -0
  75. package/lib/commonjs/web/handlers/FlingGestureHandler.js.map +1 -1
  76. package/lib/commonjs/web/handlers/GestureHandler.js +19 -4
  77. package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
  78. package/lib/commonjs/web/handlers/LongPressGestureHandler.js +8 -6
  79. package/lib/commonjs/web/handlers/LongPressGestureHandler.js.map +1 -1
  80. package/lib/commonjs/web/handlers/PanGestureHandler.js +4 -0
  81. package/lib/commonjs/web/handlers/PanGestureHandler.js.map +1 -1
  82. package/lib/commonjs/web/handlers/TapGestureHandler.js +4 -0
  83. package/lib/commonjs/web/handlers/TapGestureHandler.js.map +1 -1
  84. package/lib/commonjs/web/interfaces.js +12 -24
  85. package/lib/commonjs/web/interfaces.js.map +1 -1
  86. package/lib/commonjs/web/tools/GestureHandlerOrchestrator.js +3 -3
  87. package/lib/commonjs/web/tools/GestureHandlerOrchestrator.js.map +1 -1
  88. package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js +35 -0
  89. package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js.map +1 -1
  90. package/lib/commonjs/web/tools/NodeManager.js +3 -2
  91. package/lib/commonjs/web/tools/NodeManager.js.map +1 -1
  92. package/lib/commonjs/web/tools/PointerEventManager.js +40 -10
  93. package/lib/commonjs/web/tools/PointerEventManager.js.map +1 -1
  94. package/lib/commonjs/web/tools/TouchEventManager.js +3 -2
  95. package/lib/commonjs/web/tools/TouchEventManager.js.map +1 -1
  96. package/lib/commonjs/web/utils.js +6 -0
  97. package/lib/commonjs/web/utils.js.map +1 -1
  98. package/lib/module/PointerType.js +9 -0
  99. package/lib/module/PointerType.js.map +1 -0
  100. package/lib/module/RNGestureHandlerModule.js +4 -18
  101. package/lib/module/RNGestureHandlerModule.js.map +1 -1
  102. package/lib/module/RNGestureHandlerModule.windows.js +10 -81
  103. package/lib/module/RNGestureHandlerModule.windows.js.map +1 -1
  104. package/lib/module/components/DrawerLayout.js +2 -0
  105. package/lib/module/components/DrawerLayout.js.map +1 -1
  106. package/lib/module/components/GestureHandlerRootView.android.js +15 -2
  107. package/lib/module/components/GestureHandlerRootView.android.js.map +1 -1
  108. package/lib/module/components/GestureHandlerRootView.js +15 -3
  109. package/lib/module/components/GestureHandlerRootView.js.map +1 -1
  110. package/lib/module/components/GestureHandlerRootView.web.js +15 -3
  111. package/lib/module/components/GestureHandlerRootView.web.js.map +1 -1
  112. package/lib/module/getShadowNodeFromRef.js +19 -2
  113. package/lib/module/getShadowNodeFromRef.js.map +1 -1
  114. package/lib/module/handlers/createHandler.js +6 -1
  115. package/lib/module/handlers/createHandler.js.map +1 -1
  116. package/lib/module/handlers/gestureHandlerCommon.js +1 -1
  117. package/lib/module/handlers/gestureHandlerCommon.js.map +1 -1
  118. package/lib/module/handlers/gestures/GestureDetector.js +11 -1
  119. package/lib/module/handlers/gestures/GestureDetector.js.map +1 -1
  120. package/lib/module/handlers/gestures/gesture.js +5 -0
  121. package/lib/module/handlers/gestures/gesture.js.map +1 -1
  122. package/lib/module/index.js +2 -0
  123. package/lib/module/index.js.map +1 -1
  124. package/lib/module/specs/NativeRNGestureHandlerModule.js +3 -0
  125. package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -0
  126. package/lib/module/web/handlers/FlingGestureHandler.js +4 -0
  127. package/lib/module/web/handlers/FlingGestureHandler.js.map +1 -1
  128. package/lib/module/web/handlers/GestureHandler.js +18 -4
  129. package/lib/module/web/handlers/GestureHandler.js.map +1 -1
  130. package/lib/module/web/handlers/LongPressGestureHandler.js +8 -5
  131. package/lib/module/web/handlers/LongPressGestureHandler.js.map +1 -1
  132. package/lib/module/web/handlers/PanGestureHandler.js +4 -0
  133. package/lib/module/web/handlers/PanGestureHandler.js.map +1 -1
  134. package/lib/module/web/handlers/TapGestureHandler.js +4 -0
  135. package/lib/module/web/handlers/TapGestureHandler.js.map +1 -1
  136. package/lib/module/web/interfaces.js +9 -20
  137. package/lib/module/web/interfaces.js.map +1 -1
  138. package/lib/module/web/tools/GestureHandlerOrchestrator.js +2 -2
  139. package/lib/module/web/tools/GestureHandlerOrchestrator.js.map +1 -1
  140. package/lib/module/web/tools/GestureHandlerWebDelegate.js +34 -0
  141. package/lib/module/web/tools/GestureHandlerWebDelegate.js.map +1 -1
  142. package/lib/module/web/tools/NodeManager.js +3 -2
  143. package/lib/module/web/tools/NodeManager.js.map +1 -1
  144. package/lib/module/web/tools/PointerEventManager.js +41 -12
  145. package/lib/module/web/tools/PointerEventManager.js.map +1 -1
  146. package/lib/module/web/tools/TouchEventManager.js +2 -2
  147. package/lib/module/web/tools/TouchEventManager.js.map +1 -1
  148. package/lib/module/web/utils.js +2 -0
  149. package/lib/module/web/utils.js.map +1 -1
  150. package/lib/typescript/PointerType.d.ts +6 -0
  151. package/lib/typescript/RNGestureHandlerModule.d.ts +2 -13
  152. package/lib/typescript/RNGestureHandlerModule.windows.d.ts +5 -21
  153. package/lib/typescript/components/DrawerLayout.d.ts +11 -0
  154. package/lib/typescript/components/GestureHandlerRootView.android.d.ts +1 -1
  155. package/lib/typescript/components/GestureHandlerRootView.d.ts +1 -1
  156. package/lib/typescript/components/GestureHandlerRootView.web.d.ts +1 -1
  157. package/lib/typescript/getShadowNodeFromRef.d.ts +1 -1
  158. package/lib/typescript/handlers/NativeViewGestureHandler.d.ts +1 -1
  159. package/lib/typescript/handlers/PanGestureHandler.d.ts +1 -1
  160. package/lib/typescript/handlers/gestureHandlerCommon.d.ts +6 -1
  161. package/lib/typescript/handlers/gestures/GestureDetector.d.ts +2 -1
  162. package/lib/typescript/handlers/gestures/gesture.d.ts +2 -0
  163. package/lib/typescript/index.d.ts +2 -0
  164. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +14 -0
  165. package/lib/typescript/web/handlers/GestureHandler.d.ts +4 -1
  166. package/lib/typescript/web/interfaces.d.ts +10 -14
  167. package/lib/typescript/web/tools/GestureHandlerDelegate.d.ts +2 -0
  168. package/lib/typescript/web/tools/GestureHandlerWebDelegate.d.ts +7 -0
  169. package/lib/typescript/web/tools/PointerEventManager.d.ts +2 -0
  170. package/lib/typescript/web/utils.d.ts +2 -0
  171. package/package.json +14 -11
  172. package/src/PointerType.ts +6 -0
  173. package/src/RNGestureHandlerModule.ts +4 -49
  174. package/src/RNGestureHandlerModule.windows.ts +18 -100
  175. package/src/components/DrawerLayout.tsx +15 -0
  176. package/src/components/GestureHandlerRootView.android.tsx +13 -5
  177. package/src/components/GestureHandlerRootView.tsx +10 -5
  178. package/src/components/GestureHandlerRootView.web.tsx +10 -5
  179. package/src/getShadowNodeFromRef.ts +28 -6
  180. package/src/handlers/createHandler.tsx +6 -0
  181. package/src/handlers/gestureHandlerCommon.ts +7 -0
  182. package/src/handlers/gestures/GestureDetector.tsx +16 -2
  183. package/src/handlers/gestures/gesture.ts +6 -0
  184. package/src/index.ts +2 -0
  185. package/src/specs/NativeRNGestureHandlerModule.ts +26 -0
  186. package/src/web/handlers/FlingGestureHandler.ts +4 -0
  187. package/src/web/handlers/GestureHandler.ts +20 -2
  188. package/src/web/handlers/LongPressGestureHandler.ts +8 -5
  189. package/src/web/handlers/PanGestureHandler.ts +4 -0
  190. package/src/web/handlers/TapGestureHandler.ts +4 -0
  191. package/src/web/interfaces.ts +12 -17
  192. package/src/web/tools/GestureHandlerDelegate.ts +3 -0
  193. package/src/web/tools/GestureHandlerOrchestrator.ts +2 -2
  194. package/src/web/tools/GestureHandlerWebDelegate.ts +39 -0
  195. package/src/web/tools/NodeManager.ts +5 -1
  196. package/src/web/tools/PointerEventManager.ts +46 -10
  197. package/src/web/tools/TouchEventManager.ts +2 -8
  198. package/src/web/utils.ts +9 -0
  199. package/ios/Handlers/RNPinchHandler.m +0 -95
  200. package/ios/Handlers/RNRotationHandler.m +0 -93
  201. package/ios/RNGestureHandlerModule.h +0 -7
  202. package/lib/commonjs/RNGestureHandlerModule.macos.js +0 -149
  203. package/lib/commonjs/RNGestureHandlerModule.macos.js.map +0 -1
  204. package/lib/module/RNGestureHandlerModule.macos.js +0 -110
  205. package/lib/module/RNGestureHandlerModule.macos.js.map +0 -1
  206. package/lib/typescript/RNGestureHandlerModule.macos.d.ts +0 -47
  207. package/src/RNGestureHandlerModule.macos.ts +0 -133
  208. /package/{ios → apple}/Handlers/RNFlingHandler.h +0 -0
  209. /package/{ios → apple}/Handlers/RNForceTouchHandler.h +0 -0
  210. /package/{ios → apple}/Handlers/RNHoverHandler.h +0 -0
  211. /package/{ios → apple}/Handlers/RNLongPressHandler.h +0 -0
  212. /package/{ios → apple}/Handlers/RNManualHandler.h +0 -0
  213. /package/{ios → apple}/Handlers/RNNativeViewHandler.h +0 -0
  214. /package/{ios → apple}/Handlers/RNPanHandler.h +0 -0
  215. /package/{ios → apple}/Handlers/RNPinchHandler.h +0 -0
  216. /package/{ios → apple}/Handlers/RNRotationHandler.h +0 -0
  217. /package/{ios → apple}/Handlers/RNTapHandler.h +0 -0
  218. /package/{ios → apple}/RNGHTouchEventType.h +0 -0
  219. /package/{ios → apple}/RNGestureHandler.xcodeproj/project.pbxproj +0 -0
  220. /package/{ios → apple}/RNGestureHandler.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -0
  221. /package/{ios → apple}/RNGestureHandlerActionType.h +0 -0
  222. /package/{ios → apple}/RNGestureHandlerButtonComponentView.h +0 -0
  223. /package/{ios → apple}/RNGestureHandlerButtonComponentView.mm +0 -0
  224. /package/{ios → apple}/RNGestureHandlerButtonManager.h +0 -0
  225. /package/{ios → apple}/RNGestureHandlerDirection.h +0 -0
  226. /package/{ios → apple}/RNGestureHandlerRootViewComponentView.mm +0 -0
  227. /package/{ios → apple}/RNGestureHandlerState.h +0 -0
  228. /package/{ios → apple}/RNGestureHandlerStateManager.h +0 -0
  229. /package/{ios → apple}/RNRootViewGestureRecognizer.h +0 -0
@@ -0,0 +1,26 @@
1
+ import { TurboModuleRegistry, TurboModule } from 'react-native';
2
+ import { Double } from 'react-native/Libraries/Types/CodegenTypes';
3
+
4
+ export interface Spec extends TurboModule {
5
+ handleSetJSResponder: (tag: Double, blockNativeResponder: boolean) => void;
6
+ handleClearJSResponder: () => void;
7
+ createGestureHandler: (
8
+ handlerName: string,
9
+ handlerTag: Double,
10
+ // Record<> is not supported by codegen
11
+ // eslint-disable-next-line @typescript-eslint/ban-types
12
+ config: Object
13
+ ) => void;
14
+ attachGestureHandler: (
15
+ handlerTag: Double,
16
+ newView: Double,
17
+ actionType: Double
18
+ ) => void;
19
+ // eslint-disable-next-line @typescript-eslint/ban-types
20
+ updateGestureHandler: (handlerTag: Double, newConfig: Object) => void;
21
+ dropGestureHandler: (handlerTag: Double) => void;
22
+ install: () => boolean;
23
+ flushOperations: () => void;
24
+ }
25
+
26
+ export default TurboModuleRegistry.getEnforcing<Spec>('RNGestureHandlerModule');
@@ -83,6 +83,10 @@ export default class FlingGestureHandler extends GestureHandler {
83
83
  }
84
84
 
85
85
  protected onPointerDown(event: AdaptedEvent): void {
86
+ if (!this.isButtonInConfig(event.button)) {
87
+ return;
88
+ }
89
+
86
90
  this.tracker.addToTracker(event);
87
91
  this.keyPointer = event.pointerId;
88
92
 
@@ -7,15 +7,16 @@ import {
7
7
  ResultEvent,
8
8
  PointerData,
9
9
  ResultTouchEvent,
10
- PointerType,
11
10
  TouchEventType,
12
11
  EventTypes,
12
+ MouseButton,
13
13
  } from '../interfaces';
14
14
  import EventManager from '../tools/EventManager';
15
15
  import GestureHandlerOrchestrator from '../tools/GestureHandlerOrchestrator';
16
16
  import InteractionManager from '../tools/InteractionManager';
17
17
  import PointerTracker, { TrackerElement } from '../tools/PointerTracker';
18
18
  import { GestureHandlerDelegate } from '../tools/GestureHandlerDelegate';
19
+ import { PointerType } from '../../PointerType';
19
20
 
20
21
  export default abstract class GestureHandler {
21
22
  private lastSentState: State | null = null;
@@ -37,7 +38,7 @@ export default abstract class GestureHandler {
37
38
  protected awaiting = false;
38
39
  protected active = false;
39
40
  protected shouldResetProgress = false;
40
- protected pointerType: PointerType = PointerType.NONE;
41
+ protected pointerType: PointerType = PointerType.MOUSE;
41
42
 
42
43
  protected delegate: GestureHandlerDelegate<unknown>;
43
44
 
@@ -117,6 +118,10 @@ export default abstract class GestureHandler {
117
118
  );
118
119
 
119
120
  this.onStateChange(newState, oldState);
121
+
122
+ if (!this.enabled && this.isFinished()) {
123
+ this.currentState = State.UNDETERMINED;
124
+ }
120
125
  }
121
126
 
122
127
  protected onStateChange(_newState: State, _oldState: State): void {}
@@ -416,6 +421,7 @@ export default abstract class GestureHandler {
416
421
  handlerTag: this.handlerTag,
417
422
  target: this.viewRef,
418
423
  oldState: newState !== oldState ? oldState : undefined,
424
+ pointerType: this.pointerType,
419
425
  },
420
426
  timeStamp: Date.now(),
421
427
  };
@@ -736,8 +742,20 @@ export default abstract class GestureHandler {
736
742
  return false;
737
743
  }
738
744
 
745
+ public isButtonInConfig(mouseButton: MouseButton | undefined) {
746
+ return (
747
+ !mouseButton ||
748
+ (!this.config.mouseButton && mouseButton === MouseButton.LEFT) ||
749
+ (this.config.mouseButton && mouseButton & this.config.mouseButton)
750
+ );
751
+ }
752
+
739
753
  protected resetConfig(): void {}
740
754
 
755
+ public onDestroy(): void {
756
+ this.delegate.destroy(this.config);
757
+ }
758
+
741
759
  //
742
760
  // Getters and setters
743
761
  //
@@ -1,4 +1,3 @@
1
- import { Platform } from 'react-native';
2
1
  import { State } from '../../State';
3
2
  import { AdaptedEvent, Config } from '../interfaces';
4
3
 
@@ -22,11 +21,11 @@ export default class LongPressGestureHandler extends GestureHandler {
22
21
  private activationTimeout: number | undefined;
23
22
 
24
23
  public init(ref: number, propsRef: React.RefObject<unknown>) {
25
- super.init(ref, propsRef);
26
-
27
- if (Platform.OS === 'web') {
28
- (this.delegate.getView() as HTMLElement).oncontextmenu = () => false;
24
+ if (this.config.enableContextMenu === undefined) {
25
+ this.config.enableContextMenu = false;
29
26
  }
27
+
28
+ super.init(ref, propsRef);
30
29
  }
31
30
 
32
31
  protected transformNativeEvent() {
@@ -59,6 +58,10 @@ export default class LongPressGestureHandler extends GestureHandler {
59
58
  }
60
59
 
61
60
  protected onPointerDown(event: AdaptedEvent): void {
61
+ if (!this.isButtonInConfig(event.button)) {
62
+ return;
63
+ }
64
+
62
65
  this.tracker.addToTracker(event);
63
66
  super.onPointerDown(event);
64
67
  this.tryBegin(event);
@@ -211,6 +211,10 @@ export default class PanGestureHandler extends GestureHandler {
211
211
 
212
212
  //EventsHandling
213
213
  protected onPointerDown(event: AdaptedEvent): void {
214
+ if (!this.isButtonInConfig(event.button)) {
215
+ return;
216
+ }
217
+
214
218
  this.tracker.addToTracker(event);
215
219
  super.onPointerDown(event);
216
220
 
@@ -105,6 +105,10 @@ export default class TapGestureHandler extends GestureHandler {
105
105
 
106
106
  //Handling Events
107
107
  protected onPointerDown(event: AdaptedEvent): void {
108
+ if (!this.isButtonInConfig(event.button)) {
109
+ return;
110
+ }
111
+
108
112
  this.tracker.addToTracker(event);
109
113
  super.onPointerDown(event);
110
114
 
@@ -1,6 +1,7 @@
1
1
  import { UserSelect, ActiveCursor } from '../handlers/gestureHandlerCommon';
2
2
  import { Directions } from '../Directions';
3
3
  import { State } from '../State';
4
+ import { PointerType } from '../PointerType';
4
5
 
5
6
  export interface HitSlop {
6
7
  left?: number;
@@ -37,6 +38,8 @@ export interface Config extends Record<string, ConfigArgs> {
37
38
  shouldCancelWhenOutside?: boolean;
38
39
  userSelect?: UserSelect;
39
40
  activeCursor?: ActiveCursor;
41
+ mouseButton?: MouseButton;
42
+ enableContextMenu?: boolean;
40
43
 
41
44
  activateAfterLongPress?: number;
42
45
  failOffsetXStart?: number;
@@ -77,6 +80,7 @@ interface NativeEvent extends Record<string, NativeEventArgs> {
77
80
  handlerTag: number;
78
81
  target: number;
79
82
  oldState?: State;
83
+ pointerType: PointerType;
80
84
  }
81
85
 
82
86
  export interface PointerData {
@@ -122,22 +126,20 @@ export interface AdaptedEvent {
122
126
  pointerId: number;
123
127
  eventType: EventTypes;
124
128
  pointerType: PointerType;
125
- buttons: number;
126
129
  time: number;
130
+ button?: MouseButton;
127
131
  allTouches?: TouchList;
128
132
  changedTouches?: TouchList;
129
133
  touchEventType?: TouchEventType;
130
134
  }
131
135
 
132
- export enum MouseButtons {
133
- NONE,
134
- LEFT,
135
- RIGHT,
136
- LEFT_RIGHT,
137
- SCROLL,
138
- SCROLL_LEFT,
139
- SCROLL_RIGHT,
140
- SCROLL_LEFT_RIGHT,
136
+ export enum MouseButton {
137
+ LEFT = 1,
138
+ RIGHT = 2,
139
+ MIDDLE = 4,
140
+ BUTTON_4 = 8,
141
+ BUTTON_5 = 16,
142
+ ALL = 31,
141
143
  }
142
144
 
143
145
  export enum EventTypes {
@@ -158,10 +160,3 @@ export enum TouchEventType {
158
160
  UP,
159
161
  CANCELLED,
160
162
  }
161
-
162
- export enum PointerType {
163
- NONE = 'none',
164
- MOUSE = 'mouse',
165
- TOUCH = 'touch',
166
- PEN = 'pen',
167
- }
@@ -1,4 +1,5 @@
1
1
  import type GestureHandler from '../handlers/GestureHandler';
2
+ import { Config } from '../interfaces';
2
3
 
3
4
  export interface MeasureResult {
4
5
  pageX: number;
@@ -20,4 +21,6 @@ export interface GestureHandlerDelegate<T> {
20
21
  onEnd(): void;
21
22
  onCancel(): void;
22
23
  onFail(): void;
24
+
25
+ destroy(config: Config): void;
23
26
  }
@@ -1,5 +1,5 @@
1
+ import { PointerType } from '../../PointerType';
1
2
  import { State } from '../../State';
2
- import { PointerType } from '../interfaces';
3
3
 
4
4
  import GestureHandler from '../handlers/GestureHandler';
5
5
  import PointerTracker from './PointerTracker';
@@ -359,7 +359,7 @@ export default class GestureHandlerOrchestrator {
359
359
  this.gestureHandlers.forEach((handler: GestureHandler) => {
360
360
  if (
361
361
  handler.getPointerType() !== PointerType.MOUSE &&
362
- handler.getPointerType() !== PointerType.PEN
362
+ handler.getPointerType() !== PointerType.STYLUS
363
363
  ) {
364
364
  return;
365
365
  }
@@ -9,6 +9,7 @@ import TouchEventManager from './TouchEventManager';
9
9
  import { State } from '../../State';
10
10
  import { isPointerInBounds } from '../utils';
11
11
  import EventManager from './EventManager';
12
+ import { Config, MouseButton } from '../interfaces';
12
13
 
13
14
  export class GestureHandlerWebDelegate
14
15
  implements GestureHandlerDelegate<HTMLElement>
@@ -37,6 +38,8 @@ export class GestureHandlerWebDelegate
37
38
 
38
39
  const config = handler.getConfig();
39
40
 
41
+ this.addContextMenuListeners(config);
42
+
40
43
  if (!config.userSelect) {
41
44
  this.view.style['webkitUserSelect'] = 'none';
42
45
  this.view.style['userSelect'] = 'none';
@@ -86,6 +89,38 @@ export class GestureHandlerWebDelegate
86
89
  }
87
90
  }
88
91
 
92
+ private shouldDisableContextMenu(config: Config) {
93
+ return (
94
+ (config.enableContextMenu === undefined &&
95
+ this.gestureHandler.isButtonInConfig(MouseButton.RIGHT)) ||
96
+ config.enableContextMenu === false
97
+ );
98
+ }
99
+
100
+ private addContextMenuListeners(config: Config): void {
101
+ if (this.shouldDisableContextMenu(config)) {
102
+ this.view.addEventListener('contextmenu', this.disableContextMenu);
103
+ } else if (config.enableContextMenu) {
104
+ this.view.addEventListener('contextmenu', this.enableContextMenu);
105
+ }
106
+ }
107
+
108
+ private removeContextMenuListeners(config: Config): void {
109
+ if (this.shouldDisableContextMenu(config)) {
110
+ this.view.removeEventListener('contextmenu', this.disableContextMenu);
111
+ } else if (config.enableContextMenu) {
112
+ this.view.removeEventListener('contextmenu', this.enableContextMenu);
113
+ }
114
+ }
115
+
116
+ private disableContextMenu(this: void, e: MouseEvent): void {
117
+ e.preventDefault();
118
+ }
119
+
120
+ private enableContextMenu(this: void, e: MouseEvent): void {
121
+ e.stopPropagation();
122
+ }
123
+
89
124
  onBegin(): void {
90
125
  // no-op for now
91
126
  }
@@ -112,4 +147,8 @@ export class GestureHandlerWebDelegate
112
147
  onFail(): void {
113
148
  this.tryResetCursor();
114
149
  }
150
+
151
+ public destroy(config: Config): void {
152
+ this.removeContextMenuListeners(config);
153
+ }
115
154
  }
@@ -21,7 +21,9 @@ export default abstract class NodeManager {
21
21
  handler: InstanceType<ValueOf<typeof Gestures>>
22
22
  ): void {
23
23
  if (handlerTag in this.gestures) {
24
- throw new Error(`Handler with tag ${handlerTag} already exists`);
24
+ throw new Error(
25
+ `Handler with tag ${handlerTag} already exists. Please ensure that no Gesture instance is used across multiple GestureDetectors.`
26
+ );
25
27
  }
26
28
 
27
29
  this.gestures[handlerTag] = handler;
@@ -33,6 +35,8 @@ export default abstract class NodeManager {
33
35
  return;
34
36
  }
35
37
 
38
+ this.gestures[handlerTag].onDestroy();
39
+
36
40
  // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
37
41
  delete this.gestures[handlerTag];
38
42
  }
@@ -1,15 +1,31 @@
1
- import { AdaptedEvent, EventTypes, PointerType } from '../interfaces';
1
+ import { AdaptedEvent, EventTypes, MouseButton } from '../interfaces';
2
2
  import EventManager from './EventManager';
3
- import { isPointerInBounds } from '../utils';
3
+ import { PointerTypeMapping, isPointerInBounds } from '../utils';
4
+ import { PointerType } from '../../PointerType';
4
5
 
5
6
  const POINTER_CAPTURE_EXCLUDE_LIST = new Set<string>(['SELECT', 'INPUT']);
7
+ const PointerTypes = {
8
+ Touch: 'touch',
9
+ Stylus: 'pen',
10
+ };
6
11
 
7
12
  export default class PointerEventManager extends EventManager<HTMLElement> {
8
13
  private trackedPointers = new Set<number>();
14
+ private readonly mouseButtonsMapper = new Map<number, MouseButton>();
15
+
16
+ constructor(view: HTMLElement) {
17
+ super(view);
18
+
19
+ this.mouseButtonsMapper.set(0, MouseButton.LEFT);
20
+ this.mouseButtonsMapper.set(1, MouseButton.MIDDLE);
21
+ this.mouseButtonsMapper.set(2, MouseButton.RIGHT);
22
+ this.mouseButtonsMapper.set(3, MouseButton.BUTTON_4);
23
+ this.mouseButtonsMapper.set(4, MouseButton.BUTTON_5);
24
+ }
9
25
 
10
26
  public setListeners(): void {
11
27
  this.view.addEventListener('pointerdown', (event: PointerEvent): void => {
12
- if (event.pointerType === PointerType.TOUCH) {
28
+ if (event.pointerType === PointerTypes.Touch) {
13
29
  return;
14
30
  }
15
31
  if (
@@ -37,7 +53,7 @@ export default class PointerEventManager extends EventManager<HTMLElement> {
37
53
  });
38
54
 
39
55
  this.view.addEventListener('pointerup', (event: PointerEvent): void => {
40
- if (event.pointerType === PointerType.TOUCH) {
56
+ if (event.pointerType === PointerTypes.Touch) {
41
57
  return;
42
58
  }
43
59
 
@@ -67,8 +83,24 @@ export default class PointerEventManager extends EventManager<HTMLElement> {
67
83
  }
68
84
  });
69
85
 
86
+ const lastPosition: { x: number | null; y: number | null } = {
87
+ x: null,
88
+ y: null,
89
+ };
90
+
70
91
  this.view.addEventListener('pointermove', (event: PointerEvent): void => {
71
- if (event.pointerType === PointerType.TOUCH) {
92
+ if (event.pointerType === PointerTypes.Touch) {
93
+ return;
94
+ }
95
+
96
+ // Stylus triggers `pointermove` event when it detects changes in pressure. Since it is very sensitive to those changes,
97
+ // it constantly sends events, even though there was no change in position. To fix that we check whether
98
+ // pointer has actually moved and if not, we do not send event.
99
+ if (
100
+ event.pointerType === PointerTypes.Stylus &&
101
+ event.x === lastPosition.x &&
102
+ event.y === lastPosition.y
103
+ ) {
72
104
  return;
73
105
  }
74
106
 
@@ -120,10 +152,13 @@ export default class PointerEventManager extends EventManager<HTMLElement> {
120
152
  this.onPointerOutOfBounds(adaptedEvent);
121
153
  }
122
154
  }
155
+
156
+ lastPosition.x = event.x;
157
+ lastPosition.y = event.y;
123
158
  });
124
159
 
125
160
  this.view.addEventListener('pointercancel', (event: PointerEvent): void => {
126
- if (event.pointerType === PointerType.TOUCH) {
161
+ if (event.pointerType === PointerTypes.Touch) {
127
162
  return;
128
163
  }
129
164
 
@@ -144,7 +179,7 @@ export default class PointerEventManager extends EventManager<HTMLElement> {
144
179
  // mapping them to onPointerMoveOver and onPointerMoveOut respectively.
145
180
 
146
181
  this.view.addEventListener('pointerenter', (event: PointerEvent): void => {
147
- if (event.pointerType === PointerType.TOUCH) {
182
+ if (event.pointerType === PointerTypes.Touch) {
148
183
  return;
149
184
  }
150
185
 
@@ -154,7 +189,7 @@ export default class PointerEventManager extends EventManager<HTMLElement> {
154
189
  });
155
190
 
156
191
  this.view.addEventListener('pointerleave', (event: PointerEvent): void => {
157
- if (event.pointerType === PointerType.TOUCH) {
192
+ if (event.pointerType === PointerTypes.Touch) {
158
193
  return;
159
194
  }
160
195
 
@@ -191,8 +226,9 @@ export default class PointerEventManager extends EventManager<HTMLElement> {
191
226
  offsetY: event.offsetY,
192
227
  pointerId: event.pointerId,
193
228
  eventType: eventType,
194
- pointerType: event.pointerType as PointerType,
195
- buttons: event.buttons,
229
+ pointerType:
230
+ PointerTypeMapping.get(event.pointerType) ?? PointerType.OTHER,
231
+ button: this.mouseButtonsMapper.get(event.button),
196
232
  time: event.timeStamp,
197
233
  };
198
234
  }
@@ -1,12 +1,7 @@
1
- import {
2
- AdaptedEvent,
3
- EventTypes,
4
- MouseButtons,
5
- PointerType,
6
- TouchEventType,
7
- } from '../interfaces';
1
+ import { AdaptedEvent, EventTypes, TouchEventType } from '../interfaces';
8
2
  import EventManager from './EventManager';
9
3
  import { isPointerInBounds } from '../utils';
4
+ import { PointerType } from '../../PointerType';
10
5
 
11
6
  export default class TouchEventManager extends EventManager<HTMLElement> {
12
7
  public setListeners(): void {
@@ -157,7 +152,6 @@ export default class TouchEventManager extends EventManager<HTMLElement> {
157
152
  pointerId: event.changedTouches[index].identifier,
158
153
  eventType: eventType,
159
154
  pointerType: PointerType.TOUCH,
160
- buttons: MouseButtons.NONE,
161
155
  time: event.timeStamp,
162
156
  allTouches: event.touches,
163
157
  changedTouches: event.changedTouches,
package/src/web/utils.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { PointerType } from '../PointerType';
2
+
1
3
  export function isPointerInBounds(
2
4
  view: HTMLElement,
3
5
  { x, y }: { x: number; y: number }
@@ -6,3 +8,10 @@ export function isPointerInBounds(
6
8
 
7
9
  return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;
8
10
  }
11
+
12
+ export const PointerTypeMapping = new Map<string, PointerType>([
13
+ ['mouse', PointerType.MOUSE],
14
+ ['touch', PointerType.TOUCH],
15
+ ['pen', PointerType.STYLUS],
16
+ ['none', PointerType.OTHER],
17
+ ]);
@@ -1,95 +0,0 @@
1
-
2
-
3
- //
4
- // RNPinchHandler.m
5
- // RNGestureHandler
6
- //
7
- // Created by Krzysztof Magiera on 12/10/2017.
8
- // Copyright © 2017 Software Mansion. All rights reserved.
9
- //
10
-
11
- #import "RNPinchHandler.h"
12
-
13
- #if !TARGET_OS_TV
14
- @interface RNBetterPinchRecognizer : UIPinchGestureRecognizer
15
-
16
- - (id)initWithGestureHandler:(RNGestureHandler *)gestureHandler;
17
-
18
- @end
19
-
20
- @implementation RNBetterPinchRecognizer {
21
- __weak RNGestureHandler *_gestureHandler;
22
- }
23
-
24
- - (id)initWithGestureHandler:(RNGestureHandler *)gestureHandler
25
- {
26
- if ((self = [super initWithTarget:self action:@selector(handleGesture:)])) {
27
- _gestureHandler = gestureHandler;
28
- }
29
- return self;
30
- }
31
-
32
- - (void)handleGesture:(UIGestureRecognizer *)recognizer
33
- {
34
- if (self.state == UIGestureRecognizerStateBegan) {
35
- self.scale = 1;
36
- }
37
- [_gestureHandler handleGesture:recognizer];
38
- }
39
-
40
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
41
- {
42
- [super touchesBegan:touches withEvent:event];
43
- [_gestureHandler.pointerTracker touchesBegan:touches withEvent:event];
44
- }
45
-
46
- - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
47
- {
48
- [super touchesMoved:touches withEvent:event];
49
- [_gestureHandler.pointerTracker touchesMoved:touches withEvent:event];
50
- }
51
-
52
- - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
53
- {
54
- [super touchesEnded:touches withEvent:event];
55
- [_gestureHandler.pointerTracker touchesEnded:touches withEvent:event];
56
- }
57
-
58
- - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
59
- {
60
- [super touchesCancelled:touches withEvent:event];
61
- [_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
62
- }
63
-
64
- - (void)reset
65
- {
66
- [_gestureHandler.pointerTracker reset];
67
- [super reset];
68
- }
69
-
70
- @end
71
- #endif
72
-
73
- @implementation RNPinchGestureHandler
74
-
75
- - (instancetype)initWithTag:(NSNumber *)tag
76
- {
77
- if ((self = [super initWithTag:tag])) {
78
- #if !TARGET_OS_TV
79
- _recognizer = [[RNBetterPinchRecognizer alloc] initWithGestureHandler:self];
80
- #endif
81
- }
82
- return self;
83
- }
84
-
85
- #if !TARGET_OS_TV
86
- - (RNGestureHandlerEventExtraData *)eventExtraData:(UIPinchGestureRecognizer *)recognizer
87
- {
88
- return [RNGestureHandlerEventExtraData forPinch:recognizer.scale
89
- withFocalPoint:[recognizer locationInView:recognizer.view]
90
- withVelocity:recognizer.velocity
91
- withNumberOfTouches:recognizer.numberOfTouches];
92
- }
93
- #endif
94
-
95
- @end
@@ -1,93 +0,0 @@
1
- //
2
- // RNRotationHandler.m
3
- // RNGestureHandler
4
- //
5
- // Created by Krzysztof Magiera on 12/10/2017.
6
- // Copyright © 2017 Software Mansion. All rights reserved.
7
- //
8
-
9
- #import "RNRotationHandler.h"
10
-
11
- #if !TARGET_OS_TV
12
- @interface RNBetterRotationRecognizer : UIRotationGestureRecognizer
13
-
14
- - (id)initWithGestureHandler:(RNGestureHandler *)gestureHandler;
15
-
16
- @end
17
-
18
- @implementation RNBetterRotationRecognizer {
19
- __weak RNGestureHandler *_gestureHandler;
20
- }
21
-
22
- - (id)initWithGestureHandler:(RNGestureHandler *)gestureHandler
23
- {
24
- if ((self = [super initWithTarget:self action:@selector(handleGesture:)])) {
25
- _gestureHandler = gestureHandler;
26
- }
27
- return self;
28
- }
29
-
30
- - (void)handleGesture:(UIGestureRecognizer *)recognizer
31
- {
32
- if (self.state == UIGestureRecognizerStateBegan) {
33
- self.rotation = 0;
34
- }
35
- [_gestureHandler handleGesture:recognizer];
36
- }
37
-
38
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
39
- {
40
- [super touchesBegan:touches withEvent:event];
41
- [_gestureHandler.pointerTracker touchesBegan:touches withEvent:event];
42
- }
43
-
44
- - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
45
- {
46
- [super touchesMoved:touches withEvent:event];
47
- [_gestureHandler.pointerTracker touchesMoved:touches withEvent:event];
48
- }
49
-
50
- - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
51
- {
52
- [super touchesEnded:touches withEvent:event];
53
- [_gestureHandler.pointerTracker touchesEnded:touches withEvent:event];
54
- }
55
-
56
- - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
57
- {
58
- [super touchesCancelled:touches withEvent:event];
59
- [_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
60
- }
61
-
62
- - (void)reset
63
- {
64
- [_gestureHandler.pointerTracker reset];
65
- [super reset];
66
- }
67
-
68
- @end
69
- #endif
70
-
71
- @implementation RNRotationGestureHandler
72
-
73
- - (instancetype)initWithTag:(NSNumber *)tag
74
- {
75
- if ((self = [super initWithTag:tag])) {
76
- #if !TARGET_OS_TV
77
- _recognizer = [[RNBetterRotationRecognizer alloc] initWithGestureHandler:self];
78
- #endif
79
- }
80
- return self;
81
- }
82
-
83
- #if !TARGET_OS_TV
84
- - (RNGestureHandlerEventExtraData *)eventExtraData:(UIRotationGestureRecognizer *)recognizer
85
- {
86
- return [RNGestureHandlerEventExtraData forRotation:recognizer.rotation
87
- withAnchorPoint:[recognizer locationInView:recognizer.view]
88
- withVelocity:recognizer.velocity
89
- withNumberOfTouches:recognizer.numberOfTouches];
90
- }
91
- #endif
92
-
93
- @end
@@ -1,7 +0,0 @@
1
- #import <React/RCTBridgeModule.h>
2
- #import <React/RCTEventEmitter.h>
3
- #import <React/RCTUIManager.h>
4
-
5
- @interface RNGestureHandlerModule : RCTEventEmitter <RCTBridgeModule>
6
-
7
- @end