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,5 +1,7 @@
1
1
  #import "RNManualHandler.h"
2
2
 
3
+ #if !TARGET_OS_OSX
4
+
3
5
  @interface RNManualRecognizer : UIGestureRecognizer
4
6
 
5
7
  - (id)initWithGestureHandler:(RNGestureHandler *)gestureHandler;
@@ -20,7 +22,7 @@
20
22
  return self;
21
23
  }
22
24
 
23
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
25
+ - (void)touchesBegan:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
24
26
  {
25
27
  [super touchesBegan:touches withEvent:event];
26
28
  [_gestureHandler.pointerTracker touchesBegan:touches withEvent:event];
@@ -31,7 +33,7 @@
31
33
  }
32
34
  }
33
35
 
34
- - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
36
+ - (void)touchesMoved:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
35
37
  {
36
38
  [super touchesMoved:touches withEvent:event];
37
39
  [_gestureHandler.pointerTracker touchesMoved:touches withEvent:event];
@@ -44,13 +46,13 @@
44
46
  }
45
47
  }
46
48
 
47
- - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
49
+ - (void)touchesEnded:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
48
50
  {
49
51
  [super touchesEnded:touches withEvent:event];
50
52
  [_gestureHandler.pointerTracker touchesEnded:touches withEvent:event];
51
53
  }
52
54
 
