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
@@ -8,7 +8,9 @@
8
8
 
9
9
  #import "RNTapHandler.h"
10
10
 
11
+ #if !TARGET_OS_OSX
11
12
  #import <UIKit/UIGestureRecognizerSubclass.h>
13
+ #endif
12
14
 
13
15
  #import <React/RCTConvert.h>
14
16
 
@@ -69,9 +71,8 @@ static const NSTimeInterval defaultMaxDuration = 0.5;
69
71
  self.enabled = NO;
70
72
  }
71
73
 
72
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
74
+ - (void)interactionsBegan:(NSSet *)touches withEvent:(UIEvent *)event
73
75
  {
74
- [super touchesBegan:touches withEvent:event];
75
76
  [_gestureHandler.pointerTracker touchesBegan:touches withEvent:event];
76
77
 
77
78
  if (_tapsSoFar == 0) {
@@ -79,7 +80,11 @@ static const NSTimeInterval defaultMaxDuration = 0.5;
79
80
  // is called (it resets the gesture handler), making it send whatever the last known state as oldState
80
81
  // in the event. If we reset it here it correctly sends UNDETERMINED as oldState.
81
82
  [_gestureHandler reset];
83
+ #if TARGET_OS_OSX
84
+ _initPosition = [self locationInView:self.view.window.contentView];
85
+ #else
82
86
  _initPosition = [self locationInView:self.view.window];
87
+ #endif
83
88
  }
84
89
  _tapsSoFar++;
85
90
  if (_tapsSoFar) {
@@ -96,9 +101,8 @@ static const NSTimeInterval defaultMaxDuration = 0.5;
96
101
  [self triggerAction];
97
102
  }
98
103
 
99
- - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
104
+ - (void)interactionsMoved:(NSSet *)touches withEvent:(UIEvent *)event
100
105
  {
101
- [super touchesMoved:touches withEvent:event];
102
106
  [_gestureHandler.pointerTracker touchesMoved:touches withEvent:event];
103
107
 
104
108
  NSInteger numberOfTouches = [touches count];
@@ -121,9 +125,98 @@ static const NSTimeInterval defaultMaxDuration = 0.5;
121
125
  [self triggerAction];
122
126
  }
123
127
 
128
+ - (void)interactionsEnded:(NSSet *)touches withEvent:(UIEvent *)event
129
+ {
130
+ [_gestureHandler.pointerTracker touchesEnded:touches withEvent:event];
131
+
132
+ if (_numberOfTaps == _tapsSoFar && _maxNumberOfTouches >= _minPointers) {
133
+ self.state = UIGestureRecognizerStateEnded;
134
+ [self reset];
135
+ } else {
136
+ [self performSelector:@selector(cancel) withObject:nil afterDelay:_maxDelay];
137
+ }
138
+ }
139
+
140
+ - (void)interactionsCancelled:(NSSet *)touches withEvent:(UIEvent *)event
141
+ {
142
+ [_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
143
+ self.state = UIGestureRecognizerStateCancelled;
144
+ [self reset];
145
+ }
146
+
147
+ #if TARGET_OS_OSX
148
+ - (void)mouseDown:(NSEvent *)event
149
+ {
150
+ [_gestureHandler setCurrentPointerTypeToMouse];
151
+ [super mouseDown:event];
152
+ [self interactionsBegan:[NSSet setWithObject:event] withEvent:event];
153
+ }
154
+
155
+ - (void)rightMouseDown:(NSEvent *)event
156
+ {
157
+ [super rightMouseDown:event];
158
+ [self interactionsBegan:[NSSet setWithObject:event] withEvent:event];
159
+ }
160
+
161
+ - (void)mouseDragged:(NSEvent *)event
162
+ {
163
+ [super mouseDragged:event];
164
+ [self interactionsMoved:[NSSet setWithObject:event] withEvent:event];
165
+ }
166
+
167
+ - (void)rightMouseDragged:(NSEvent *)event
168
+ {
169
+ [super rightMouseDragged:event];
170
+ [self interactionsMoved:[NSSet setWithObject:event] withEvent:event];
171
+ }
172
+
173
+ - (void)mouseUp:(NSEvent *)event
174
+ {
175
+ [super mouseUp:event];
176
+ [self interactionsEnded:[NSSet setWithObject:event] withEvent:event];
177
+ }
178
+
179
+ - (void)rightMouseUp:(NSEvent *)event
180
+ {
181
+ [super rightMouseUp:event];
182
+ [self interactionsEnded:[NSSet setWithObject:event] withEvent:event];
183
+ }
184
+ #else
185
+
186
+ - (void)touchesBegan:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
187
+ {
188
+ [_gestureHandler setCurrentPointerType:event];
189
+ [super touchesBegan:touches withEvent:event];
190
+ [self interactionsBegan:touches withEvent:event];
191
+ }
192
+
193
+ - (void)touchesMoved:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
194
+ {
195
+ [super touchesMoved:touches withEvent:event];
196
+ [self interactionsMoved:touches withEvent:event];
197
+ }
198
+
199
+ - (void)touchesEnded:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
200
+ {
201
+ [super touchesEnded:touches withEvent:event];
202
+ [self interactionsEnded:touches withEvent:event];
203
+ }
204
+
205
+ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
206
+ {
207
+ [super touchesCancelled:touches withEvent:event];
208
+ [self interactionsCancelled:touches withEvent:event];
209
+ }
210
+
211
+ #endif
212
+
124
213
  - (CGPoint)translationInView
125
214
  {
215
+ #if TARGET_OS_OSX
216
+ CGPoint currentPosition = [self locationInView:self.view.window.contentView];
217
+ #else
126
218
  CGPoint currentPosition = [self locationInView:self.view.window];
219
+ #endif
127
220
  return CGPointMake(currentPosition.x - _initPosition.x, currentPosition.y - _initPosition.y);
128
221
  }
129
222
 
@@ -148,28 +241,6 @@ static const NSTimeInterval defaultMaxDuration = 0.5;
148
241
  return NO;
149
242
  }
150
243
 
151
- - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
152
- {
153
- [super touchesEnded:touches withEvent:event];
154
- [_gestureHandler.pointerTracker touchesEnded:touches withEvent:event];
155
-
156
- if (_numberOfTaps == _tapsSoFar && _maxNumberOfTouches >= _minPointers) {
157
- self.state = UIGestureRecognizerStateEnded;
158
- [self reset];
159
- } else {
160
- [self performSelector:@selector(cancel) withObject:nil afterDelay:_maxDelay];
161
- }
162
- }
163
-
164
- - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
165
- {
166
- [super touchesCancelled:touches withEvent:event];
167
- [_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
168
-
169
- self.state = UIGestureRecognizerStateCancelled;
170
- [self reset];
171
- }
172
-
173
244
  - (void)reset
174
245
  {
175
246
  if (self.state == UIGestureRecognizerStateFailed) {
@@ -182,6 +253,7 @@ static const NSTimeInterval defaultMaxDuration = 0.5;
182
253
  _maxNumberOfTouches = 0;
183
254
  self.enabled = YES;
184
255
  [super reset];
256
+ [_gestureHandler reset];
185
257
  }
186
258
 
187
259
  @end
@@ -0,0 +1,27 @@
1
+ #if !TARGET_OS_OSX
2
+
3
+ #import <UIKit/UIKit.h>
4
+
5
+ typedef UIView RNGHUIView;
6
+ typedef UITouch RNGHUITouch;
7
+
8
+ #define RNGHGestureRecognizerStateFailed UIGestureRecognizerStateFailed;
9
+ #define RNGHGestureRecognizerStatePossible UIGestureRecognizerStatePossible;
10
+ #define RNGHGestureRecognizerStateCancelled UIGestureRecognizerStateCancelled;
11
+ #define RNGHGestureRecognizerStateBegan UIGestureRecognizerStateBegan;
12
+ #define RNGHGestureRecognizerStateEnded UIGestureRecognizerStateEnded;
13
+
14
+ #else // TARGET_OS_OSX [
15
+
16
+ #import <React/RCTUIKit.h>
17
+
18
+ typedef RCTUIView RNGHUIView;
19
+ typedef RCTUITouch RNGHUITouch;
20
+
21
+ #define RNGHGestureRecognizerStateFailed NSGestureRecognizerStateFailed;
22
+ #define RNGHGestureRecognizerStatePossible NSGestureRecognizerStatePossible;
23
+ #define RNGHGestureRecognizerStateCancelled NSGestureRecognizerStateCancelled;
24
+ #define RNGHGestureRecognizerStateBegan NSGestureRecognizerStateBegan;
25
+ #define RNGHGestureRecognizerStateEnded NSGestureRecognizerStateEnded;
26
+
27
+ #endif // ] TARGET_OS_OSX
@@ -1,12 +1,13 @@
1
+ #import "RNGHUIKit.h"
1
2
  #import "RNGestureHandlerActionType.h"
2
3
  #import "RNGestureHandlerDirection.h"
3
4
  #import "RNGestureHandlerEvents.h"
4
5
  #import "RNGestureHandlerPointerTracker.h"
6
+ #import "RNGestureHandlerPointerType.h"
5
7
  #import "RNGestureHandlerState.h"
6
8
 
7
9
  #import <Foundation/Foundation.h>
8
10
  #import <React/RCTConvert.h>
9
- #import <UIKit/UIKit.h>
10
11
 
11
12
  #define VEC_LEN_SQ(pt) (pt.x * pt.x + pt.y * pt.y)
12
13
  #define TEST_MIN_IF_NOT_NAN(value, limit) \
@@ -44,7 +45,7 @@
44
45
  @protocol RNRootViewGestureRecognizerDelegate <UIGestureRecognizerDelegate>
45
46
 
46
47
  - (void)gestureRecognizer:(nullable UIGestureRecognizer *)gestureRecognizer
47
- didActivateInViewWithTouchHandler:(nullable UIView *)viewWithTouchHandler;
48
+ didActivateInViewWithTouchHandler:(nullable RNGHUIView *)viewWithTouchHandler;
48
49
 
49
50
  @end
50
51
 
@@ -53,6 +54,8 @@
53
54
  UIGestureRecognizer *_recognizer;
54
55
  @protected
55
56
  RNGestureHandlerState _lastState;
57
+ @protected
58
+ NSInteger _pointerType;
56
59
  }
57
60
 
58
61
  + (nullable RNGestureHandler *)findGestureHandlerByRecognizer:(nonnull UIGestureRecognizer *)recognizer;
@@ -69,7 +72,7 @@
69
72
  @property (nonatomic) BOOL needsPointerData;
70
73
  @property (nonatomic) BOOL manualActivation;
71
74
 
72
- - (void)bindToView:(nonnull UIView *)view;
75
+ - (void)bindToView:(nonnull RNGHUIView *)view;
73
76
  - (void)unbindFromView;
74
77
  - (void)resetConfig NS_REQUIRES_SUPER;
75
78
  - (void)configure:(nullable NSDictionary *)config NS_REQUIRES_SUPER;
@@ -87,4 +90,10 @@
87
90
  - (void)sendEvent:(nonnull RNGestureHandlerStateChange *)event;
88
91
  - (void)sendTouchEventInState:(RNGestureHandlerState)state forViewWithTag:(nonnull NSNumber *)reactTag;
89
92
 
93
+ #if !TARGET_OS_OSX
94
+ - (void)setCurrentPointerType:(nonnull UIEvent *)event;
95
+ #else
96
+ - (void)setCurrentPointerTypeToMouse;
97
+ #endif
98
+
90
99
  @end
@@ -3,7 +3,9 @@
3
3
 
4
4
  #import "Handlers/RNNativeViewHandler.h"
5
5
 
6
+ #if !TARGET_OS_OSX
6
7
  #import <UIKit/UIGestureRecognizerSubclass.h>
8
+ #endif
7
9
 
8
10
  #import <React/UIView+React.h>
9
11
 
@@ -102,8 +104,9 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
102
104
  _handlersThatShouldWait = nil;
103
105
  _hitSlop = RNGHHitSlopEmpty;
104
106
  _needsPointerData = NO;
105
-
107
+ #if !TARGET_OS_OSX
106
108
  _recognizer.cancelsTouchesInView = YES;
109
+ #endif
107
110
  }
108
111
 
109
112
  - (void)configure:(NSDictionary *)config
@@ -123,10 +126,12 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
123
126
  _shouldCancelWhenOutside = [RCTConvert BOOL:prop];
124
127
  }
