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
@@ -9,8 +9,12 @@
9
9
  #import "RNRotationHandler.h"
10
10
 
11
11
  #if !TARGET_OS_TV
12
- @interface RNBetterRotationRecognizer : UIRotationGestureRecognizer
13
12
 
13
+ #if TARGET_OS_OSX
14
+ @interface RNBetterRotationRecognizer : NSRotationGestureRecognizer
15
+ #else
16
+ @interface RNBetterRotationRecognizer : UIRotationGestureRecognizer
17
+ #endif
14
18
  - (id)initWithGestureHandler:(RNGestureHandler *)gestureHandler;
15
19
 
16
20
  @end
@@ -35,34 +39,81 @@
35
39
  [_gestureHandler handleGesture:recognizer];
36
40
  }
37
41
 
38
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
42
+ - (void)interactionsBegan:(NSSet *)touches withEvent:(UIEvent *)event
39
43
  {
40
- [super touchesBegan:touches withEvent:event];
41
44
  [_gestureHandler.pointerTracker touchesBegan:touches withEvent:event];
42
45
  }
43
46
 
44
- - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
47
+ - (void)interactionsMoved:(NSSet *)touches withEvent:(UIEvent *)event
45
48
  {
46
- [super touchesMoved:touches withEvent:event];
47
49
  [_gestureHandler.pointerTracker touchesMoved:touches withEvent:event];
48
50
  }
49
51
 
50
- - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
52
+ - (void)interactionsEnded:(NSSet *)touches withEvent:(UIEvent *)event
51
53
  {
52
- [super touchesEnded:touches withEvent:event];
53
54
  [_gestureHandler.pointerTracker touchesEnded:touches withEvent:event];
54
55
  }
55
56
 
56
- - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
57
+ - (void)interactionsCancelled:(NSSet *)touches withEvent:(UIEvent *)event
57
58
  {
58
- [super touchesCancelled:touches withEvent:event];
59
59
  [_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
60
60
  }
61
61
 
62
+ #if TARGET_OS_OSX
63
+ - (void)touchesBeganWithEvent:(NSEvent *)event
64
+ {
65
+ [super touchesBeganWithEvent:event];
66
+ [self interactionsBegan:[NSSet setWithObject:event] withEvent:event];
67
+ }
68
+
69
+ - (void)touchesMovedWithEvent:(NSEvent *)event
70
+ {
71
+ [super touchesMovedWithEvent:event];
72
+ [self interactionsMoved:[NSSet setWithObject:event] withEvent:event];
73
+ }
74
+
75
+ - (void)touchesEndedWithEvent:(NSEvent *)event
76
+ {
77
+ [super touchesEndedWithEvent:event];
78
+ [self interactionsEnded:[NSSet setWithObject:event] withEvent:event];
79
+ }
80
+
81
+ - (void)touchesCancelledWithEvent:(NSEvent *)event
82
+ {
83
+ [super touchesCancelledWithEvent:event];
84
+ [self interactionsCancelled:[NSSet setWithObject:event] withEvent:event];
85
+ }
86
+ #else
87
+ - (void)touchesBegan:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
88
+ {
89
+ [super touchesBegan:touches withEvent:event];
90
+ [self interactionsBegan:[NSSet setWithObject:event] withEvent:event];
91
+ }
92
+
93
+ - (void)touchesMoved:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
94
+ {
95
+ [super touchesMoved:touches withEvent:event];
96
+ [self interactionsMoved:[NSSet setWithObject:event] withEvent:event];
97
+ }
98
+
99
+ - (void)touchesEnded:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
100
+ {
101
+ [super touchesEnded:touches withEvent:event];
102
+ [self interactionsEnded:[NSSet setWithObject:event] withEvent:event];
103
+ }
104
+
105
+ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
106
+ {
107
+ [super touchesCancelled:touches withEvent:event];
108
+ [self interactionsCancelled:[NSSet setWithObject:event] withEvent:event];
109
+ }
110
+ #endif
111
+
62
112
  - (void)reset
63
113
  {
64
114
  [_gestureHandler.pointerTracker reset];
65
115
  [super reset];
116
+ [_gestureHandler reset];
66
117
  }
67
118
 
68
119
  @end
@@ -81,6 +132,16 @@
81
132
  }