53
- - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
55
+ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
54
56
  {
55
57
  [super touchesCancelled:touches withEvent:event];
56
58
  [_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
@@ -60,6 +62,7 @@
60
62
  {
61
63
  [_gestureHandler.pointerTracker reset];
62
64
  [super reset];
65
+ [_gestureHandler reset];
63
66
 
64
67
  _shouldSendBeginEvent = YES;
65
68
  }
@@ -86,3 +89,20 @@
86
89
  }
87
90
 
88
91
  @end
92
+
93
+ #else
94
+
95
+ @implementation RNManualGestureHandler
96
+
97
+ - (instancetype)initWithTag:(NSNumber *)tag
98
+ {
99
+ RCTLogWarn(@"ManualGestureHandler is not supported on macOS");
100
+ if ((self = [super initWithTag:tag])) {
101
+ _recognizer = [NSGestureRecognizer alloc];
102
+ }
103
+ return self;
104
+ }
105
+
106
+ @end
107
+
108
+ #endif
@@ -8,7 +8,9 @@
8
8
 
9
9
  #import "RNNativeViewHandler.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
  #import <React/UIView+React.h>
@@ -19,6 +21,8 @@
19
21
  #import <React/RCTScrollView.h>
20
22
  #endif // RCT_NEW_ARCH_ENABLED
21
23
 
24
+ #if !TARGET_OS_OSX
25
+
22
26
  #pragma mark RNDummyGestureRecognizer
23
27
 
24
28
  @implementation RNDummyGestureRecognizer {
@@ -33,24 +37,24 @@
33
37
  return self;
34
38
  }
35
39
 
36
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
40
+ - (void)touchesBegan:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
37
41
  {
38
42
  [_gestureHandler.pointerTracker touchesBegan:touches withEvent:event];
39
43
  }
40
44
 
41
- - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
45
+ - (void)touchesMoved:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
42
46
  {
43
47
  [_gestureHandler.pointerTracker touchesMoved:touches withEvent:event];
44
48
  }
45
49
 
46
- - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
50
+ - (void)touchesEnded:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
47
51
  {
48
52
  [_gestureHandler.pointerTracker touchesEnded:touches withEvent:event];
49
53
  self.state = UIGestureRecognizerStateFailed;
50
54
  [self reset];
51
55
  }
52
56
 
53
- - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
57
+ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
54
58
  {
55
59
  [_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
56
60
  self.state = UIGestureRecognizerStateCancelled;
@@ -61,11 +65,12 @@
61
65
  {
62
66
  [_gestureHandler.pointerTracker reset];
63
67
  [super reset];
68
+ [_gestureHandler reset];
64
69
  }
65
70
 
66
71
  @end
67
72
 
68
- #pragma mark RNNativeViewgestureHandler
73
+ #pragma mark RNNativeViewGestureHandler
69
74
 
70
75
  @implementation RNNativeViewGestureHandler {
71
76
  BOOL _shouldActivateOnStart;
@@ -133,7 +138,7 @@
133
138
  if (_disallowInterruption) {
134
139
  // When `disallowInterruption` is set we cancel all gesture handlers when this UIControl
135
140
  // gets DOWN event
136
- for (UITouch *touch in [event allTouches]) {
141
+ for (RNGHUITouch *touch in [event allTouches]) {
137
142
  for (UIGestureRecognizer *recogn in [touch gestureRecognizers]) {
138
143
  recogn.enabled = NO;
139
144
  recogn.enabled = YES;
@@ -191,3 +196,34 @@
191
196
  }
192
197
 
193
198
  @end
199
+
200
+ #else
201
+
202
+ #pragma mark RNDummyGestureRecognizer
203
+
204
+ @implementation RNDummyGestureRecognizer
205
+
206
+ - (id)initWithGestureHandler:(RNGestureHandler *)gestureHandler
207
+ {
208
+ self = [super initWithTarget:gestureHandler action:@selector(handleGesture:)];
209
+ return self;
210
+ }
211
+
212
+ @end
213
+
214
+ #pragma mark RNNativeViewGestureHandler
215
+
216
+ @implementation RNNativeViewGestureHandler
217
+
218
+ - (instancetype)initWithTag:(NSNumber *)tag
219
+ {
220
+ RCTLogWarn(@"NativeViewGestureHandler is not supported on macOS");
221
+ if ((self = [super initWithTag:tag])) {
222
+ _recognizer = [NSGestureRecognizer alloc];
223
+ }
224
+ return self;
225
+ }
226
+
227
+ @end
228
+
229
+ #endif
@@ -8,9 +8,13 @@
8
8
 
9
9
  #import "RNPanHandler.h"
10
10
 
11
+ #if TARGET_OS_OSX
12
+ @interface RNBetterPanGestureRecognizer : NSPanGestureRecognizer
13
+ #else
11
14
  #import <UIKit/UIGestureRecognizerSubclass.h>
12
15
 
13
16
  @interface RNBetterPanGestureRecognizer : UIPanGestureRecognizer
17
+ #endif
14
18
 
15
19
  @property (nonatomic) CGFloat minDistSq;
16
20
  @property (nonatomic) CGFloat minVelocityX;
@@ -32,7 +36,9 @@
32
36
 
33
37
  @implementation RNBetterPanGestureRecognizer {
34
38
  __weak RNGestureHandler *_gestureHandler;
39
+ #if !TARGET_OS_OSX
35
40
  NSUInteger _realMinimumNumberOfTouches;
41
+ #endif
36
42
  BOOL _hasCustomActivationCriteria;
37
43
  }
38
44
 
@@ -54,7 +60,7 @@
54
60
  _failOffsetYEnd = NAN;
55
61
  _activateAfterLongPress = NAN;
56
62
  _hasCustomActivationCriteria = NO;
57
- #if !TARGET_OS_TV
63
+ #if !TARGET_OS_TV && !TARGET_OS_OSX
58
64
  _realMinimumNumberOfTouches = self.minimumNumberOfTouches;
59
65
  #endif
60
66
  }
@@ -66,10 +72,12 @@
66
72
  [_gestureHandler handleGesture:self];
67
73
  }
68
74
 
75
+ #if !TARGET_OS_OSX
69
76
  - (void)setMinimumNumberOfTouches:(NSUInteger)minimumNumberOfTouches
70
77
  {
71
78
  _realMinimumNumberOfTouches = minimumNumberOfTouches;
72
79
  }
80
+ #endif
73
81
 
74
82
  - (void)activateAfterLongPress
75
83
  {
@@ -78,12 +86,13 @@
78
86
  [_gestureHandler handleGesture:self inState:RNGestureHandlerStateActive];
79
87
  }
80
88
 
81
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
89
+ - (void)interactionsBegan:(NSSet *)touches withEvent:(UIEvent *)event
82
90
  {
83
- if ([self numberOfTouches] == 0) {
91
+ if (touches.count == 0) {
84
92
  [_gestureHandler reset];
85
93
  }
86
- #if !TARGET_OS_TV
94
+
95
+ #if !TARGET_OS_TV && !TARGET_OS_OSX
87
96
  if (_hasCustomActivationCriteria) {
88
97
  // We use "minimumNumberOfTouches" property to prevent pan handler from recognizing
89
98
  // the gesture too early before we are sure that all criteria (e.g. minimum distance
@@ -93,7 +102,13 @@
93
102
  super.minimumNumberOfTouches = _realMinimumNumberOfTouches;
94
103
  }
95
104
  #endif
105
+
106
+ #if TARGET_OS_OSX
107
+ [super mouseDown:event];
108
+ #else
96
109
  [super touchesBegan:touches withEvent:event];
110
+ #endif
111
+
97
112
  [_gestureHandler.pointerTracker touchesBegan:touches withEvent:event];
98
113
  [self triggerAction];
99
114
 
@@ -102,15 +117,16 @@
102
117
  }
103
118
  }
104
119
 
105
- - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
120
+ - (void)interactionsMoved:(NSSet *)touches withEvent:(UIEvent *)event
106
121
  {
107
- [super touchesMoved:touches withEvent:event];
108
122
  [_gestureHandler.pointerTracker touchesMoved:touches withEvent:event];
109
123
 
110
124
  if (self.state == UIGestureRecognizerStatePossible && [self shouldFailUnderCustomCriteria]) {
111
125
  self.state = UIGestureRecognizerStateFailed;
126
+ [self triggerAction];
112
127
  return;
113
128
  }
129
+
114
130
  if ((self.state == UIGestureRecognizerStatePossible || self.state == UIGestureRecognizerStateChanged)) {
115
131
  if (_gestureHandler.shouldCancelWhenOutside && ![_gestureHandler containsPointInView]) {
116
132
  // If the previous recognizer state is UIGestureRecognizerStateChanged
@@ -123,30 +139,79 @@
123
139
  return;
124
140
  }
125
141
  }
142
+
143
+ #if !TARGET_OS_TV && !TARGET_OS_OSX
126
144
  if (_hasCustomActivationCriteria && self.state == UIGestureRecognizerStatePossible &&
127
145
  [self shouldActivateUnderCustomCriteria]) {
128
- #if !TARGET_OS_TV
129
146
  super.minimumNumberOfTouches = _realMinimumNumberOfTouches;
130
147
  if ([self numberOfTouches] >= _realMinimumNumberOfTouches) {
131
148
  self.state = UIGestureRecognizerStateBegan;
132
149
  [self setTranslation:CGPointMake(0, 0) inView:self.view];
133
150
  }
134
- #endif
135
151
  }
152
+ #endif
136
153
  }
137
154
 
138
- - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
155
+ - (void)interactionsEnded:(NSSet *)touches withEvent:(UIEvent *)event
139
156
  {
140
- [super touchesEnded:touches withEvent:event];
141
157
  [_gestureHandler.pointerTracker touchesEnded:touches withEvent:event];
142
158
  }
143
159
 
144
- - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
160
+ - (void)interactionsCancelled:(NSSet *)touches withEvent:(UIEvent *)event
145
161
  {
146
- [super touchesCancelled:touches withEvent:event];
147
162
  [_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
148
163
  }
149
164
 
165
+ #if TARGET_OS_OSX
166
+
167
+ - (void)mouseDown:(NSEvent *)event
168
+ {
169
+ // super call was moved to interactionsBegan method to keep the
170
+ // original order of calls
171
+ [self interactionsBegan:[NSSet setWithObject:event] withEvent:event];
172
+ }
173
+
174
+ - (void)mouseDragged:(NSEvent *)event
175
+ {
176
+ [super mouseDragged:event];
177
+ [self interactionsMoved:[NSSet setWithObject:event] withEvent:event];
178
+ }
179
+
180
+ - (void)mouseUp:(NSEvent *)event
181
+ {
182
+ [super mouseUp:event];
183
+ [self interactionsEnded:[NSSet setWithObject:event] withEvent:event];
184
+ }
185
+
186
+ #else
187
+
188
+ - (void)touchesBegan:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
189
+ {
190
+ // super call was moved to interactionsBegan method to keep the
191
+ // original order of calls
192
+ [self interactionsBegan:touches withEvent:event];
193
+ }
194
+
195
+ - (void)touchesMoved:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
196
+ {
197
+ [super touchesMoved:touches withEvent:event];
198
+ [self interactionsMoved:touches withEvent:event];
199
+ }
200
+
201
+ - (void)touchesEnded:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
202
+ {
203
+ [super touchesEnded:touches withEvent:event];
204
+ [self interactionsEnded:touches withEvent:event];
205
+ }
206
+
207
+ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
208
+ {
209
+ [super touchesCancelled:touches withEvent:event];
210
+ [self interactionsCancelled:touches withEvent:event];
211
+ }
212
+
213
+ #endif
214
+
150
215
  - (void)reset
151
216
  {
152
217
  [self triggerAction];
@@ -154,6 +219,7 @@
154
219
  [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(activateAfterLongPress) object:nil];
155
220
  self.enabled = YES;
156
221
  [super reset];
222
+ [_gestureHandler reset];
157
223
  }
158
224
 
159
225
  - (void)updateHasCustomActivationCriteria
@@ -165,7 +231,11 @@
165
231
 
166
232
  - (BOOL)shouldFailUnderCustomCriteria
167
233
  {
234
+ #if TARGET_OS_OSX
235
+ CGPoint trans = [self translationInView:self.view.window.contentView];
236
+ #else
168
237
  CGPoint trans = [self translationInView:self.view.window];
238
+ #endif
169
239
  // Apple docs say that 10 units is the default allowable movement for UILongPressGestureRecognizer
170
240
  if (!isnan(_activateAfterLongPress) && trans.x * trans.x + trans.y * trans.y > 100) {
171
241
  [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(activateAfterLongPress) object:nil];
@@ -189,7 +259,11 @@
189
259
 
190
260
  - (BOOL)shouldActivateUnderCustomCriteria
191
261
  {
262
+ #if TARGET_OS_OSX
263
+ CGPoint trans = [self translationInView:self.view.window.contentView];
264
+ #else
192
265
  CGPoint trans = [self translationInView:self.view.window];
266
+ #endif
193
267
  if (!isnan(_activeOffsetXStart) && trans.x < _activeOffsetXStart) {
194
268
  return YES;
195
269
  }
@@ -248,12 +322,12 @@
248
322
  recognizer.failOffsetYStart = NAN;
249
323
  recognizer.failOffsetYStart = NAN;
250
324
  recognizer.failOffsetYEnd = NAN;
251
- #if !TARGET_OS_TV && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130400
325
+ #if !TARGET_OS_OSX && !TARGET_OS_TV && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130400
252
326
  if (@available(iOS 13.4, *)) {
253
327
  recognizer.allowedScrollTypesMask = 0;
254
328
  }
255
329
  #endif
256
- #if !TARGET_OS_TV
330
+ #if !TARGET_OS_OSX && !TARGET_OS_TV
257
331
  recognizer.minimumNumberOfTouches = 1;
258
332
  recognizer.maximumNumberOfTouches = NSUIntegerMax;
259
333
  #endif
@@ -278,7 +352,7 @@
278
352
  APPLY_FLOAT_PROP(failOffsetYStart);
279
353
  APPLY_FLOAT_PROP(failOffsetYEnd);
280
354
 
281
- #if !TARGET_OS_TV && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130400
355
+ #if !TARGET_OS_OSX && !TARGET_OS_TV && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130400
282
356
  if (@available(iOS 13.4, *)) {
283
357
  bool enableTrackpadTwoFingerGesture = [RCTConvert BOOL:config[@"enableTrackpadTwoFingerGesture"]];
284
358
  if (enableTrackpadTwoFingerGesture) {
@@ -319,6 +393,16 @@
319
393
  return shouldBegin;
320
394
  }
321
395
 
396
+ #if TARGET_OS_OSX
397
+ - (RNGestureHandlerEventExtraData *)eventExtraData:(NSPanGestureRecognizer *)recognizer
398
+ {
399
+ return [RNGestureHandlerEventExtraData forPan:[recognizer locationInView:recognizer.view]
400
+ withAbsolutePosition:[recognizer locationInView:recognizer.view.window.contentView]
401
+ withTranslation:[recognizer translationInView:recognizer.view.window.contentView]
402
+ withVelocity:[recognizer velocityInView:recognizer.view.window.contentView]
403
+ withNumberOfTouches:1];
404
+ }
405
+ #else
322
406
  - (RNGestureHandlerEventExtraData *)eventExtraData:(UIPanGestureRecognizer *)recognizer
323
407
  {
324
408
  return [RNGestureHandlerEventExtraData forPan:[recognizer locationInView:recognizer.view]
@@ -327,5 +411,6 @@
327
411
  withVelocity:[recognizer velocityInView:recognizer.view.window]
328
412
  withNumberOfTouches:recognizer.numberOfTouches];
329
413
  }
414
+ #endif
330
415
 
331
416
  @end
@@ -0,0 +1,162 @@
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
+
15
+ #if TARGET_OS_OSX
16
+ @interface RNBetterPinchRecognizer : NSMagnificationGestureRecognizer
17
+ #else
18
+ @interface RNBetterPinchRecognizer : UIPinchGestureRecognizer
19
+ #endif
20
+
21
+ - (id)initWithGestureHandler:(RNGestureHandler *)gestureHandler;
22
+
23
+ @end
24
+
25
+ @implementation RNBetterPinchRecognizer {
26
+ __weak RNGestureHandler *_gestureHandler;
27
+ }
28
+
29
+ - (id)initWithGestureHandler:(RNGestureHandler *)gestureHandler
30
+ {
31
+ if ((self = [super initWithTarget:self action:@selector(handleGesture:)])) {
32
+ _gestureHandler = gestureHandler;
33
+ }
34
+ return self;
35
+ }
36
+
37
+ - (void)handleGesture:(UIGestureRecognizer *)recognizer
38
+ {
39
+ if (self.state == UIGestureRecognizerStateBegan) {
40
+ #if TARGET_OS_OSX
41
+ self.magnification = 1;
42
+ #else
43
+ self.scale = 1;
44
+ #endif
45
+ }
46
+ [_gestureHandler handleGesture:recognizer];
47
+ }
48
+
49
+ - (void)interactionsBegan:(NSSet *)touches withEvent:(UIEvent *)event
50
+ {
51
+ [_gestureHandler.pointerTracker touchesBegan:touches withEvent:event];
52
+ }
53
+
54
+ - (void)interactionsMoved:(NSSet *)touches withEvent:(UIEvent *)event
55
+ {
56
+ [_gestureHandler.pointerTracker touchesMoved:touches withEvent:event];
57
+ }
58
+
59
+ - (void)interactionsEnded:(NSSet *)touches withEvent:(UIEvent *)event
60
+ {
61
+ [_gestureHandler.pointerTracker touchesEnded:touches withEvent:event];
62
+ }
63
+
64
+ - (void)interactionsCancelled:(NSSet *)touches withEvent:(UIEvent *)event
65
+ {
66
+ [_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
67
+ }
68
+
69
+ #if TARGET_OS_OSX
70
+ - (void)touchesBeganWithEvent:(NSEvent *)event
71
+ {
72
+ [super touchesBeganWithEvent:event];
73
+ [self interactionsBegan:[NSSet setWithObject:event] withEvent:event];
74
+ }
75
+
76
+ - (void)touchesMovedWithEvent:(NSEvent *)event
77
+ {
78
+ [super touchesMovedWithEvent:event];
79
+ [self interactionsMoved:[NSSet setWithObject:event] withEvent:event];
80
+ }
81
+
82
+ - (void)touchesEndedWithEvent:(NSEvent *)event
83
+ {
84
+ [super touchesEndedWithEvent:event];
85
+ [self interactionsEnded:[NSSet setWithObject:event] withEvent:event];
86
+ }
87
+
88
+ - (void)touchesCancelledWithEvent:(NSEvent *)event
89
+ {
90
+ [super touchesCancelledWithEvent:event];
91
+ [self interactionsCancelled:[NSSet setWithObject:event] withEvent:event];
92
+ }
93
+ #else
94
+ - (void)touchesBegan:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
95
+ {
96
+ [super touchesBegan:touches withEvent:event];
97
+ [self interactionsBegan:touches withEvent:event];
98
+ }
99
+
100
+ - (void)touchesMoved:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
101
+ {
102
+ [super touchesMoved:touches withEvent:event];
103
+ [self interactionsMoved:touches withEvent:event];
104
+ }
105
+
106
+ - (void)touchesEnded:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
107
+ {
108
+ [super touchesEnded:touches withEvent:event];
109
+ [self interactionsEnded:touches withEvent:event];
110
+ }
111
+
112
+ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
113
+ {
114
+ [super touchesCancelled:touches withEvent:event];
115
+ [self interactionsCancelled:touches withEvent:event];
116
+ }
117
+ #endif
118
+
119
+ - (void)reset
120
+ {
121
+ [_gestureHandler.pointerTracker reset];
122
+ [super reset];
123
+ [_gestureHandler reset];
124
+ }
125
+
126
+ @end
127
+ #endif
128
+
129
+ @implementation RNPinchGestureHandler
130
+
131
+ - (instancetype)initWithTag:(NSNumber *)tag
132
+ {
133
+ if ((self = [super initWithTag:tag])) {
134
+ #if !TARGET_OS_TV
135
+ _recognizer = [[RNBetterPinchRecognizer alloc] initWithGestureHandler:self];
136
+ #endif
137
+ }
138
+ return self;
139
+ }
140
+
141
+ #if !TARGET_OS_TV
142
+
143
+ #if TARGET_OS_OSX
144
+ - (RNGestureHandlerEventExtraData *)eventExtraData:(NSMagnificationGestureRecognizer *)recognizer
145
+ {
146
+ return [RNGestureHandlerEventExtraData forPinch:recognizer.magnification
147
+ withFocalPoint:[recognizer locationInView:recognizer.view]
148
+ withVelocity:1
149
+ withNumberOfTouches:2];
150
+ }
151
+ #else
152
+ - (RNGestureHandlerEventExtraData *)eventExtraData:(UIPinchGestureRecognizer *)recognizer
153
+ {
154
+ return [RNGestureHandlerEventExtraData forPinch:recognizer.scale
155
+ withFocalPoint:[recognizer locationInView:recognizer.view]
156
+ withVelocity:recognizer.velocity
157
+ withNumberOfTouches:recognizer.numberOfTouches];
158
+ }
159
+ #endif
160
+ #endif // !TARGET_OS_TV
161
+
162
+ @end