125
128
 
129
+ #if !TARGET_OS_OSX
126
130
  prop = config[@"cancelsTouchesInView"];
127
131
  if (prop != nil) {
128
132
  _recognizer.cancelsTouchesInView = [RCTConvert BOOL:prop];
129
133
  }
134
+ #endif
130
135
 
131
136
  prop = config[@"needsPointerData"];
132
137
  if (prop != nil) {
@@ -171,9 +176,43 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
171
176
  self.recognizer.enabled = enabled;
172
177
  }
173
178
 
174
- - (void)bindToView:(UIView *)view
179
+ #if !TARGET_OS_OSX
180
+ - (void)setCurrentPointerType:(UIEvent *)event
181
+ {
182
+ UITouch *touch = [[event allTouches] anyObject];
183
+
184
+ switch (touch.type) {
185
+ case UITouchTypeDirect:
186
+ _pointerType = RNGestureHandlerTouch;
187
+ break;
188
+ case UITouchTypePencil:
189
+ _pointerType = RNGestureHandlerStylus;
190
+ break;
191
+ case UITouchTypeIndirectPointer:
192
+ _pointerType = RNGestureHandlerMouse;
193
+ break;
194
+ default:
195
+ _pointerType = RNGestureHandlerOtherPointer;
196
+ break;
197
+ }
198
+ }
199
+ #else
200
+ - (void)setCurrentPointerTypeToMouse
201
+ {
202
+ _pointerType = RNGestureHandlerMouse;
203
+ }
204
+ #endif
205
+
206
+ - (UITouchType)getPointerType
175
207
  {
208
+ return _pointerType;
209
+ }
210
+
211
+ - (void)bindToView:(RNGHUIView *)view
212
+ {
213
+ #if !TARGET_OS_OSX
176
214
  view.userInteractionEnabled = YES;
215
+ #endif
177
216
  self.recognizer.delegate = self;
178
217
  [view addGestureRecognizer:self.recognizer];
179
218
 
@@ -190,9 +229,17 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
190
229
 
191
230
  - (RNGestureHandlerEventExtraData *)eventExtraData:(UIGestureRecognizer *)recognizer
192
231
  {
232
+ #if TARGET_OS_OSX
233
+ return [RNGestureHandlerEventExtraData forPosition:[recognizer locationInView:recognizer.view]
234
+ withAbsolutePosition:[recognizer locationInView:recognizer.view.window.contentView]
235
+ withNumberOfTouches:1
236
+ withPointerType:RNGestureHandlerMouse];
237
+ #else
193
238
  return [RNGestureHandlerEventExtraData forPosition:[recognizer locationInView:recognizer.view]
194
239
  withAbsolutePosition:[recognizer locationInView:recognizer.view.window]
195
- withNumberOfTouches:recognizer.numberOfTouches];
240
+ withNumberOfTouches:recognizer.numberOfTouches
241
+ withPointerType:_pointerType];
242
+ #endif
196
243
  }
