react-native-gesture-handler 2.14.1 → 2.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/README.md +1 -0
  2. package/RNGestureHandler.podspec +2 -2
  3. package/android/paper/src/main/java/com/swmansion/gesturehandler/NativeRNGestureHandlerModuleSpec.java +55 -0
  4. package/android/src/main/java/com/swmansion/gesturehandler/RNGestureHandlerPackage.kt +64 -4
  5. package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +12 -2
  6. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt +53 -19
  7. package/{ios → apple}/Handlers/RNFlingHandler.m +25 -5
  8. package/{ios → apple}/Handlers/RNForceTouchHandler.m +25 -7
  9. package/{ios → apple}/Handlers/RNHoverHandler.m +26 -1
  10. package/{ios → apple}/Handlers/RNLongPressHandler.m +24 -4
  11. package/{ios → apple}/Handlers/RNManualHandler.m +24 -4
  12. package/{ios → apple}/Handlers/RNNativeViewHandler.mm +42 -6
  13. package/{ios → apple}/Handlers/RNPanHandler.m +100 -15
  14. package/apple/Handlers/RNPinchHandler.m +162 -0
  15. package/{ios → apple}/Handlers/RNRotationHandler.m +71 -9
  16. package/{ios → apple}/Handlers/RNTapHandler.m +96 -26
  17. package/apple/RNGHUIKit.h +27 -0
  18. package/{ios → apple}/RNGestureHandler.h +3 -3
  19. package/{ios → apple}/RNGestureHandler.m +31 -5
  20. package/{ios → apple}/RNGestureHandlerButton.h +4 -1
  21. package/{ios → apple}/RNGestureHandlerButton.m +12 -4
  22. package/{ios → apple}/RNGestureHandlerButtonManager.m +4 -2
  23. package/{ios → apple}/RNGestureHandlerEvents.h +1 -1
  24. package/{ios → apple}/RNGestureHandlerManager.h +2 -2
  25. package/{ios → apple}/RNGestureHandlerManager.mm +46 -11
  26. package/apple/RNGestureHandlerModule.h +17 -0
  27. package/{ios → apple}/RNGestureHandlerModule.mm +46 -60
  28. package/{ios → apple}/RNGestureHandlerPointerTracker.h +5 -5
  29. package/{ios → apple}/RNGestureHandlerPointerTracker.m +19 -14
  30. package/{ios → apple}/RNGestureHandlerRegistry.h +1 -1
  31. package/{ios → apple}/RNGestureHandlerRegistry.m +1 -1
  32. package/{ios → apple}/RNManualActivationRecognizer.h +8 -0
  33. package/{ios → apple}/RNManualActivationRecognizer.m +27 -7
  34. package/{ios → apple}/RNRootViewGestureRecognizer.m +72 -4
  35. package/lib/commonjs/RNGestureHandlerModule.js +5 -18
  36. package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
  37. package/lib/commonjs/RNGestureHandlerModule.windows.js +10 -102
  38. package/lib/commonjs/RNGestureHandlerModule.windows.js.map +1 -1
  39. package/lib/commonjs/components/DrawerLayout.js +2 -0
  40. package/lib/commonjs/components/DrawerLayout.js.map +1 -1
  41. package/lib/commonjs/handlers/gestureHandlerCommon.js +1 -1
  42. package/lib/commonjs/handlers/gestureHandlerCommon.js.map +1 -1
  43. package/lib/commonjs/handlers/gestures/GestureDetector.js +11 -1
  44. package/lib/commonjs/handlers/gestures/GestureDetector.js.map +1 -1
  45. package/lib/commonjs/handlers/gestures/gesture.js +5 -0
  46. package/lib/commonjs/handlers/gestures/gesture.js.map +1 -1
  47. package/lib/commonjs/index.js +8 -0
  48. package/lib/commonjs/index.js.map +1 -1
  49. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js +13 -0
  50. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -0
  51. package/lib/commonjs/web/handlers/FlingGestureHandler.js +4 -0
  52. package/lib/commonjs/web/handlers/FlingGestureHandler.js.map +1 -1
  53. package/lib/commonjs/web/handlers/GestureHandler.js +13 -1
  54. package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
  55. package/lib/commonjs/web/handlers/LongPressGestureHandler.js +8 -6
  56. package/lib/commonjs/web/handlers/LongPressGestureHandler.js.map +1 -1
  57. package/lib/commonjs/web/handlers/PanGestureHandler.js +4 -0
  58. package/lib/commonjs/web/handlers/PanGestureHandler.js.map +1 -1
  59. package/lib/commonjs/web/handlers/TapGestureHandler.js +4 -0
  60. package/lib/commonjs/web/handlers/TapGestureHandler.js.map +1 -1
  61. package/lib/commonjs/web/interfaces.js +12 -14
  62. package/lib/commonjs/web/interfaces.js.map +1 -1
  63. package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js +35 -0
  64. package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js.map +1 -1
  65. package/lib/commonjs/web/tools/NodeManager.js +3 -2
  66. package/lib/commonjs/web/tools/NodeManager.js.map +1 -1
  67. package/lib/commonjs/web/tools/PointerEventManager.js +11 -3
  68. package/lib/commonjs/web/tools/PointerEventManager.js.map +1 -1
  69. package/lib/commonjs/web/tools/TouchEventManager.js +0 -1
  70. package/lib/commonjs/web/tools/TouchEventManager.js.map +1 -1
  71. package/lib/module/RNGestureHandlerModule.js +4 -18
  72. package/lib/module/RNGestureHandlerModule.js.map +1 -1
  73. package/lib/module/RNGestureHandlerModule.windows.js +10 -81
  74. package/lib/module/RNGestureHandlerModule.windows.js.map +1 -1
  75. package/lib/module/components/DrawerLayout.js +2 -0
  76. package/lib/module/components/DrawerLayout.js.map +1 -1
  77. package/lib/module/handlers/gestureHandlerCommon.js +1 -1
  78. package/lib/module/handlers/gestureHandlerCommon.js.map +1 -1
  79. package/lib/module/handlers/gestures/GestureDetector.js +11 -1
  80. package/lib/module/handlers/gestures/GestureDetector.js.map +1 -1
  81. package/lib/module/handlers/gestures/gesture.js +5 -0
  82. package/lib/module/handlers/gestures/gesture.js.map +1 -1
  83. package/lib/module/index.js +1 -0
  84. package/lib/module/index.js.map +1 -1
  85. package/lib/module/specs/NativeRNGestureHandlerModule.js +3 -0
  86. package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -0
  87. package/lib/module/web/handlers/FlingGestureHandler.js +4 -0
  88. package/lib/module/web/handlers/FlingGestureHandler.js.map +1 -1
  89. package/lib/module/web/handlers/GestureHandler.js +14 -2
  90. package/lib/module/web/handlers/GestureHandler.js.map +1 -1
  91. package/lib/module/web/handlers/LongPressGestureHandler.js +8 -5
  92. package/lib/module/web/handlers/LongPressGestureHandler.js.map +1 -1
  93. package/lib/module/web/handlers/PanGestureHandler.js +4 -0
  94. package/lib/module/web/handlers/PanGestureHandler.js.map +1 -1
  95. package/lib/module/web/handlers/TapGestureHandler.js +4 -0
  96. package/lib/module/web/handlers/TapGestureHandler.js.map +1 -1
  97. package/lib/module/web/interfaces.js +9 -11
  98. package/lib/module/web/interfaces.js.map +1 -1
  99. package/lib/module/web/tools/GestureHandlerWebDelegate.js +34 -0
  100. package/lib/module/web/tools/GestureHandlerWebDelegate.js.map +1 -1
  101. package/lib/module/web/tools/NodeManager.js +3 -2
  102. package/lib/module/web/tools/NodeManager.js.map +1 -1
  103. package/lib/module/web/tools/PointerEventManager.js +12 -4
  104. package/lib/module/web/tools/PointerEventManager.js.map +1 -1
  105. package/lib/module/web/tools/TouchEventManager.js +1 -2
  106. package/lib/module/web/tools/TouchEventManager.js.map +1 -1
  107. package/lib/typescript/RNGestureHandlerModule.d.ts +2 -13
  108. package/lib/typescript/RNGestureHandlerModule.windows.d.ts +5 -21
  109. package/lib/typescript/components/DrawerLayout.d.ts +11 -0
  110. package/lib/typescript/handlers/NativeViewGestureHandler.d.ts +1 -1
  111. package/lib/typescript/handlers/PanGestureHandler.d.ts +1 -1
  112. package/lib/typescript/handlers/gestureHandlerCommon.d.ts +4 -1
  113. package/lib/typescript/handlers/gestures/GestureDetector.d.ts +2 -1
  114. package/lib/typescript/handlers/gestures/gesture.d.ts +2 -0
  115. package/lib/typescript/index.d.ts +1 -0
  116. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +14 -0
  117. package/lib/typescript/web/handlers/GestureHandler.d.ts +3 -1
  118. package/lib/typescript/web/interfaces.d.ts +9 -9
  119. package/lib/typescript/web/tools/GestureHandlerDelegate.d.ts +2 -0
  120. package/lib/typescript/web/tools/GestureHandlerWebDelegate.d.ts +7 -0
  121. package/lib/typescript/web/tools/PointerEventManager.d.ts +2 -0
  122. package/package.json +14 -11
  123. package/src/RNGestureHandlerModule.ts +4 -49
  124. package/src/RNGestureHandlerModule.windows.ts +18 -100
  125. package/src/components/DrawerLayout.tsx +15 -0
  126. package/src/handlers/gestureHandlerCommon.ts +5 -0
  127. package/src/handlers/gestures/GestureDetector.tsx +16 -2
  128. package/src/handlers/gestures/gesture.ts +6 -0
  129. package/src/index.ts +1 -0
  130. package/src/specs/NativeRNGestureHandlerModule.ts +26 -0
  131. package/src/web/handlers/FlingGestureHandler.ts +4 -0
  132. package/src/web/handlers/GestureHandler.ts +17 -0
  133. package/src/web/handlers/LongPressGestureHandler.ts +8 -5
  134. package/src/web/handlers/PanGestureHandler.ts +4 -0
  135. package/src/web/handlers/TapGestureHandler.ts +4 -0
  136. package/src/web/interfaces.ts +10 -10
  137. package/src/web/tools/GestureHandlerDelegate.ts +3 -0
  138. package/src/web/tools/GestureHandlerWebDelegate.ts +39 -0
  139. package/src/web/tools/NodeManager.ts +5 -1
  140. package/src/web/tools/PointerEventManager.ts +18 -2
  141. package/src/web/tools/TouchEventManager.ts +0 -2
  142. package/ios/Handlers/RNPinchHandler.m +0 -95
  143. package/ios/RNGestureHandlerModule.h +0 -7
  144. package/lib/commonjs/RNGestureHandlerModule.macos.js +0 -149
  145. package/lib/commonjs/RNGestureHandlerModule.macos.js.map +0 -1
  146. package/lib/module/RNGestureHandlerModule.macos.js +0 -110
  147. package/lib/module/RNGestureHandlerModule.macos.js.map +0 -1
  148. package/lib/typescript/RNGestureHandlerModule.macos.d.ts +0 -47
  149. package/src/RNGestureHandlerModule.macos.ts +0 -133
  150. /package/{ios → apple}/Handlers/RNFlingHandler.h +0 -0
  151. /package/{ios → apple}/Handlers/RNForceTouchHandler.h +0 -0
  152. /package/{ios → apple}/Handlers/RNHoverHandler.h +0 -0
  153. /package/{ios → apple}/Handlers/RNLongPressHandler.h +0 -0
  154. /package/{ios → apple}/Handlers/RNManualHandler.h +0 -0
  155. /package/{ios → apple}/Handlers/RNNativeViewHandler.h +0 -0
  156. /package/{ios → apple}/Handlers/RNPanHandler.h +0 -0
  157. /package/{ios → apple}/Handlers/RNPinchHandler.h +0 -0
  158. /package/{ios → apple}/Handlers/RNRotationHandler.h +0 -0
  159. /package/{ios → apple}/Handlers/RNTapHandler.h +0 -0
  160. /package/{ios → apple}/RNGHTouchEventType.h +0 -0
  161. /package/{ios → apple}/RNGestureHandler.xcodeproj/project.pbxproj +0 -0
  162. /package/{ios → apple}/RNGestureHandler.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -0
  163. /package/{ios → apple}/RNGestureHandlerActionType.h +0 -0
  164. /package/{ios → apple}/RNGestureHandlerButtonComponentView.h +0 -0
  165. /package/{ios → apple}/RNGestureHandlerButtonComponentView.mm +0 -0
  166. /package/{ios → apple}/RNGestureHandlerButtonManager.h +0 -0
  167. /package/{ios → apple}/RNGestureHandlerDirection.h +0 -0
  168. /package/{ios → apple}/RNGestureHandlerEvents.m +0 -0
  169. /package/{ios → apple}/RNGestureHandlerRootViewComponentView.mm +0 -0
  170. /package/{ios → apple}/RNGestureHandlerState.h +0 -0
  171. /package/{ios → apple}/RNGestureHandlerStateManager.h +0 -0
  172. /package/{ios → apple}/RNRootViewGestureRecognizer.h +0 -0