82
133
 
83
134
  #if !TARGET_OS_TV
135
+
136
+ #if TARGET_OS_OSX
137
+ - (RNGestureHandlerEventExtraData *)eventExtraData:(NSRotationGestureRecognizer *)recognizer
138
+ {
139
+ return [RNGestureHandlerEventExtraData forRotation:recognizer.rotation
140
+ withAnchorPoint:[recognizer locationInView:recognizer.view]
141
+ withVelocity:1
142
+ withNumberOfTouches:2];
143
+ }
144
+ #else
84
145
  - (RNGestureHandlerEventExtraData *)eventExtraData:(UIRotationGestureRecognizer *)recognizer
85
146
  {
86
147
  return [RNGestureHandlerEventExtraData forRotation:recognizer.rotation
@@ -89,5 +150,6 @@
89
150
  withNumberOfTouches:recognizer.numberOfTouches];
90
151
  }
91
152
  #endif
153
+ #endif // !TARGET_OS_TV
92
154
 
93
155
  @end
@@ -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,96 @@ 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
+ [super mouseDown:event];
151
+ [self interactionsBegan:[NSSet setWithObject:event] withEvent:event];
152
+ }
153
+
154
+ - (void)rightMouseDown:(NSEvent *)event
155
+ {
156
+ [super rightMouseDown:event];
157
+ [self interactionsBegan:[NSSet setWithObject:event] withEvent:event];
158
+ }
159
+
160
+ - (void)mouseDragged:(NSEvent *)event
161
+ {
162
+ [super mouseDragged:event];
163
+ [self interactionsMoved:[NSSet setWithObject:event] withEvent:event];
164
+ }
165
+
166
+ - (void)rightMouseDragged:(NSEvent *)event
167
+ {
168
+ [super rightMouseDragged:event];
169
+ [self interactionsMoved:[NSSet setWithObject:event] withEvent:event];
170
+ }
171
+
172
+ - (void)mouseUp:(NSEvent *)event
173
+ {
174
+ [super mouseUp:event];
175
+ [self interactionsEnded:[NSSet setWithObject:event] withEvent:event];
176
+ }
177
+
178
+ - (void)rightMouseUp:(NSEvent *)event
179
+ {
180
+ [super rightMouseUp:event];
181
+ [self interactionsEnded:[NSSet setWithObject:event] withEvent:event];
182
+ }
183
+ #else
184
+
185
+ - (void)touchesBegan:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
186
+ {
187
+ [super touchesBegan:touches withEvent:event];
188
+ [self interactionsBegan:[NSSet setWithObject:event] withEvent:event];
189
+ }
190
+
191
+ - (void)touchesMoved:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
192
+ {
193
+ [super touchesMoved:touches withEvent:event];
194
+ [self interactionsMoved:[NSSet setWithObject:event] withEvent:event];
195
+ }
196
+
197
+ - (void)touchesEnded:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
198
+ {
199
+ [super touchesEnded:touches withEvent:event];
200
+ [self interactionsEnded:[NSSet setWithObject:event] withEvent:event];
201
+ }
202
+
203
+ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
204
+ {
205
+ [super touchesCancelled:touches withEvent:event];
206
+ [self interactionsCancelled:[NSSet setWithObject:event] withEvent:event];
207
+ }
208
+
209
+ #endif
210
+
124
211
  - (CGPoint)translationInView
125
212
  {
213
+ #if TARGET_OS_OSX
214
+ CGPoint currentPosition = [self locationInView:self.view.window.contentView];
215
+ #else
126
216
  CGPoint currentPosition = [self locationInView:self.view.window];
217
+ #endif
127
218
  return CGPointMake(currentPosition.x - _initPosition.x, currentPosition.y - _initPosition.y);
128
219
  }