197
244
 
198
245
  - (void)handleGesture:(UIGestureRecognizer *)recognizer
@@ -227,6 +274,15 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
227
274
  return;
228
275
  }
229
276
 
277
+ // Recognizers don't respect manually changing their state (that happens when we are activating handler
278
+ // under custom conditions). If we send a custom event in state ACTIVE and the recognizer will later update its
279
+ // state, we will end up sending ACTIVE->BEGAN and BEGAN->ACTIVE chain. To prevent this, we simply detect the first
280
+ // weird state change and stop it (then we don't update _lastState), so the second call ends up without state change
281
+ // and is fine.
282
+ if (state == RNGestureHandlerStateBegan && _lastState == RNGestureHandlerStateActive) {
283
+ return;
284
+ }
285
+
230
286
  if (state == RNGestureHandlerStateActive) {
231
287
  // Generate a unique coalescing-key each time the gesture-handler becomes active. All events will have
232
288
  // the same coalescing-key allowing RCTEventDispatcher to coalesce RNGestureHandlerEvents when events are
@@ -272,7 +328,8 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
272
328
  id extraData = [RNGestureHandlerEventExtraData forEventType:_pointerTracker.eventType
273
329
  withChangedPointers:_pointerTracker.changedPointersData
274
330
  withAllPointers:_pointerTracker.allPointersData
275
- withNumberOfTouches:_pointerTracker.trackedPointersCount];
331
+ withNumberOfTouches:_pointerTracker.trackedPointersCount
332
+ withPointerType:_pointerType];
276
333
  id event = [[RNGestureHandlerEvent alloc] initWithReactTag:reactTag
277
334
  handlerTag:_tag
278
335
  state:state
@@ -332,7 +389,7 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
332
389
  }