@@ -1,7 +1,7 @@
1
1
  #import "RNGestureHandlerManager.h"
2
2
 
3
3
  #import <React/RCTComponent.h>
4
- #import <React/RCTEventDispatcher.h>
4
+ #import <React/RCTEventDispatcherProtocol.h>
5
5
  #import <React/RCTLog.h>
6
6
  #import <React/RCTModalHostViewController.h>
7
7
  #import <React/RCTRootContentView.h>
@@ -52,11 +52,12 @@ constexpr int NEW_ARCH_NUMBER_OF_ATTACH_RETRIES = 25;
52
52
  RCTUIManager *_uiManager;
53
53
  NSHashTable<RNRootViewGestureRecognizer *> *_rootViewGestureRecognizers;
54
54
  NSMutableDictionary<NSNumber *, NSNumber *> *_attachRetryCounter;
55
- RCTEventDispatcher *_eventDispatcher;
55
+ id<RCTEventDispatcherProtocol> _eventDispatcher;
56
56
  id _reanimatedModule;
57
57
  }
58
58
 
59
- - (instancetype)initWithUIManager:(RCTUIManager *)uiManager eventDispatcher:(RCTEventDispatcher *)eventDispatcher
59
+ - (instancetype)initWithUIManager:(RCTUIManager *)uiManager
60
+ eventDispatcher:(id<RCTEventDispatcherProtocol>)eventDispatcher
60
61
  {
61
62
  if ((self = [super init])) {
62
63
  _uiManager = uiManager;
@@ -71,6 +72,14 @@ constexpr int NEW_ARCH_NUMBER_OF_ATTACH_RETRIES = 25;
71
72
 
72
73
  - (void)createGestureHandler:(NSString *)handlerName tag:(NSNumber *)handlerTag config:(NSDictionary *)config
73
74
  {
75
+ if ([_registry handlerWithTag:handlerTag] != nullptr) {
76
+ NSString *errorMessage = [NSString
77
+ stringWithFormat:
78
+ @"Handler with tag %@ already exists. Please ensure that no Gesture instance is used across multiple GestureDetectors.",
79
+ handlerTag];
80
+ @throw [NSException exceptionWithName:@"HandlerAlreadyRegistered" reason:errorMessage userInfo:nil];
81
+ }
82
+
74
83
  static NSDictionary *map;
75
84
  static dispatch_once_t mapToken;
76
85
  dispatch_once(&mapToken, ^{
@@ -106,7 +115,7 @@ constexpr int NEW_ARCH_NUMBER_OF_ATTACH_RETRIES = 25;
106
115
  toViewWithTag:(nonnull NSNumber *)viewTag
107
116
  withActionType:(RNGestureHandlerActionType)actionType
108
117
  {
109
- UIView *view = [_uiManager viewForReactTag:viewTag];
118
+ RNGHUIView *view = [_uiManager viewForReactTag:viewTag];
110
119
 
111
120
  #ifdef RCT_NEW_ARCH_ENABLED
112
121
  if (view == nil || view.superview == nil) {
@@ -177,9 +186,9 @@ constexpr int NEW_ARCH_NUMBER_OF_ATTACH_RETRIES = 25;
177
186
  [_registry dropAllHandlers];
178
187
  }
179
188
 
180
- - (void)handleSetJSResponder:(NSNumber *)viewTag blockNativeResponder:(NSNumber *)blockNativeResponder
189
+ - (void)handleSetJSResponder:(NSNumber *)viewTag blockNativeResponder:(BOOL)blockNativeResponder
181
190
  {
182
- if ([blockNativeResponder boolValue]) {
191
+ if (blockNativeResponder) {
183
192
  for (RNRootViewGestureRecognizer *recognizer in _rootViewGestureRecognizers) {
184
193
  [recognizer blockOtherRecognizers];
185
194
  }
@@ -198,11 +207,12 @@ constexpr int NEW_ARCH_NUMBER_OF_ATTACH_RETRIES = 25;
198
207
 
199
208
  #pragma mark Root Views Management
200
209
 
201
- - (void)registerViewWithGestureRecognizerAttachedIfNeeded:(UIView *)childView
210
+ - (void)registerViewWithGestureRecognizerAttachedIfNeeded:(RNGHUIView *)childView
202
211
  {
203
212
  #ifdef RCT_NEW_ARCH_ENABLED
204
- UIView *touchHandlerView = childView;
213
+ RNGHUIView *touchHandlerView = childView;
205
214
 
215
+ #if !TARGET_OS_OSX
206
216
  if ([[childView reactViewController] isKindOfClass:[RCTFabricModalHostViewController class]]) {
207
217
  touchHandlerView = [childView reactViewController].view;
208
218
  } else {
@@ -211,8 +221,15 @@ constexpr int NEW_ARCH_NUMBER_OF_ATTACH_RETRIES = 25;
211
221
  }
212
222
  }
213
223
  #else
214
- UIView *touchHandlerView = nil;
224
+ while (touchHandlerView != nil && ![touchHandlerView isKindOfClass:[RCTSurfaceView class]]) {
225
+ touchHandlerView = touchHandlerView.superview;
226
+ }
227
+ #endif // !TARGET_OS_OSX
215
228
 
229
+ #else
230
+ RNGHUIView *touchHandlerView = nil;
231
+
232
+ #if !TARGET_OS_OSX
216
233
  if ([[childView reactViewController] isKindOfClass:[RCTModalHostViewController class]]) {
217
234
  touchHandlerView = [childView reactViewController].view.subviews[0];
218
235
  } else {
@@ -223,6 +240,15 @@ constexpr int NEW_ARCH_NUMBER_OF_ATTACH_RETRIES = 25;
223
240
 
224
241
  touchHandlerView = [[parent performSelector:@selector(touchHandler)] view];
225
242
  }
243
+ #else
244
+ NSView *parent = childView;
245
+ while (parent != nil && ![parent respondsToSelector:@selector(touchHandler)]) {
246
+ parent = parent.superview;
247
+ }
248
+
249
+ touchHandlerView = [[parent performSelector:@selector(touchHandler)] view];
250
+ #endif // !TARGET_OS_OSX
251
+
226
252
  #endif // RCT_NEW_ARCH_ENABLED
227
253
 
228
254
  if (touchHandlerView == nil) {
@@ -240,13 +266,15 @@ constexpr int NEW_ARCH_NUMBER_OF_ATTACH_RETRIES = 25;
240
266
  RCTLifecycleLog(@"[GESTURE HANDLER] Initialize gesture handler for view %@", touchHandlerView);
241
267
  RNRootViewGestureRecognizer *recognizer = [RNRootViewGestureRecognizer new];
242
268
  recognizer.delegate = self;
269
+ #if !TARGET_OS_OSX
243
270
  touchHandlerView.userInteractionEnabled = YES;
271
+ #endif
244
272
  [touchHandlerView addGestureRecognizer:recognizer];
245
273
  [_rootViewGestureRecognizers addObject:recognizer];
246
274
  }
247
275
 
248
276
  - (void)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
249
- didActivateInViewWithTouchHandler:(UIView *)viewWithTouchHandler
277
+ didActivateInViewWithTouchHandler:(RNGHUIView *)viewWithTouchHandler
250
278
  {
251
279
  // Cancel touches in RN's root view in order to cancel all in-js recognizers
252
280
 
@@ -259,8 +287,15 @@ constexpr int NEW_ARCH_NUMBER_OF_ATTACH_RETRIES = 25;
259
287
  // particular if we have one PanHandler and ScrollView that can work simultaniously then when
260
288
  // the Pan handler activates it would still tigger cancel events.
261
289
  // Once the upstream fix lands the line below along with this comment can be removed
262
- if ([gestureRecognizer.view isKindOfClass:[UIScrollView class]])
290
+ #if TARGET_OS_OSX
291
+ if ([gestureRecognizer.view isKindOfClass:[NSScrollView class]]) {
292
+ return;
293
+ }
294
+ #else
295
+ if ([gestureRecognizer.view isKindOfClass:[UIScrollView class]]) {
263
296
  return;
297
+ }
298
+ #endif
264
299
 
265
300
  UIGestureRecognizer *touchHandler = nil;
266
301
 
@@ -0,0 +1,17 @@
1
+ #import <React/RCTEventEmitter.h>
2
+ #import <React/RCTUIManager.h>
3
+
4
+ #ifdef RN_FABRIC_ENABLED
5
+ #import <rngesturehandler_codegen/rngesturehandler_codegen.h>
6
+ #else
7
+ #import <React/RCTBridgeModule.h>
8
+ #endif
9
+
10
+ @interface RNGestureHandlerModule : RCTEventEmitter
11
+ #ifdef RN_FABRIC_ENABLED
12
+ <NativeRNGestureHandlerModuleSpec>
13
+ #else
14
+ <RCTBridgeModule>
15
+ #endif
16
+
17
+ @end
@@ -10,7 +10,6 @@
10
10
  #ifdef RCT_NEW_ARCH_ENABLED
11
11
  #import <React/RCTBridge+Private.h>
12
12
  #import <React/RCTBridge.h>
13
- #import <React/RCTSurfacePresenter.h>
14
13
  #import <React/RCTUtils.h>
15
14
  #import <ReactCommon/CallInvoker.h>
16
15
  #import <ReactCommon/RCTTurboModule.h>
@@ -26,13 +25,15 @@
26
25
  #import "RNGestureHandlerButton.h"
27
26
  #import "RNGestureHandlerStateManager.h"
28
27
 
28
+ #import <React/RCTJSThread.h>
29
+
29
30
  #ifdef RCT_NEW_ARCH_ENABLED
30
31
  using namespace facebook;
31
32
  using namespace react;
32
33
  #endif // RCT_NEW_ARCH_ENABLED
33
34
 
34
35
  #ifdef RCT_NEW_ARCH_ENABLED
35
- @interface RNGestureHandlerModule () <RCTSurfacePresenterObserver, RNGestureHandlerStateManager>
36
+ @interface RNGestureHandlerModule () <RNGestureHandlerStateManager>
36
37
 
37
38
  @end
38
39
  #else
@@ -66,9 +67,7 @@ RCT_EXPORT_MODULE()
66
67
 
67
68
  _manager = nil;
68
69
 
69
- #ifdef RCT_NEW_ARCH_ENABLED
70
- [self.bridge.surfacePresenter removeObserver:self];
71
- #else
70
+ #ifndef RCT_NEW_ARCH_ENABLED
72
71
  [self.bridge.uiManager.observerCoordinator removeObserver:self];
73
72
  #endif // RCT_NEW_ARCH_ENABLED
74
73
  }
@@ -113,9 +112,7 @@ void decorateRuntime(jsi::Runtime &runtime)
113
112
  eventDispatcher:bridge.eventDispatcher];
114
113
  _operations = [NSMutableArray new];
115
114
 
116
- #ifdef RCT_NEW_ARCH_ENABLED
117
- [bridge.surfacePresenter addObserver:self];
118
- #else
115
+ #ifndef RCT_NEW_ARCH_ENABLED
119
116
  [bridge.uiManager.observerCoordinator addObserver:self];
120
117
  #endif // RCT_NEW_ARCH_ENABLED
121
118
  }
@@ -123,55 +120,55 @@ void decorateRuntime(jsi::Runtime &runtime)
123
120
  #ifdef RCT_NEW_ARCH_ENABLED
124
121
  RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install)
125
122
  {
126
- RCTCxxBridge *cxxBridge = (RCTCxxBridge *)self.bridge;
127
- auto runtime = (jsi::Runtime *)cxxBridge.runtime;
128
- decorateRuntime(*runtime);
123
+ [self.bridge
124
+ dispatchBlock:^{
125
+ RCTCxxBridge *cxxBridge = (RCTCxxBridge *)self.bridge;
126
+ auto runtime = (jsi::Runtime *)cxxBridge.runtime;
127
+ decorateRuntime(*runtime);
128
+ }
129
+ queue:RCTJSThread];
130
+
129
131
  return @true;
130
132
  }
131
133
  #endif // RCT_NEW_ARCH_ENABLED
132
134
 
133
135
  RCT_EXPORT_METHOD(createGestureHandler
134
- : (nonnull NSString *)handlerName tag
135
- : (nonnull NSNumber *)handlerTag config
136
+ : (nonnull NSString *)handlerName handlerTag
137
+ : (double)handlerTag config
136
138
  : (NSDictionary *)config)
137
139
  {
138
140
  [self addOperationBlock:^(RNGestureHandlerManager *manager) {
139
- [manager createGestureHandler:handlerName tag:handlerTag config:config];
141
+ [manager createGestureHandler:handlerName tag:[NSNumber numberWithDouble:handlerTag] config:config];
140
142
  }];
141
143
  }
142
144
 
143
- RCT_EXPORT_METHOD(attachGestureHandler
144
- : (nonnull NSNumber *)handlerTag toViewWithTag
145
- : (nonnull NSNumber *)viewTag actionType
146
- : (nonnull NSNumber *)actionType)
145
+ RCT_EXPORT_METHOD(attachGestureHandler : (double)handlerTag newView : (double)viewTag actionType : (double)actionType)
147
146
  {
148
147
  [self addOperationBlock:^(RNGestureHandlerManager *manager) {
149
- [manager attachGestureHandler:handlerTag
150
- toViewWithTag:viewTag
151
- withActionType:(RNGestureHandlerActionType)[actionType integerValue]];
148
+ [manager attachGestureHandler:[NSNumber numberWithDouble:handlerTag]
149
+ toViewWithTag:[NSNumber numberWithDouble:viewTag]
150
+ withActionType:(RNGestureHandlerActionType)[[NSNumber numberWithDouble:actionType] integerValue]];
152
151
  }];
153
152
  }
154
153
 
155
- RCT_EXPORT_METHOD(updateGestureHandler : (nonnull NSNumber *)handlerTag config : (NSDictionary *)config)
154
+ RCT_EXPORT_METHOD(updateGestureHandler : (double)handlerTag newConfig : (NSDictionary *)config)
156
155
  {
157
156
  [self addOperationBlock:^(RNGestureHandlerManager *manager) {
158
- [manager updateGestureHandler:handlerTag config:config];
157
+ [manager updateGestureHandler:[NSNumber numberWithDouble:handlerTag] config:config];
159
158
  }];
160
159
  }
161
160
 
162
- RCT_EXPORT_METHOD(dropGestureHandler : (nonnull NSNumber *)handlerTag)
161
+ RCT_EXPORT_METHOD(dropGestureHandler : (double)handlerTag)
163
162
  {
164
163
  [self addOperationBlock:^(RNGestureHandlerManager *manager) {
165
- [manager dropGestureHandler:handlerTag];
164
+ [manager dropGestureHandler:[NSNumber numberWithDouble:handlerTag]];
166
165
  }];
167
166
  }
168
167
 
169
- RCT_EXPORT_METHOD(handleSetJSResponder
170
- : (nonnull NSNumber *)viewTag blockNativeResponder
171
- : (nonnull NSNumber *)blockNativeResponder)
168
+ RCT_EXPORT_METHOD(handleSetJSResponder : (double)viewTag blockNativeResponder : (BOOL)blockNativeResponder)
172
169
  {
173
170
  [self addOperationBlock:^(RNGestureHandlerManager *manager) {
174
- [manager handleSetJSResponder:viewTag blockNativeResponder:blockNativeResponder];
171
+ [manager handleSetJSResponder:[NSNumber numberWithDouble:viewTag] blockNativeResponder:blockNativeResponder];
175
172
  }];
176
173
  }
177
174
 
@@ -209,16 +206,16 @@ RCT_EXPORT_METHOD(flushOperations)
209
206
 
210
207
  if (handler != nil) {
211
208
  if (state == 1) { // FAILED
212
- handler.recognizer.state = UIGestureRecognizerStateFailed;
209
+ handler.recognizer.state = RNGHGestureRecognizerStateFailed;
213
210
  } else if (state == 2) { // BEGAN
214
- handler.recognizer.state = UIGestureRecognizerStatePossible;
211
+ handler.recognizer.state = RNGHGestureRecognizerStatePossible;
215
212
  } else if (state == 3) { // CANCELLED
216
- handler.recognizer.state = UIGestureRecognizerStateCancelled;
213
+ handler.recognizer.state = RNGHGestureRecognizerStateCancelled;
217
214
  } else if (state == 4) { // ACTIVE
218
215
  [handler stopActivationBlocker];
219
- handler.recognizer.state = UIGestureRecognizerStateBegan;
216
+ handler.recognizer.state = RNGHGestureRecognizerStateBegan;
220
217
  } else if (state == 5) { // ENDED
221
- handler.recognizer.state = UIGestureRecognizerStateEnded;
218
+ handler.recognizer.state = RNGHGestureRecognizerStateEnded;
222
219
  }
223
220
  }
224
221
 
@@ -241,27 +238,7 @@ RCT_EXPORT_METHOD(flushOperations)
241
238
  [_operations addObject:operation];
242
239
  }
243
240
 
244
- #pragma mark - RCTSurfacePresenterObserver
245
-
246
- #ifdef RCT_NEW_ARCH_ENABLED
247
-
248
- - (void)didMountComponentsWithRootTag:(NSInteger)rootTag
249
- {
250
- RCTAssertMainQueue();
251
-
252
- if (_operations.count == 0) {
253
- return;
254
- }
255
-
256
- NSArray<GestureHandlerOperation> *operations = _operations;
257
- _operations = [NSMutableArray new];
258
-
259
- for (GestureHandlerOperation operation in operations) {
260
- operation(self->_manager);
261
- }
262
- }
263
-
264
- #else
241
+ #ifndef RCT_NEW_ARCH_ENABLED
265
242
 
266
243
  #pragma mark - RCTUIManagerObserver
267
244
 
@@ -279,11 +256,12 @@ RCT_EXPORT_METHOD(flushOperations)
279
256
  NSArray<GestureHandlerOperation> *operations = _operations;
280
257
  _operations = [NSMutableArray new];
281
258
 
282
- [uiManager addUIBlock:^(__unused RCTUIManager *manager, __unused NSDictionary<NSNumber *, UIView *> *viewRegistry) {
283
- for (GestureHandlerOperation operation in operations) {
284
- operation(self->_manager);
285
- }
286
- }];
259
+ [uiManager
260
+ addUIBlock:^(__unused RCTUIManager *manager, __unused NSDictionary<NSNumber *, RNGHUIView *> *viewRegistry) {
261
+ for (GestureHandlerOperation operation in operations) {
262
+ operation(self->_manager);
263
+ }
264
+ }];
287
265
  }
288
266
 
289
267
  #endif // RCT_NEW_ARCH_ENABLED
@@ -317,4 +295,12 @@ RCT_EXPORT_METHOD(flushOperations)
317
295
  };
318
296
  }
319
297
 
298
+ #if RN_FABRIC_ENABLED
299
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
300
+ (const facebook::react::ObjCTurboModule::InitParams &)params
301
+ {
302
+ return std::make_shared<facebook::react::NativeRNGestureHandlerModuleSpecJSI>(params);
303
+ }
304
+ #endif
305
+
320
306
  @end
@@ -1,6 +1,6 @@
1
1
  #import <Foundation/Foundation.h>
2
-
3
2
  #import "RNGHTouchEventType.h"
3
+ #import "RNGHUIKit.h"
4
4
 
5
5
  #define MAX_POINTERS_COUNT 12
6
6
 
@@ -15,10 +15,10 @@
15
15
 
16
16
  - (id)initWithGestureHandler:(RNGestureHandler *)gestureHandler;
17
17
 
18
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
19
- - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
20
- - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
21
- - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
18
+ - (void)touchesBegan:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event;
19
+ - (void)touchesMoved:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event;
20
+ - (void)touchesEnded:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event;
21
+ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event;
22
22
  - (void)reset;
23
23
  - (void)cancelPointers;
24
24
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  @implementation RNGestureHandlerPointerTracker {
7
7
  __weak RNGestureHandler *_gestureHandler;
8
- UITouch *_trackedPointers[MAX_POINTERS_COUNT];
8
+ RNGHUITouch *_trackedPointers[MAX_POINTERS_COUNT];
9
9
  int _trackedPointersCount;
10
10
  }
11
11
 
@@ -23,7 +23,7 @@
23
23
  return self;
24
24
  }
25
25
 
26
- - (int)registerTouch:(UITouch *)touch
26
+ - (int)registerTouch:(RNGHUITouch *)touch
27
27
  {
28
28
  for (int index = 0; index < MAX_POINTERS_COUNT; index++) {
29
29
  if (_trackedPointers[index] == nil) {
@@ -35,7 +35,7 @@
35
35
  return -1;
36
36
  }
37
37
 
38
- - (int)unregisterTouch:(UITouch *)touch
38
+ - (int)unregisterTouch:(RNGHUITouch *)touch
39
39
  {
40
40
  for (int index = 0; index < MAX_POINTERS_COUNT; index++) {
41
41
  if (_trackedPointers[index] == touch) {
@@ -47,7 +47,7 @@
47
47
  return -1;
48
48
  }
49
49
 
50
- - (int)findTouchIndex:(UITouch *)touch
50
+ - (int)findTouchIndex:(RNGHUITouch *)touch
51
51
  {
52
52
  for (int index = 0; index < MAX_POINTERS_COUNT; index++) {
53
53
  if (_trackedPointers[index] == touch) {
@@ -68,10 +68,15 @@
68
68
  return count;
69
69
  }
70
70
 
71
- - (NSDictionary *)extractPointerData:(int)index forTouch:(UITouch *)touch
71
+ - (NSDictionary *)extractPointerData:(int)index forTouch:(RNGHUITouch *)touch
72
72
  {
73
+ #if TARGET_OS_OSX
74
+ CGPoint absolutePos = [touch locationInWindow];
75
+ CGPoint relativePos = [touch.window.contentView convertPoint:absolutePos fromView:_gestureHandler.recognizer.view];
76
+ #else
73
77
  CGPoint relativePos = [touch locationInView:_gestureHandler.recognizer.view];
74
78
  CGPoint absolutePos = [touch locationInView:_gestureHandler.recognizer.view.window];
79
+ #endif
75
80
 
76
81
  return @{
77
82
  @"id" : @(index),
@@ -90,7 +95,7 @@
90
95
  int nextIndex = 0;
91
96
 
92
97
  for (int i = 0; i < MAX_POINTERS_COUNT; i++) {
93
- UITouch *touch = _trackedPointers[i];
98
+ RNGHUITouch *touch = _trackedPointers[i];
94
99
  if (touch != nil) {
95
100
  data[nextIndex++] = [self extractPointerData:i forTouch:touch];
96
101
  }
@@ -99,7 +104,7 @@
99
104
  _allPointersData = [[NSArray alloc] initWithObjects:data count:registeredTouches];
100
105
  }
101
106
 
102
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
107
+ - (void)touchesBegan:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
103
108
  {
104
109
  if (!_gestureHandler.needsPointerData) {
105
110
  return;
@@ -110,7 +115,7 @@
110
115
  NSDictionary *data[touches.count];
111
116
 
112
117
  for (int i = 0; i < [touches count]; i++) {
113
- UITouch *touch = [[touches allObjects] objectAtIndex:i];
118
+ RNGHUITouch *touch = [[touches allObjects] objectAtIndex:i];
114
119
  int index = [self registerTouch:touch];
115
120
  if (index >= 0) {
116
121
  _trackedPointersCount++;
@@ -125,7 +130,7 @@
125
130
  [self sendEvent];
126
131
  }
127
132
 
128
- - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
133
+ - (void)touchesMoved:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
129
134
  {
130
135
  if (!_gestureHandler.needsPointerData) {
131
136
  return;
@@ -136,7 +141,7 @@
136
141
  NSDictionary *data[touches.count];
137
142
 
138
143
  for (int i = 0; i < [touches count]; i++) {
139
- UITouch *touch = [[touches allObjects] objectAtIndex:i];
144
+ RNGHUITouch *touch = [[touches allObjects] objectAtIndex:i];
140
145
  int index = [self findTouchIndex:touch];
141
146
  data[i] = [self extractPointerData:index forTouch:touch];
142
147
  }
@@ -146,7 +151,7 @@
146
151
  [self sendEvent];
147
152
  }
148
153
 
149
- - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
154
+ - (void)touchesEnded:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
150
155
  {
151
156
  if (!_gestureHandler.needsPointerData) {
152
157
  return;
@@ -160,7 +165,7 @@
160
165
  NSDictionary *data[touches.count];
161
166
 
162
167
  for (int i = 0; i < [touches count]; i++) {
163
- UITouch *touch = [[touches allObjects] objectAtIndex:i];
168
+ RNGHUITouch *touch = [[touches allObjects] objectAtIndex:i];
164
169
  int index = [self unregisterTouch:touch];
165
170
  if (index >= 0) {
166
171
  _trackedPointersCount--;
@@ -173,7 +178,7 @@
173
178
  [self sendEvent];
174
179
  }
175
180
 
176
- - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
181
+ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
177
182
  {
178
183
  if (!_gestureHandler.needsPointerData) {
179
184
  return;
@@ -213,7 +218,7 @@
213
218
  NSDictionary *data[registeredTouches];
214
219
 
215
220
  for (int i = 0; i < MAX_POINTERS_COUNT; i++) {
216
- UITouch *touch = _trackedPointers[i];
221
+ RNGHUITouch *touch = _trackedPointers[i];
217
222
  if (touch != nil) {
218
223
  data[nextIndex++] = [self extractPointerData:i forTouch:touch];
219
224
  [self unregisterTouch:touch];
@@ -13,7 +13,7 @@
13
13
  - (nullable RNGestureHandler *)handlerWithTag:(nonnull NSNumber *)handlerTag;
14
14
  - (void)registerGestureHandler:(nonnull RNGestureHandler *)gestureHandler;
15
15
  - (void)attachHandlerWithTag:(nonnull NSNumber *)handlerTag
16
- toView:(nonnull UIView *)view
16
+ toView:(nonnull RNGHUIView *)view
17
17
  withActionType:(RNGestureHandlerActionType)actionType;
18
18
  - (void)dropHandlerWithTag:(nonnull NSNumber *)handlerTag;
19
19
  - (void)dropAllHandlers;
@@ -33,7 +33,7 @@
33
33
  }
34
34
 
35
35
  - (void)attachHandlerWithTag:(NSNumber *)handlerTag
36
- toView:(UIView *)view
36
+ toView:(RNGHUIView *)view
37
37
  withActionType:(RNGestureHandlerActionType)actionType
38
38
  {
39
39
  RNGestureHandler *handler = _handlers[handlerTag];
@@ -1,8 +1,16 @@
1
+ #if !TARGET_OS_OSX
1
2
  #import <UIKit/UIGestureRecognizerSubclass.h>
3
+ #else
4
+ #import <Appkit/NSGestureRecognizer.h>
5
+ #endif
2
6
 
3
7
  @class RNGestureHandler;
4
8
 
9
+ #if !TARGET_OS_OSX
5
10
  @interface RNManualActivationRecognizer : UIGestureRecognizer <UIGestureRecognizerDelegate>
11
+ #else
12
+ @interface RNManualActivationRecognizer : NSGestureRecognizer <NSGestureRecognizerDelegate>
13
+ #endif
6
14
 
7
15
  - (id)initWithGestureHandler:(RNGestureHandler *)gestureHandler;
8
16
  - (void)fail;
@@ -12,7 +12,9 @@
12
12
  _handler = gestureHandler;
13
13
  _activePointers = 0;
14
14
  self.delegate = self;
15
+ #if !TARGET_OS_OSX
15
16
  self.cancelsTouchesInView = NO;
17
+ #endif
16
18
  }
17
19
  return self;
18
20
  }
@@ -25,19 +27,35 @@
25
27
  }
26
28
  }
27
29
 
28
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
30
+ #if TARGET_OS_OSX
31
+ - (void)mouseUp:(NSEvent *)event
29
32
  {
30
- [super touchesBegan:touches withEvent:event];
33
+ [super mouseUp:event];
31
34
 
32
- _activePointers += touches.count;
35
+ _activePointers -= 1;
33
36
  }
34
37
 
35
- - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
38
+ - (void)mouseDown:(NSEvent *)event
36
39
  {
37
- [super touchesMoved:touches withEvent:event];
40
+ [super mouseDown:event];
41
+
42
+ _activePointers += 1;
43
+
44
+ if (_activePointers == 0) {
45
+ self.state = UIGestureRecognizerStateBegan;
46
+ }
38
47
  }
39
48
 
40
- - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
49
+ #else
50
+
51
+ - (void)touchesBegan:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
52
+ {
53
+ [super touchesBegan:touches withEvent:event];
54
+
55
+ _activePointers += touches.count;
56
+ }
57
+
58
+ - (void)touchesEnded:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
41
59
  {
42
60
  [super touchesEnded:touches withEvent:event];
43
61
 
@@ -48,7 +66,7 @@
48
66
  }
49
67
  }
50
68
 
51
- - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
69
+ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
52
70
  {
53
71
  [super touchesCancelled:touches withEvent:event];
54
72
 
@@ -56,6 +74,8 @@
56
74
  [self reset];
57
75
  }
58
76
 
77
+ #endif
78
+
59
79
  - (void)reset
60
80
  {
61
81
  self.enabled = YES;