129
220
 
@@ -148,28 +239,6 @@ static const NSTimeInterval defaultMaxDuration = 0.5;
148
239
  return NO;
149
240
  }
150
241
 
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
242
  - (void)reset
174
243
  {
175
244
  if (self.state == UIGestureRecognizerStateFailed) {
@@ -182,6 +251,7 @@ static const NSTimeInterval defaultMaxDuration = 0.5;
182
251
  _maxNumberOfTouches = 0;
183
252
  self.enabled = YES;
184
253
  [super reset];
254
+ [_gestureHandler reset];
185
255
  }
186
256
 
187
257
  @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,3 +1,4 @@
1
+ #import "RNGHUIKit.h"
1
2
  #import "RNGestureHandlerActionType.h"
2
3
  #import "RNGestureHandlerDirection.h"
3
4
  #import "RNGestureHandlerEvents.h"
@@ -6,7 +7,6 @@
6
7
 
7
8
  #import <Foundation/Foundation.h>
8
9
  #import <React/RCTConvert.h>
9
- #import <UIKit/UIKit.h>
10
10
 
11
11
  #define VEC_LEN_SQ(pt) (pt.x * pt.x + pt.y * pt.y)
12
12
  #define TEST_MIN_IF_NOT_NAN(value, limit) \
@@ -44,7 +44,7 @@
44
44
  @protocol RNRootViewGestureRecognizerDelegate <UIGestureRecognizerDelegate>
45
45
 
46
46
  - (void)gestureRecognizer:(nullable UIGestureRecognizer *)gestureRecognizer
47
- didActivateInViewWithTouchHandler:(nullable UIView *)viewWithTouchHandler;
47
+ didActivateInViewWithTouchHandler:(nullable RNGHUIView *)viewWithTouchHandler;
48
48
 
49
49
  @end
50
50
 
@@ -69,7 +69,7 @@
69
69
  @property (nonatomic) BOOL needsPointerData;
70
70
  @property (nonatomic) BOOL manualActivation;
71
71
 
72
- - (void)bindToView:(nonnull UIView *)view;
72
+ - (void)bindToView:(nonnull RNGHUIView *)view;
73
73
  - (void)unbindFromView;
74
74
  - (void)resetConfig NS_REQUIRES_SUPER;
75
75
  - (void)configure:(nullable NSDictionary *)config NS_REQUIRES_SUPER;
@@ -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,11 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
171
176
  self.recognizer.enabled = enabled;
172
177
  }
173
178
 
174
- - (void)bindToView:(UIView *)view
179
+ - (void)bindToView:(RNGHUIView *)view
175
180
  {
181
+ #if !TARGET_OS_OSX
176
182
  view.userInteractionEnabled = YES;
183
+ #endif
177
184
  self.recognizer.delegate = self;
178
185
  [view addGestureRecognizer:self.recognizer];
179
186
 
@@ -190,9 +197,15 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
190
197
 
191
198
  - (RNGestureHandlerEventExtraData *)eventExtraData:(UIGestureRecognizer *)recognizer
192
199
  {
200
+ #if TARGET_OS_OSX
201
+ return [RNGestureHandlerEventExtraData forPosition:[recognizer locationInView:recognizer.view]
202
+ withAbsolutePosition:[recognizer locationInView:recognizer.view.window.contentView]
203
+ withNumberOfTouches:1];
204
+ #else
193
205
  return [RNGestureHandlerEventExtraData forPosition:[recognizer locationInView:recognizer.view]
194
206
  withAbsolutePosition:[recognizer locationInView:recognizer.view.window]
195
207
  withNumberOfTouches:recognizer.numberOfTouches];
208
+ #endif
196
209
  }
197
210
 
198
211
  - (void)handleGesture:(UIGestureRecognizer *)recognizer
@@ -227,6 +240,15 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
227
240
  return;
228
241
  }
229
242
 