333
390
  }
334
391
 
335
- - (void)bindManualActivationToView:(UIView *)view
392
+ - (void)bindManualActivationToView:(RNGHUIView *)view
336
393
  {
337
394
  if (_manualActivationRecognizer != nil) {
338
395
  [view addGestureRecognizer:_manualActivationRecognizer];
@@ -357,7 +414,7 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
357
414
 
358
415
  // We may try to extract "DummyGestureHandler" in case when "otherGestureRecognizer" belongs to
359
416
  // a native view being wrapped with "NativeViewGestureHandler"
360
- UIView *reactView = recognizer.view;
417
+ RNGHUIView *reactView = recognizer.view;
361
418
  while (reactView != nil && reactView.reactTag == nil) {
362
419
  reactView = reactView.superview;
363
420
  }
@@ -475,7 +532,7 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
475
532
  return YES;
476
533
  }
477
534
 
478
- - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
535
+ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(RNGHUITouch *)touch
479
536
  {
480
537
  // If hitSlop is set we use it to determine if a given gesture recognizer should start processing
481
538
  // touch stream. This only works for negative values of hitSlop as this method won't be triggered
@@ -483,7 +540,11 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
483
540
  // values of hitSlop one should set hitSlop for the underlying view. This limitation is due to the
484
541
  // fact that hitTest method is only available at the level of UIView
485
542
  if (RNGH_HIT_SLOP_IS_SET(_hitSlop)) {
543
+ #if TARGET_OS_OSX
544
+ CGPoint location = [gestureRecognizer.view convertPoint:touch.locationInWindow fromView:nil];
545
+ #else
486
546
  CGPoint location = [touch locationInView:gestureRecognizer.view];
547
+ #endif
487
548
  CGRect hitFrame = RNGHHitSlopInsetRect(gestureRecognizer.view.bounds, _hitSlop);
488
549
  return CGRectContainsPoint(hitFrame, location);
489
550
  }
@@ -8,8 +8,11 @@
8
8
 
9
9
  #import "RNGestureHandler.h"
10
10
 
11
+ #if TARGET_OS_OSX
12
+ @interface RNGestureHandlerButton : NSControl
13
+ #else
11
14
  @interface RNGestureHandlerButton : UIControl
12
-
15
+ #endif
13
16
  /**
14
17
  * Insets used when hit testing inside this view.
15
18
  */
@@ -8,7 +8,9 @@
8
8
 
9
9
  #import "RNGestureHandlerButton.h"
10
10
 
11
+ #if !TARGET_OS_OSX
11
12
  #import <UIKit/UIKit.h>
13
+ #endif
12
14
 
13
15
  /**
14
16
  * Gesture Handler Button components overrides standard mechanism used by RN
@@ -39,23 +41,28 @@
39
41
  if (self) {
40
42
  _hitTestEdgeInsets = UIEdgeInsetsZero;
41
43
  _userEnabled = YES;
42
- #if !TARGET_OS_TV
44
+ #if !TARGET_OS_TV && !TARGET_OS_OSX
43
45
  [self setExclusiveTouch:YES];
44
46
  #endif
45
47
  }
46
48
  return self;
47
49
  }
48
50
 
49
- - (BOOL)shouldHandleTouch:(UIView *)view
51
+ - (BOOL)shouldHandleTouch:(RNGHUIView *)view
50
52
  {
51
53
  if ([view isKindOfClass:[RNGestureHandlerButton class]]) {
52
54
  RNGestureHandlerButton *button = (RNGestureHandlerButton *)view;
53
55
  return button.userEnabled;
54
56
  }
55
57
 
58
+ #if !TARGET_OS_OSX
56
59
  return [view isKindOfClass:[UIControl class]] || [view.gestureRecognizers count] > 0;
60
+ #else
61
+ return [view isKindOfClass:[NSControl class]] || [view.gestureRecognizers count] > 0;
62
+ #endif
57
63
  }
58
64
 
65
+ #if !TARGET_OS_OSX
59
66
  - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
60
67
  {
61
68
  if (UIEdgeInsetsEqualToEdgeInsets(self.hitTestEdgeInsets, UIEdgeInsetsZero)) {
@@ -65,13 +72,14 @@
65
72
  return CGRectContainsPoint(hitFrame, point);
66
73
  }
67
74
 
68
- - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
75
+ - (RNGHUIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
69
76
  {
70
- UIView *inner = [super hitTest:point withEvent:event];
77
+ RNGHUIView *inner = [super hitTest:point withEvent:event];
71
78
  while (inner && ![self shouldHandleTouch:inner]) {
72
79
  inner = inner.superview;
73
80
  }
74
81
  return inner;
75
82
  }
83
+ #endif
76
84
 
77
85
  @end
@@ -9,12 +9,14 @@ RCT_CUSTOM_VIEW_PROPERTY(enabled, BOOL, RNGestureHandlerButton)
9
9
  {
10
10
  view.userEnabled = json == nil ? YES : [RCTConvert BOOL:json];
11
11
  }
12
- #if !TARGET_OS_TV
12
+
13
+ #if !TARGET_OS_TV && !TARGET_OS_OSX
13
14
  RCT_CUSTOM_VIEW_PROPERTY(exclusive, BOOL, RNGestureHandlerButton)
14
15
  {
15
16
  [view setExclusiveTouch:json == nil ? YES : [RCTConvert BOOL:json]];
16
17
  }
17
18
  #endif
19
+
18
20
  RCT_CUSTOM_VIEW_PROPERTY(hitSlop, UIEdgeInsets, RNGestureHandlerButton)
19
21
  {
20
22
  if (json) {
@@ -26,7 +28,7 @@ RCT_CUSTOM_VIEW_PROPERTY(hitSlop, UIEdgeInsets, RNGestureHandlerButton)
26
28
  }
27
29
  }
28
30
 
29
- - (UIView *)view
31
+ - (RNGHUIView *)view
30
32
  {
31
33
  return [RNGestureHandlerButton new];
32
34
  }
@@ -1,9 +1,9 @@
1
1
  #import <React/RCTEventDispatcher.h>
2
2
 
3
3
  #import <Foundation/Foundation.h>
4
- #import <UIKit/UIKit.h>
5
4
 
6
5
  #import "RNGHTouchEventType.h"
6
+ #import "RNGHUIKit.h"
7
7
  #import "RNGestureHandlerState.h"
8
8
 
9
9
  @interface RNGestureHandlerEventExtraData : NSObject
@@ -12,36 +12,45 @@
12
12
 
13
13
  - (instancetype)initWithData:(NSDictionary *)data;
14
14
 
15
- + (RNGestureHandlerEventExtraData *)forPosition:(CGPoint)position withAbsolutePosition:(CGPoint)absolutePosition;
16
15
  + (RNGestureHandlerEventExtraData *)forPosition:(CGPoint)position
17
16
  withAbsolutePosition:(CGPoint)absolutePosition
18
- withNumberOfTouches:(NSUInteger)numberOfTouches;
17
+ withPointerType:(NSInteger)pointerType;
19
18
  + (RNGestureHandlerEventExtraData *)forPosition:(CGPoint)position
20
19
  withAbsolutePosition:(CGPoint)absolutePosition
21
20
  withNumberOfTouches:(NSUInteger)numberOfTouches
22
- withDuration:(NSUInteger)duration;
21
+ withPointerType:(NSInteger)pointerType;
22
+ + (RNGestureHandlerEventExtraData *)forPosition:(CGPoint)position
23
+ withAbsolutePosition:(CGPoint)absolutePosition
24
+ withNumberOfTouches:(NSUInteger)numberOfTouches
25
+ withDuration:(NSUInteger)duration
26
+ withPointerType:(NSInteger)pointerType;
23
27
  + (RNGestureHandlerEventExtraData *)forPan:(CGPoint)position
24
28
  withAbsolutePosition:(CGPoint)absolutePosition
25
29
  withTranslation:(CGPoint)translation
26
30
  withVelocity:(CGPoint)velocity
27
- withNumberOfTouches:(NSUInteger)numberOfTouches;
31
+ withNumberOfTouches:(NSUInteger)numberOfTouches
32
+ withPointerType:(NSInteger)pointerType;
28
33
  + (RNGestureHandlerEventExtraData *)forForce:(CGFloat)force
29
34
  forPosition:(CGPoint)position
30
35
  withAbsolutePosition:(CGPoint)absolutePosition
31
- withNumberOfTouches:(NSUInteger)numberOfTouches;
36
+ withNumberOfTouches:(NSUInteger)numberOfTouches
37
+ withPointerType:(NSInteger)pointerType;
32
38
  + (RNGestureHandlerEventExtraData *)forPinch:(CGFloat)scale
33
39
  withFocalPoint:(CGPoint)focalPoint
34
40
  withVelocity:(CGFloat)velocity
35
- withNumberOfTouches:(NSUInteger)numberOfTouches;
41
+ withNumberOfTouches:(NSUInteger)numberOfTouches
42
+ withPointerType:(NSInteger)pointerType;
36
43
  + (RNGestureHandlerEventExtraData *)forRotation:(CGFloat)rotation
37
44
  withAnchorPoint:(CGPoint)anchorPoint
38
45
  withVelocity:(CGFloat)velocity
39
- withNumberOfTouches:(NSUInteger)numberOfTouches;
46
+ withNumberOfTouches:(NSUInteger)numberOfTouches
47
+ withPointerType:(NSInteger)pointerType;
40
48
  + (RNGestureHandlerEventExtraData *)forEventType:(RNGHTouchEventType)eventType
41
49
  withChangedPointers:(NSArray<NSDictionary *> *)changedPointers
42
50
  withAllPointers:(NSArray<NSDictionary *> *)allPointers
43
- withNumberOfTouches:(NSUInteger)numberOfTouches;
44
- + (RNGestureHandlerEventExtraData *)forPointerInside:(BOOL)pointerInside;
51
+ withNumberOfTouches:(NSUInteger)numberOfTouches
52
+ withPointerType:(NSInteger)pointerType;
53
+ + (RNGestureHandlerEventExtraData *)forPointerInside:(BOOL)pointerInside withPointerType:(NSInteger)pointerType;
45
54
  @end
46
55
 
47
56
  @interface RNGestureHandlerEvent : NSObject <RCTEvent>