243
+ // Recognizers don't respect manually changing their state (that happens when we are activating handler
244
+ // under custom conditions). If we send a custom event in state ACTIVE and the recognizer will later update its
245
+ // state, we will end up sending ACTIVE->BEGAN and BEGAN->ACTIVE chain. To prevent this, we simply detect the first
246
+ // weird state change and stop it (then we don't update _lastState), so the second call ends up without state change
247
+ // and is fine.
248
+ if (state == RNGestureHandlerStateBegan && _lastState == RNGestureHandlerStateActive) {
249
+ return;
250
+ }
251
+
230
252
  if (state == RNGestureHandlerStateActive) {
231
253
  // Generate a unique coalescing-key each time the gesture-handler becomes active. All events will have
232
254
  // the same coalescing-key allowing RCTEventDispatcher to coalesce RNGestureHandlerEvents when events are
@@ -332,7 +354,7 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
332
354
  }
333
355
  }
334
356
 
335
- - (void)bindManualActivationToView:(UIView *)view
357
+ - (void)bindManualActivationToView:(RNGHUIView *)view
336
358
  {
337
359
  if (_manualActivationRecognizer != nil) {
338
360
  [view addGestureRecognizer:_manualActivationRecognizer];
@@ -357,7 +379,7 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
357
379
 
358
380
  // We may try to extract "DummyGestureHandler" in case when "otherGestureRecognizer" belongs to
359
381
  // a native view being wrapped with "NativeViewGestureHandler"
360
- UIView *reactView = recognizer.view;
382
+ RNGHUIView *reactView = recognizer.view;
361
383
  while (reactView != nil && reactView.reactTag == nil) {
362
384
  reactView = reactView.superview;
363
385
  }
@@ -475,7 +497,7 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
475
497
  return YES;
476
498
  }
477
499
 
478
- - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
500
+ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(RNGHUITouch *)touch
479
501
  {
480
502
  // If hitSlop is set we use it to determine if a given gesture recognizer should start processing
481
503
  // touch stream. This only works for negative values of hitSlop as this method won't be triggered
@@ -483,7 +505,11 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
483
505
  // values of hitSlop one should set hitSlop for the underlying view. This limitation is due to the
484
506
  // fact that hitTest method is only available at the level of UIView
485
507
  if (RNGH_HIT_SLOP_IS_SET(_hitSlop)) {
508
+ #if TARGET_OS_OSX
509
+ CGPoint location = [gestureRecognizer.view convertPoint:touch.locationInWindow fromView:nil];
510
+ #else
486
511
  CGPoint location = [touch locationInView:gestureRecognizer.view];
512
+ #endif
487
513
  CGRect hitFrame = RNGHHitSlopInsetRect(gestureRecognizer.view.bounds, _hitSlop);
488
514
  return CGRectContainsPoint(hitFrame, location);
489
515
  }
@@ -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
@@ -10,7 +10,7 @@
10
10
  @interface RNGestureHandlerManager : NSObject
11
11
 
12
12
  - (nonnull instancetype)initWithUIManager:(nonnull RCTUIManager *)uiManager
13
- eventDispatcher:(nonnull RCTEventDispatcher *)eventDispatcher;
13
+ eventDispatcher:(nonnull id<RCTEventDispatcherProtocol>)eventDispatcher;
14
14
 
15
15
  - (void)createGestureHandler:(nonnull NSString *)handlerName
16
16
  tag:(nonnull NSNumber *)handlerTag
@@ -26,7 +26,7 @@
26
26
 
27
27
  - (void)dropAllGestureHandlers;
28
28
 
29
- - (void)handleSetJSResponder:(nonnull NSNumber *)viewTag blockNativeResponder:(nonnull NSNumber *)blockNativeResponder;
29
+ - (void)handleSetJSResponder:(nonnull NSNumber *)viewTag blockNativeResponder:(BOOL)blockNativeResponder;
30
30
 
31
31
  - (void)handleClearJSResponder;
32
32