react-native-gesture-handler 2.4.2 → 2.5.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 (82) hide show
  1. package/README.md +3 -2
  2. package/android/lib/src/main/java/com/swmansion/gesturehandler/GestureHandler.kt +9 -5
  3. package/android/lib/src/main/java/com/swmansion/gesturehandler/GestureHandlerOrchestrator.kt +6 -1
  4. package/android/lib/src/main/java/com/swmansion/gesturehandler/NativeViewGestureHandler.kt +103 -22
  5. package/android/lib/src/main/java/com/swmansion/gesturehandler/PanGestureHandler.kt +29 -2
  6. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt +74 -84
  7. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt +4 -0
  8. package/android/src/main/jni/Android.mk +1 -2
  9. package/android/src/paper/java/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerDelegate.java +12 -9
  10. package/android/src/paper/java/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerInterface.java +1 -0
  11. package/ios/Handlers/RNFlingHandler.m +43 -1
  12. package/ios/Handlers/{RNNativeViewHandler.m → RNNativeViewHandler.mm} +13 -1
  13. package/ios/Handlers/RNPanHandler.m +27 -0
  14. package/ios/RNGestureHandler.h +1 -0
  15. package/ios/RNGestureHandler.m +22 -4
  16. package/ios/RNGestureHandlerManager.mm +10 -2
  17. package/ios/RNGestureHandlerModule.mm +4 -1
  18. package/ios/RNManualActivationRecognizer.m +10 -3
  19. package/ios/RNRootViewGestureRecognizer.m +12 -1
  20. package/lib/commonjs/RNGestureHandlerModule.macos.js +81 -0
  21. package/lib/commonjs/RNGestureHandlerModule.macos.js.map +1 -0
  22. package/lib/commonjs/components/GestureButtons.js.map +1 -1
  23. package/lib/commonjs/components/touchables/GenericTouchable.js +4 -1
  24. package/lib/commonjs/components/touchables/GenericTouchable.js.map +1 -1
  25. package/lib/commonjs/fabric/RNGestureHandlerButtonNativeComponent.js.map +1 -1
  26. package/lib/commonjs/handlers/PanGestureHandler.js +1 -1
  27. package/lib/commonjs/handlers/PanGestureHandler.js.map +1 -1
  28. package/lib/commonjs/handlers/PressabilityDebugView.js +14 -0
  29. package/lib/commonjs/handlers/PressabilityDebugView.js.map +1 -0
  30. package/lib/commonjs/handlers/PressabilityDebugView.web.js +12 -0
  31. package/lib/commonjs/handlers/PressabilityDebugView.web.js.map +1 -0
  32. package/lib/commonjs/handlers/createHandler.js +6 -3
  33. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  34. package/lib/commonjs/handlers/gestures/gestureStateManager.js +13 -9
  35. package/lib/commonjs/handlers/gestures/gestureStateManager.js.map +1 -1
  36. package/lib/commonjs/handlers/gestures/panGesture.js +5 -0
  37. package/lib/commonjs/handlers/gestures/panGesture.js.map +1 -1
  38. package/lib/commonjs/utils.js +6 -3
  39. package/lib/commonjs/utils.js.map +1 -1
  40. package/lib/module/RNGestureHandlerModule.macos.js +57 -0
  41. package/lib/module/RNGestureHandlerModule.macos.js.map +1 -0
  42. package/lib/module/components/GestureButtons.js.map +1 -1
  43. package/lib/module/components/touchables/GenericTouchable.js +4 -1
  44. package/lib/module/components/touchables/GenericTouchable.js.map +1 -1
  45. package/lib/module/fabric/RNGestureHandlerButtonNativeComponent.js.map +1 -1
  46. package/lib/module/handlers/PanGestureHandler.js +1 -1
  47. package/lib/module/handlers/PanGestureHandler.js.map +1 -1
  48. package/lib/module/handlers/PressabilityDebugView.js +3 -0
  49. package/lib/module/handlers/PressabilityDebugView.js.map +1 -0
  50. package/lib/module/handlers/PressabilityDebugView.web.js +5 -0
  51. package/lib/module/handlers/PressabilityDebugView.web.js.map +1 -0
  52. package/lib/module/handlers/createHandler.js +6 -4
  53. package/lib/module/handlers/createHandler.js.map +1 -1
  54. package/lib/module/handlers/gestures/gestureStateManager.js +13 -9
  55. package/lib/module/handlers/gestures/gestureStateManager.js.map +1 -1
  56. package/lib/module/handlers/gestures/panGesture.js +5 -0
  57. package/lib/module/handlers/gestures/panGesture.js.map +1 -1
  58. package/lib/module/utils.js +2 -1
  59. package/lib/module/utils.js.map +1 -1
  60. package/lib/typescript/RNGestureHandlerModule.macos.d.ts +34 -0
  61. package/lib/typescript/RNGestureHandlerModule.web.d.ts +1 -1
  62. package/lib/typescript/components/GestureButtons.d.ts +6 -0
  63. package/lib/typescript/fabric/RNGestureHandlerButtonNativeComponent.d.ts +1 -0
  64. package/lib/typescript/handlers/PanGestureHandler.d.ts +2 -1
  65. package/lib/typescript/handlers/PressabilityDebugView.d.ts +1 -0
  66. package/lib/typescript/handlers/PressabilityDebugView.web.d.ts +1 -0
  67. package/lib/typescript/handlers/gestures/panGesture.d.ts +1 -0
  68. package/lib/typescript/web/NodeManager.d.ts +2 -2
  69. package/package.json +1 -1
  70. package/src/RNGestureHandlerModule.macos.ts +62 -0
  71. package/src/components/GestureButtons.tsx +7 -0
  72. package/src/components/touchables/GenericTouchable.tsx +1 -0
  73. package/src/fabric/RNGestureHandlerButtonNativeComponent.ts +1 -0
  74. package/src/handlers/PanGestureHandler.ts +2 -0
  75. package/src/handlers/PressabilityDebugView.tsx +2 -0
  76. package/src/handlers/PressabilityDebugView.web.tsx +4 -0
  77. package/src/handlers/{createHandler.ts → createHandler.tsx} +7 -6
  78. package/src/handlers/gestures/gestureStateManager.ts +13 -8
  79. package/src/handlers/gestures/panGesture.ts +5 -0
  80. package/src/utils.ts +3 -1
  81. package/ios/RNGestureHandler.xcodeproj/project.xcworkspace/xcuserdata/jakubpiasecki.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  82. package/ios/RNGestureHandler.xcodeproj/xcuserdata/jakubpiasecki.xcuserdatad/xcschemes/xcschememanagement.plist +0 -19
@@ -1,11 +1,11 @@
1
1
  /**
2
- * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
- *
4
- * Do not edit this file as changes may cause incorrect behavior and will be lost
5
- * once the code is regenerated.
6
- *
7
- * @generated by codegen project: GeneratePropsJavaDelegate.js
8
- */
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GeneratePropsJavaDelegate.js
8
+ */
9
9
 
10
10
  package com.facebook.react.viewmanagers;
11
11
 
@@ -23,7 +23,7 @@ public class RNGestureHandlerButtonManagerDelegate<T extends View, U extends Bas
23
23
  public void setProperty(T view, String propName, @Nullable Object value) {
24
24
  switch (propName) {
25
25
  case "exclusive":
26
- mViewManager.setExclusive(view, value == null ? false : (boolean) value);
26
+ mViewManager.setExclusive(view, value == null ? true : (boolean) value);
27
27
  break;
28
28
  case "foreground":
29
29
  mViewManager.setForeground(view, value == null ? false : (boolean) value);
@@ -32,7 +32,7 @@ public class RNGestureHandlerButtonManagerDelegate<T extends View, U extends Bas
32
32
  mViewManager.setBorderless(view, value == null ? false : (boolean) value);
33
33
  break;
34
34
  case "enabled":
35
- mViewManager.setEnabled(view, value == null ? false : (boolean) value);
35
+ mViewManager.setEnabled(view, value == null ? true : (boolean) value);
36
36
  break;
37
37
  case "rippleColor":
38
38
  mViewManager.setRippleColor(view, ColorPropConverter.getColor(value, view.getContext()));
@@ -40,6 +40,9 @@ public class RNGestureHandlerButtonManagerDelegate<T extends View, U extends Bas
40
40
  case "rippleRadius":
41
41
  mViewManager.setRippleRadius(view, value == null ? 0 : ((Double) value).intValue());
42
42
  break;
43
+ case "touchSoundDisabled":
44
+ mViewManager.setTouchSoundDisabled(view, value == null ? false : (boolean) value);
45
+ break;
43
46
  default:
44
47
  super.setProperty(view, propName, value);
45
48
  }
@@ -19,4 +19,5 @@ public interface RNGestureHandlerButtonManagerInterface<T extends View> {
19
19
  void setEnabled(T view, boolean value);
20
20
  void setRippleColor(T view, @Nullable Integer value);
21
21
  void setRippleRadius(T view, int value);
22
+ void setTouchSoundDisabled(T view, boolean value);
22
23
  }
@@ -8,38 +8,54 @@
8
8
 
9
9
  @implementation RNBetterSwipeGestureRecognizer {
10
10
  __weak RNGestureHandler* _gestureHandler;
11
+ CGPoint _lastPoint; // location of the most recently updated touch, relative to the view
12
+ bool _hasBegan; // whether the `BEGAN` event has been sent
11
13
  }
12
14
 
13
15
  - (id)initWithGestureHandler:(RNGestureHandler *)gestureHandler
14
16
  {
15
17
  if ((self = [super initWithTarget:gestureHandler action:@selector(handleGesture:)])) {
16
18
  _gestureHandler = gestureHandler;
19
+ _lastPoint = CGPointZero;
20
+ _hasBegan = NO;
17
21
  }
18
22
  return self;
19
23
  }
20
24
 
21
25
  - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
22
26
  {
27
+ _lastPoint = [[[touches allObjects] objectAtIndex:0] locationInView:_gestureHandler.recognizer.view];
23
28
  [_gestureHandler reset];
24
- [self triggerAction];
25
29
  [super touchesBegan:touches withEvent:event];
30
+
31
+ // self.numberOfTouches doesn't work for this because in case than one finger is required,
32
+ // when holding one finger on the screen and tapping with the second one, numberOfTouches is equal
33
+ // to 2 only for the first tap but 1 for all the following ones
34
+ if (!_hasBegan) {
35
+ [self triggerAction];
36
+ _hasBegan = YES;
37
+ }
38
+
26
39
  [_gestureHandler.pointerTracker touchesBegan:touches withEvent:event];
27
40
  }
28
41
 
29
42
  - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
30
43
  {
44
+ _lastPoint = [[[touches allObjects] objectAtIndex:0] locationInView:_gestureHandler.recognizer.view];
31
45
  [super touchesMoved:touches withEvent:event];
32
46
  [_gestureHandler.pointerTracker touchesMoved:touches withEvent:event];
33
47
  }
34
48
 
35
49
  - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
36
50
  {
51
+ _lastPoint = [[[touches allObjects] objectAtIndex:0] locationInView:_gestureHandler.recognizer.view];
37
52
  [super touchesEnded:touches withEvent:event];
38
53
  [_gestureHandler.pointerTracker touchesEnded:touches withEvent:event];
39
54
  }
40
55
 
41
56
  - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
42
57
  {
58
+ _lastPoint = [[[touches allObjects] objectAtIndex:0] locationInView:_gestureHandler.recognizer.view];
43
59
  [super touchesCancelled:touches withEvent:event];
44
60
  [_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
45
61
  }
@@ -53,9 +69,17 @@
53
69
  {
54
70
  [self triggerAction];
55
71
  [_gestureHandler.pointerTracker reset];
72
+ _hasBegan = NO;
56
73
  [super reset];
57
74
  }
58
75
 
76
+ - (CGPoint)getLastLocation {
77
+ // I think keeping the location of only one touch is enough since it would be used to determine the direction
78
+ // of the movement, and if it's wrong the recognizer fails anyway.
79
+ // In case the location of all touches is required, touch events are the way to go
80
+ return _lastPoint;
81
+ }
82
+
59
83
  @end
60
84
 
61
85
  @implementation RNFlingGestureHandler
@@ -104,5 +128,23 @@
104
128
  return shouldBegin;
105
129
  }
106
130
 
131
+ - (RNGestureHandlerEventExtraData *)eventExtraData:(id)_recognizer
132
+ {
133
+ // For some weird reason [recognizer locationInView:recognizer.view.window] returns (0, 0).
134
+ // To calculate the correct absolute position, first calculate the absolute position of the
135
+ // view inside the root view controller (https://stackoverflow.com/a/7448573) and then
136
+ // add the relative touch position to it.
137
+
138
+ RNBetterSwipeGestureRecognizer *recognizer = (RNBetterSwipeGestureRecognizer *)_recognizer;
139
+
140
+ CGPoint viewAbsolutePosition = [recognizer.view convertPoint:recognizer.view.bounds.origin toView:[UIApplication sharedApplication].keyWindow.rootViewController.view];
141
+ CGPoint locationInView = [recognizer getLastLocation];
142
+
143
+ return [RNGestureHandlerEventExtraData
144
+ forPosition:locationInView
145
+ withAbsolutePosition:CGPointMake(viewAbsolutePosition.x + locationInView.x, viewAbsolutePosition.y + locationInView.y)
146
+ withNumberOfTouches:recognizer.numberOfTouches];
147
+ }
148
+
107
149
  @end
108
150
 
@@ -11,9 +11,14 @@
11
11
  #import <UIKit/UIGestureRecognizerSubclass.h>
12
12
 
13
13
  #import <React/RCTConvert.h>
14
- #import <React/RCTScrollView.h>
15
14
  #import <React/UIView+React.h>
16
15
 
16
+ #ifdef RN_FABRIC_ENABLED
17
+ #import <React/RCTScrollViewComponentView.h>
18
+ #else
19
+ #import <React/RCTScrollView.h>
20
+ #endif // RN_FABRIC_ENABLED
21
+
17
22
  #pragma mark RNDummyGestureRecognizer
18
23
 
19
24
  @implementation RNDummyGestureRecognizer {
@@ -101,6 +106,12 @@
101
106
  // We can restore default scrollview behaviour to delay touches to scrollview's children
102
107
  // because gesture handler system can handle cancellation of scroll recognizer when JS responder
103
108
  // is set
109
+ #ifdef RN_FABRIC_ENABLED
110
+ if ([view isKindOfClass:[RCTScrollViewComponentView class]]) {
111
+ UIScrollView *scrollView = ((RCTScrollViewComponentView *)view).scrollView;
112
+ scrollView.delaysContentTouches = YES;
113
+ }
114
+ #else
104
115
  if ([view isKindOfClass:[RCTScrollView class]]) {
105
116
  // This part of the code is coupled with RN implementation of ScrollView native wrapper and
106
117
  // we expect for RCTScrollView component to contain a subclass of UIScrollview as the only
@@ -108,6 +119,7 @@
108
119
  UIScrollView *scrollView = [view.subviews objectAtIndex:0];
109
120
  scrollView.delaysContentTouches = YES;
110
121
  }
122
+ #endif // RN_FABRIC_ENABLED
111
123
  }
112
124
 
113
125
  - (void)handleTouchDown:(UIView *)sender forEvent:(UIEvent *)event
@@ -24,6 +24,7 @@
24
24
  @property (nonatomic) CGFloat activeOffsetYEnd;
25
25
  @property (nonatomic) CGFloat failOffsetYStart;
26
26
  @property (nonatomic) CGFloat failOffsetYEnd;
27
+ @property (nonatomic) CGFloat activateAfterLongPress;
27
28
 
28
29
 
29
30
  - (id)initWithGestureHandler:(RNGestureHandler*)gestureHandler;
@@ -53,6 +54,7 @@
53
54
  _activeOffsetYEnd = NAN;
54
55
  _failOffsetYStart = NAN;
55
56
  _failOffsetYEnd = NAN;
57
+ _activateAfterLongPress = NAN;
56
58
  _hasCustomActivationCriteria = NO;
57
59
  #if !TARGET_OS_TV
58
60
  _realMinimumNumberOfTouches = self.minimumNumberOfTouches;
@@ -71,6 +73,13 @@
71
73
  _realMinimumNumberOfTouches = minimumNumberOfTouches;
72
74
  }
73
75
 
76
+ - (void)activateAfterLongPress
77
+ {
78
+ self.state = UIGestureRecognizerStateBegan;
79
+ // Send event in ACTIVE state because UIGestureRecognizerStateBegan is mapped to RNGestureHandlerStateBegan
80
+ [_gestureHandler handleGesture:self inState:RNGestureHandlerStateActive];
81
+ }
82
+
74
83
  - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
75
84
  {
76
85
  if ([self numberOfTouches] == 0) {
@@ -89,6 +98,10 @@
89
98
  [super touchesBegan:touches withEvent:event];
90
99
  [self triggerAction];
91
100
  [_gestureHandler.pointerTracker touchesBegan:touches withEvent:event];
101
+
102
+ if (!isnan(_activateAfterLongPress)) {
103
+ [self performSelector:@selector(activateAfterLongPress) withObject:nil afterDelay:_activateAfterLongPress];
104
+ }
92
105
  }
93
106
 
94
107
  - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
@@ -140,6 +153,7 @@
140
153
  {
141
154
  [self triggerAction];
142
155
  [_gestureHandler.pointerTracker reset];
156
+ [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(activateAfterLongPress) object:nil];
143
157
  self.enabled = YES;
144
158
  [super reset];
145
159
  }
@@ -155,6 +169,12 @@
155
169
  - (BOOL)shouldFailUnderCustomCriteria
156
170
  {
157
171
  CGPoint trans = [self translationInView:self.view.window];
172
+ // Apple docs say that 10 units is the default allowable movement for UILongPressGestureRecognizer
173
+ if (!isnan(_activateAfterLongPress) && trans.x * trans.x + trans.y * trans.y > 100) {
174
+ [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(activateAfterLongPress) object:nil];
175
+ return YES;
176
+ }
177
+
158
178
  if (!isnan(_failOffsetXStart) && trans.x < _failOffsetXStart) {
159
179
  return YES;
160
180
  }
@@ -242,6 +262,7 @@
242
262
  #endif
243
263
  recognizer.minDistSq = NAN;
244
264
  recognizer.minVelocitySq = NAN;
265
+ recognizer.activateAfterLongPress = NAN;
245
266
  }
246
267
 
247
268
  - (void)configure:(NSDictionary *)config
@@ -283,6 +304,12 @@
283
304
  CGFloat velocity = [RCTConvert CGFloat:prop];
284
305
  recognizer.minVelocitySq = velocity * velocity;
285
306
  }
307
+
308
+ prop = config[@"activateAfterLongPress"];
309
+ if (prop != nil) {
310
+ recognizer.activateAfterLongPress = [RCTConvert CGFloat:prop] / 1000.0;
311
+ recognizer.minDistSq = MAX(100, recognizer.minDistSq);
312
+ }
286
313
  [recognizer updateHasCustomActivationCriteria];
287
314
  }
288
315
 
@@ -65,6 +65,7 @@ if (value != nil) { recognizer.prop = [RCTConvert type:value]; }\
65
65
  - (void)resetConfig NS_REQUIRES_SUPER;
66
66
  - (void)configure:(nullable NSDictionary *)config NS_REQUIRES_SUPER;
67
67
  - (void)handleGesture:(nonnull id)recognizer;
68
+ - (void)handleGesture:(nonnull id)recognizer inState:(RNGestureHandlerState)state;
68
69
  - (BOOL)containsPointInView;
69
70
  - (RNGestureHandlerState)state;
70
71
  - (nullable RNGestureHandlerEventExtraData *)eventExtraData:(nonnull id)recognizer;
@@ -203,6 +203,12 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
203
203
  }
204
204
 
205
205
  _state = [self recognizerState];
206
+ [self handleGesture:recognizer inState:_state];
207
+ }
208
+
209
+ - (void)handleGesture:(UIGestureRecognizer *)recognizer inState:(RNGestureHandlerState)state
210
+ {
211
+ _state = state;
206
212
  RNGestureHandlerEventExtraData *eventData = [self eventExtraData:recognizer];
207
213
  [self sendEventsInState:self.state forViewWithTag:recognizer.view.reactTag withExtraData:eventData];
208
214
  }
@@ -212,6 +218,11 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
212
218
  withExtraData:(RNGestureHandlerEventExtraData *)extraData
213
219
  {
214
220
  if (state != _lastState) {
221
+ // don't send change events from END to FAILED or CANCELLED, this may happen when gesture is ended in `onTouchesUp` callback
222
+ if (_lastState == RNGestureHandlerStateEnd && (state == RNGestureHandlerStateFailed || state == RNGestureHandlerStateCancelled)) {
223
+ return;
224
+ }
225
+
215
226
  if (state == RNGestureHandlerStateActive) {
216
227
  // Generate a unique coalescing-key each time the gesture-handler becomes active. All events will have
217
228
  // the same coalescing-key allowing RCTEventDispatcher to coalesce RNGestureHandlerEvents when events are
@@ -219,7 +230,7 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
219
230
  static uint16_t nextEventCoalescingKey = 0;
220
231
  self->_eventCoalescingKey = nextEventCoalescingKey++;
221
232
 
222
- } else if (state == RNGestureHandlerStateEnd && _lastState != RNGestureHandlerStateActive) {
233
+ } else if (state == RNGestureHandlerStateEnd && _lastState != RNGestureHandlerStateActive && !_manualActivation) {
223
234
  id event = [[RNGestureHandlerStateChange alloc] initWithReactTag:reactTag
224
235
  handlerTag:_tag
225
236
  state:RNGestureHandlerStateActive
@@ -390,14 +401,21 @@ shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherG
390
401
  if (_recognizer.state == UIGestureRecognizerStateBegan && _recognizer.state == UIGestureRecognizerStatePossible) {
391
402
  return YES;
392
403
  }
393
- if ([_simultaneousHandlers count]) {
394
- RNGestureHandler *handler = [RNGestureHandler findGestureHandlerByRecognizer:otherGestureRecognizer];
395
- if (handler != nil) {
404
+
405
+ RNGestureHandler *handler = [RNGestureHandler findGestureHandlerByRecognizer:otherGestureRecognizer];
406
+ if (handler != nil) {
407
+ if ([_simultaneousHandlers count]) {
396
408
  for (NSNumber *handlerTag in _simultaneousHandlers) {
397
409
  if ([handler.tag isEqual:handlerTag]) {
398
410
  return YES;
399
411
  }
400
412
  }
413
+ } else if (handler->_simultaneousHandlers) {
414
+ for (NSNumber *handlerTag in handler->_simultaneousHandlers) {
415
+ if ([self.tag isEqual:handlerTag]) {
416
+ return YES;
417
+ }
418
+ }
401
419
  }
402
420
  }
403
421
  return NO;
@@ -4,7 +4,6 @@
4
4
  #import <React/RCTViewManager.h>
5
5
  #import <React/RCTComponent.h>
6
6
  #import <React/RCTRootView.h>
7
- #import <React/RCTTouchHandler.h>
8
7
  #import <React/RCTUIManager.h>
9
8
  #import <React/RCTEventDispatcher.h>
10
9
 
@@ -22,6 +21,9 @@
22
21
 
23
22
  #ifdef RN_FABRIC_ENABLED
24
23
  #import <React/RCTViewComponentView.h>
24
+ #import <React/RCTSurfaceTouchHandler.h>
25
+ #else
26
+ #import <React/RCTTouchHandler.h>
25
27
  #endif // RN_FABRIC_ENABLED
26
28
 
27
29
  #import "Handlers/RNPanHandler.h"
@@ -211,8 +213,14 @@
211
213
  // Once the upstream fix lands the line below along with this comment can be removed
212
214
  if ([gestureRecognizer.view isKindOfClass:[UIScrollView class]]) return;
213
215
 
216
+ #ifdef RN_FABRIC_ENABLED
217
+ RCTSurfaceTouchHandler *touchHandler = [viewWithTouchHandler performSelector:@selector(touchHandler)];
218
+ #else
214
219
  RCTTouchHandler *touchHandler = [viewWithTouchHandler performSelector:@selector(touchHandler)];
215
- [touchHandler cancel];
220
+ #endif
221
+ [touchHandler setEnabled:NO];
222
+ [touchHandler setEnabled:YES];
223
+
216
224
  }
217
225
 
218
226
  #pragma mark Events
@@ -60,7 +60,10 @@ RCT_EXPORT_MODULE()
60
60
 
61
61
  - (void)invalidate
62
62
  {
63
- [_manager dropAllGestureHandlers];
63
+ RNGestureHandlerManager *handlerManager = _manager;
64
+ dispatch_async(dispatch_get_main_queue(), ^{
65
+ [handlerManager dropAllGestureHandlers];
66
+ });
64
67
 
65
68
  _manager = nil;
66
69
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  - (id)initWithGestureHandler:(RNGestureHandler *)gestureHandler
10
10
  {
11
- if ((self = [super initWithTarget:self action:nil])) {
11
+ if ((self = [super initWithTarget:self action:@selector(handleGesture:)])) {
12
12
  _handler = gestureHandler;
13
13
  self.delegate = self;
14
14
  _activePointers = 0;
@@ -16,6 +16,14 @@
16
16
  return self;
17
17
  }
18
18
 
19
+ - (void)handleGesture:(UIGestureRecognizer *)recognizer
20
+ {
21
+ if (recognizer.state == UIGestureRecognizerStateBegan) {
22
+ self.state = UIGestureRecognizerStateEnded;
23
+ [self reset];
24
+ }
25
+ }
26
+
19
27
  - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
20
28
  {
21
29
  [super touchesBegan:touches withEvent:event];
@@ -35,8 +43,7 @@
35
43
  _activePointers -= touches.count;
36
44
 
37
45
  if (_activePointers == 0) {
38
- [self fail];
39
- [self reset];
46
+ self.state = UIGestureRecognizerStateBegan;
40
47
  }
41
48
  }
42
49
 
@@ -10,7 +10,12 @@
10
10
 
11
11
  #import <UIKit/UIGestureRecognizerSubclass.h>
12
12
 
13
+ #ifdef RN_FABRIC_ENABLED
14
+ #import <React/RCTSurfaceTouchHandler.h>
15
+ #else
13
16
  #import <React/RCTTouchHandler.h>
17
+ #endif // RN_FABRIC_ENABLED
18
+
14
19
 
15
20
  @implementation RNRootViewGestureRecognizer
16
21
  {
@@ -43,7 +48,13 @@
43
48
 
44
49
  - (BOOL)canPreventGestureRecognizer:(UIGestureRecognizer *)preventedGestureRecognizer
45
50
  {
46
- return ![preventedGestureRecognizer isKindOfClass:[RCTTouchHandler class]];
51
+ return ![preventedGestureRecognizer isKindOfClass:[
52
+ #ifdef RN_FABRIC_ENABLED
53
+ RCTSurfaceTouchHandler
54
+ #else
55
+ RCTTouchHandler
56
+ #endif
57
+ class]];
47
58
  }
48
59
 
49
60
  - (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer *)preventingGestureRecognizer
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.Gestures = void 0;
7
+
8
+ var _constants = require("./web/constants");
9
+
10
+ var _FlingGestureHandler = _interopRequireDefault(require("./web/FlingGestureHandler"));
11
+
12
+ var _LongPressGestureHandler = _interopRequireDefault(require("./web/LongPressGestureHandler"));
13
+
14
+ var _NativeViewGestureHandler = _interopRequireDefault(require("./web/NativeViewGestureHandler"));
15
+
16
+ var NodeManager = _interopRequireWildcard(require("./web/NodeManager"));
17
+
18
+ var _PanGestureHandler = _interopRequireDefault(require("./web/PanGestureHandler"));
19
+
20
+ var _PinchGestureHandler = _interopRequireDefault(require("./web/PinchGestureHandler"));
21
+
22
+ var _RotationGestureHandler = _interopRequireDefault(require("./web/RotationGestureHandler"));
23
+
24
+ var _TapGestureHandler = _interopRequireDefault(require("./web/TapGestureHandler"));
25
+
26
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
27
+
28
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
+
30
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
+
32
+ const Gestures = {
33
+ PanGestureHandler: _PanGestureHandler.default,
34
+ RotationGestureHandler: _RotationGestureHandler.default,
35
+ PinchGestureHandler: _PinchGestureHandler.default,
36
+ TapGestureHandler: _TapGestureHandler.default,
37
+ NativeViewGestureHandler: _NativeViewGestureHandler.default,
38
+ LongPressGestureHandler: _LongPressGestureHandler.default,
39
+ FlingGestureHandler: _FlingGestureHandler.default // ForceTouchGestureHandler,
40
+
41
+ };
42
+ exports.Gestures = Gestures;
43
+ var _default = {
44
+ Direction: _constants.Direction,
45
+
46
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
47
+ handleSetJSResponder() {},
48
+
49
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
50
+ handleClearJSResponder() {},
51
+
52
+ createGestureHandler(handlerName, handlerTag, config) {
53
+ //TODO(TS) extends config
54
+ if (!(handlerName in Gestures)) throw new Error(`react-native-gesture-handler: ${handlerName} is not supported on macos.`);
55
+ const GestureClass = Gestures[handlerName];
56
+ NodeManager.createGestureHandler(handlerTag, new GestureClass());
57
+ this.updateGestureHandler(handlerTag, config);
58
+ },
59
+
60
+ attachGestureHandler(handlerTag, newView, _actionType, propsRef) {
61
+ NodeManager.getHandler(handlerTag).setView(newView, propsRef);
62
+ },
63
+
64
+ updateGestureHandler(handlerTag, newConfig) {
65
+ NodeManager.getHandler(handlerTag).updateGestureConfig(newConfig);
66
+ },
67
+
68
+ getGestureHandlerNode(handlerTag) {
69
+ return NodeManager.getHandler(handlerTag);
70
+ },
71
+
72
+ dropGestureHandler(handlerTag) {
73
+ NodeManager.dropGestureHandler(handlerTag);
74
+ },
75
+
76
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
77
+ flushOperations() {}
78
+
79
+ };
80
+ exports.default = _default;
81
+ //# sourceMappingURL=RNGestureHandlerModule.macos.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["RNGestureHandlerModule.macos.ts"],"names":["Gestures","PanGestureHandler","RotationGestureHandler","PinchGestureHandler","TapGestureHandler","NativeViewGestureHandler","LongPressGestureHandler","FlingGestureHandler","Direction","handleSetJSResponder","handleClearJSResponder","createGestureHandler","handlerName","handlerTag","config","Error","GestureClass","NodeManager","updateGestureHandler","attachGestureHandler","newView","_actionType","propsRef","getHandler","setView","newConfig","updateGestureConfig","getGestureHandlerNode","dropGestureHandler","flushOperations"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEO,MAAMA,QAAQ,GAAG;AACtBC,EAA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,CAAuBV,UAAvB,CAAP;AACD,GAjCY;;AAkCbe,EAAAA,kBAAkB,CAACf,UAAD,EAAqB;AACrCI,IAAAA,WAAW,CAACW,kBAAZ,CAA+Bf,UAA/B;AACD,GApCY;;AAqCb;AACAgB,EAAAA,eAAe,GAAG,CAAE;;AAtCP,C","sourcesContent":["import { ActionType } from './ActionType';\nimport { Direction } from './web/constants';\nimport FlingGestureHandler from './web/FlingGestureHandler';\nimport LongPressGestureHandler from './web/LongPressGestureHandler';\nimport NativeViewGestureHandler from './web/NativeViewGestureHandler';\nimport * as NodeManager from './web/NodeManager';\nimport PanGestureHandler from './web/PanGestureHandler';\nimport PinchGestureHandler from './web/PinchGestureHandler';\nimport RotationGestureHandler from './web/RotationGestureHandler';\nimport TapGestureHandler from './web/TapGestureHandler';\n\nexport const Gestures = {\n PanGestureHandler,\n RotationGestureHandler,\n PinchGestureHandler,\n TapGestureHandler,\n NativeViewGestureHandler,\n LongPressGestureHandler,\n FlingGestureHandler,\n // ForceTouchGestureHandler,\n};\n\nexport default {\n Direction,\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n handleSetJSResponder() {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n handleClearJSResponder() {},\n createGestureHandler<T>(\n handlerName: keyof typeof Gestures,\n handlerTag: number,\n config: T\n ) {\n //TODO(TS) extends config\n if (!(handlerName in Gestures))\n throw new Error(\n `react-native-gesture-handler: ${handlerName} is not supported on macos.`\n );\n const GestureClass = Gestures[handlerName];\n NodeManager.createGestureHandler(handlerTag, new GestureClass());\n this.updateGestureHandler(handlerTag, config);\n },\n attachGestureHandler(\n handlerTag: number,\n newView: number,\n _actionType: ActionType,\n propsRef: React.RefObject<unknown>\n ) {\n NodeManager.getHandler(handlerTag).setView(newView, propsRef);\n },\n updateGestureHandler(handlerTag: number, newConfig: any) {\n NodeManager.getHandler(handlerTag).updateGestureConfig(newConfig);\n },\n getGestureHandlerNode(handlerTag: number) {\n return NodeManager.getHandler(handlerTag);\n },\n dropGestureHandler(handlerTag: number) {\n NodeManager.dropGestureHandler(handlerTag);\n },\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n flushOperations() {},\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["GestureButtons.tsx"],"names":["RawButton","GestureHandlerButton","shouldCancelWhenOutside","shouldActivateOnStart","BaseButton","React","Component","constructor","props","nativeEvent","state","oldState","pointerInside","active","State","ACTIVE","lastActive","onActiveStateChange","CANCELLED","onPress","e","onHandlerStateChange","handleEvent","onGestureEvent","render","rippleColor","rest","AnimatedBaseButton","Animated","createAnimatedComponent","btnStyles","StyleSheet","create","underlay","position","left","right","bottom","top","RectButton","Platform","OS","opacity","setValue","activeOpacity","Value","children","style","resolvedStyle","flatten","backgroundColor","underlayColor","borderRadius","borderTopLeftRadius","borderTopRightRadius","borderBottomLeftRadius","borderBottomRightRadius","BorderlessButton","borderless"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AASA;;AACA;;AACA;;;;;;;;;;;;AAwFO,MAAMA,SAAS,GAAG,kCAAoBC,6BAApB,EAA0C;AACjEC,EAAAA,uBAAuB,EAAE,KADwC;AAEjEC,EAAAA,qBAAqB,EAAE;AAF0C,CAA1C,CAAlB;;;AAKA,MAAMC,UAAN,SAAyBC,KAAK,CAACC,SAA/B,CAA0D;AAG/DC,EAAAA,WAAW,CAACC,KAAD,EAAyB;AAClC,UAAMA,KAAN;;AADkC;;AAAA,yCAKd,CAAC;AACrBC,MAAAA;AADqB,KAAD,KAE0C;AAC9D,YAAM;AAAEC,QAAAA,KAAF;AAASC,QAAAA,QAAT;AAAmBC,QAAAA;AAAnB,UAAqCH,WAA3C;AACA,YAAMI,MAAM,GAAGD,aAAa,IAAIF,KAAK,KAAKI,aAAMC,MAAhD;;AAEA,UAAIF,MAAM,KAAK,KAAKG,UAAhB,IAA8B,KAAKR,KAAL,CAAWS,mBAA7C,EAAkE;AAChE,aAAKT,KAAL,CAAWS,mBAAX,CAA+BJ,MAA/B;AACD;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AApDP,U,kBACW;AACpBK,EAAAA,aAAa,EAAE,KADK;AAEpBO,EAAAA,aAAa,EAAE;AAFK,C;;AAkDjB,MAAMM,gBAAN,SAA+BpD,KAAK,CAACC,SAArC,CAAsE;AAQ3EC,EAAAA,WAAW,CAACC,KAAD,EAA+B;AACxC,UAAMA,KAAN;;AADwC;;AAAA,iDAKXK,MAAD,IAAqB;AAAA;;AACjD,UAAI2B,sBAASC,EAAT,KAAgB,SAApB,EAA+B;AAC7B,aAAKC,OAAL,CAAaC,QAAb,CAAsB9B,MAAM,GAAG,KAAKL,KAAL,CAAWoC,aAAd,GAA+B,CAA3D;AACD;;AAED,qDAAKpC,KAAL,EAAWS,mBAAX,qGAAiCJ,MAAjC;AACD,KAXyC;;AAExC,SAAK6B,OAAL,GAAe,IAAId,sBAASiB,KAAb,CAAmB,CAAnB,CAAf;AACD;;AAUDrB,EAAAA,MAAM,GAAG;AACP,UAAM;AAAEsB,MAAAA,QAAF;AAAYC,MAAAA,KAAZ;AAAmB,SAAGrB;AAAtB,QAA+B,KAAKlB,KAA1C;AAEA,wBACE,oBAAC,kBAAD,eACMkB,IADN;AAEE,MAAA,mBAAmB,EAAE,KAAKT,mBAF5B;AAGE,MAAA,KAAK,EAAE,CAAC8B,KAAD,EAAQP,sBAASC,EAAT,KAAgB,KAAhB,IAAyB;AAAEC,QAAAA,OAAO,EAAE,KAAKA;AAAhB,OAAjC;AAHT,QAIGI,QAJH,CADF;AAQD;;AAhC0E;;;;gBAAhEW,gB,kBACW;AACpBb,EAAAA,aAAa,EAAE,GADK;AAEpBc,EAAAA,UAAU,EAAE;AAFQ,C","sourcesContent":["import * as React from 'react';\nimport {\n Animated,\n Platform,\n processColor,\n StyleSheet,\n StyleProp,\n ViewStyle,\n} from 'react-native';\n\nimport createNativeWrapper from '../handlers/createNativeWrapper';\nimport GestureHandlerButton from './GestureHandlerButton';\nimport { State } from '../State';\n\nimport {\n GestureEvent,\n HandlerStateChangeEvent,\n} from '../handlers/gestureHandlerCommon';\nimport {\n NativeViewGestureHandlerPayload,\n NativeViewGestureHandlerProps,\n} from '../handlers/NativeViewGestureHandler';\n\nexport interface RawButtonProps extends NativeViewGestureHandlerProps {\n /**\n * Defines if more than one button could be pressed simultaneously. By default\n * set true.\n */\n exclusive?: boolean;\n // TODO: we should transform props in `createNativeWrapper`\n\n /**\n * Android only.\n *\n * Defines color of native ripple animation used since API level 21.\n */\n rippleColor?: any; // it was present in BaseButtonProps before but is used here in code\n\n /**\n * Android only.\n *\n * Defines radius of native ripple animation used since API level 21.\n */\n rippleRadius?: number | null;\n\n /**\n * Android only.\n *\n * Set this to true if you want the ripple animation to render outside the view bounds.\n */\n borderless?: boolean;\n\n /**\n * Android only.\n *\n * Defines whether the ripple animation should be drawn on the foreground of the view.\n */\n foreground?: boolean;\n}\n\nexport interface BaseButtonProps extends RawButtonProps {\n /**\n * Called when the button gets pressed (analogous to `onPress` in\n * `TouchableHighlight` from RN core).\n */\n onPress?: (pointerInside: boolean) => void;\n\n /**\n * Called when button changes from inactive to active and vice versa. It\n * passes active state as a boolean variable as a first parameter for that\n * method.\n */\n onActiveStateChange?: (active: boolean) => void;\n style?: StyleProp<ViewStyle>;\n testID?: string;\n}\n\nexport interface RectButtonProps extends BaseButtonProps {\n /**\n * Background color that will be dimmed when button is in active state.\n */\n underlayColor?: string;\n\n /**\n * iOS only.\n *\n * Opacity applied to the underlay when button is in active state.\n */\n activeOpacity?: number;\n}\n\nexport interface BorderlessButtonProps extends BaseButtonProps {\n /**\n * iOS only.\n *\n * Opacity applied to the button when it is in an active state.\n */\n activeOpacity?: number;\n}\n\nexport const RawButton = createNativeWrapper(GestureHandlerButton, {\n shouldCancelWhenOutside: false,\n shouldActivateOnStart: false,\n});\n\nexport class BaseButton extends React.Component<BaseButtonProps> {\n private lastActive: boolean;\n\n constructor(props: BaseButtonProps) {\n super(props);\n this.lastActive = false;\n }\n\n private handleEvent = ({\n nativeEvent,\n }: HandlerStateChangeEvent<NativeViewGestureHandlerPayload>) => {\n const { state, oldState, pointerInside } = nativeEvent;\n const active = pointerInside && state === State.ACTIVE;\n\n if (active !== this.lastActive && this.props.onActiveStateChange) {\n this.props.onActiveStateChange(active);\n }\n\n if (\n oldState === State.ACTIVE &&\n state !== State.CANCELLED &&\n this.lastActive &&\n this.props.onPress\n ) {\n this.props.onPress(active);\n }\n\n this.lastActive = active;\n };\n\n // Normally, the parent would execute it's handler first, then forward the\n // event to listeners. However, here our handler is virtually only forwarding\n // events to listeners, so we reverse the order to keep the proper order of\n // the callbacks (from \"raw\" ones to \"processed\").\n private onHandlerStateChange = (\n e: HandlerStateChangeEvent<NativeViewGestureHandlerPayload>\n ) => {\n this.props.onHandlerStateChange?.(e);\n this.handleEvent(e);\n };\n\n private onGestureEvent = (\n e: GestureEvent<NativeViewGestureHandlerPayload>\n ) => {\n this.props.onGestureEvent?.(e);\n this.handleEvent(\n e as HandlerStateChangeEvent<NativeViewGestureHandlerPayload>\n ); // TODO: maybe it is not correct\n };\n\n render() {\n const { rippleColor, ...rest } = this.props;\n\n return (\n <RawButton\n rippleColor={processColor(rippleColor)}\n {...rest}\n onGestureEvent={this.onGestureEvent}\n onHandlerStateChange={this.onHandlerStateChange}\n />\n );\n }\n}\n\nconst AnimatedBaseButton = Animated.createAnimatedComponent(BaseButton);\n\nconst btnStyles = StyleSheet.create({\n underlay: {\n position: 'absolute',\n left: 0,\n right: 0,\n bottom: 0,\n top: 0,\n },\n});\n\nexport class RectButton extends React.Component<RectButtonProps> {\n static defaultProps = {\n activeOpacity: 0.105,\n underlayColor: 'black',\n };\n\n private opacity: Animated.Value;\n\n constructor(props: RectButtonProps) {\n super(props);\n this.opacity = new Animated.Value(0);\n }\n\n private onActiveStateChange = (active: boolean) => {\n if (Platform.OS !== 'android') {\n this.opacity.setValue(active ? this.props.activeOpacity! : 0);\n }\n\n this.props.onActiveStateChange?.(active);\n };\n\n render() {\n const { children, style, ...rest } = this.props;\n\n const resolvedStyle = StyleSheet.flatten(style ?? {});\n\n return (\n <BaseButton\n {...rest}\n style={resolvedStyle}\n onActiveStateChange={this.onActiveStateChange}>\n <Animated.View\n style={[\n btnStyles.underlay,\n {\n opacity: this.opacity,\n backgroundColor: this.props.underlayColor,\n borderRadius: resolvedStyle.borderRadius,\n borderTopLeftRadius: resolvedStyle.borderTopLeftRadius,\n borderTopRightRadius: resolvedStyle.borderTopRightRadius,\n borderBottomLeftRadius: resolvedStyle.borderBottomLeftRadius,\n borderBottomRightRadius: resolvedStyle.borderBottomRightRadius,\n },\n ]}\n />\n {children}\n </BaseButton>\n );\n }\n}\n\nexport class BorderlessButton extends React.Component<BorderlessButtonProps> {\n static defaultProps = {\n activeOpacity: 0.3,\n borderless: true,\n };\n\n private opacity: Animated.Value;\n\n constructor(props: BorderlessButtonProps) {\n super(props);\n this.opacity = new Animated.Value(1);\n }\n\n private onActiveStateChange = (active: boolean) => {\n if (Platform.OS !== 'android') {\n this.opacity.setValue(active ? this.props.activeOpacity! : 1);\n }\n\n this.props.onActiveStateChange?.(active);\n };\n\n render() {\n const { children, style, ...rest } = this.props;\n\n return (\n <AnimatedBaseButton\n {...rest}\n onActiveStateChange={this.onActiveStateChange}\n style={[style, Platform.OS === 'ios' && { opacity: this.opacity }]}>\n {children}\n </AnimatedBaseButton>\n );\n }\n}\n\nexport { default as PureNativeButton } from './GestureHandlerButton';\n"]}
1
+ {"version":3,"sources":["GestureButtons.tsx"],"names":["RawButton","GestureHandlerButton","shouldCancelWhenOutside","shouldActivateOnStart","BaseButton","React","Component","constructor","props","nativeEvent","state","oldState","pointerInside","active","State","ACTIVE","lastActive","onActiveStateChange","CANCELLED","onPress","e","onHandlerStateChange","handleEvent","onGestureEvent","render","rippleColor","rest","AnimatedBaseButton","Animated","createAnimatedComponent","btnStyles","StyleSheet","create","underlay","position","left","right","bottom","top","RectButton","Platform","OS","opacity","setValue","activeOpacity","Value","children","style","resolvedStyle","flatten","backgroundColor","underlayColor","borderRadius","borderTopLeftRadius","borderTopRightRadius","borderBottomLe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AnB,CAAf;AACD;;AAUDrB,EAAAA,MAAM,GAAG;AACP,UAAM;AAAEsB,MAAAA,QAAF;AAAYC,MAAAA,KAAZ;AAAmB,SAAGrB;AAAtB,QAA+B,KAAKlB,KAA1C;AAEA,wBACE,oBAAC,kBAAD,eACMkB,IADN;AAEE,MAAA,mBAAmB,EAAE,KAAKT,mBAF5B;AAGE,MAAA,KAAK,EAAE,CAAC8B,KAAD,EAAQP,sBAASC,EAAT,KAAgB,KAAhB,IAAyB;AAAEC,QAAAA,OAAO,EAAE,KAAKA;AAAhB,OAAjC;AAHT,QAIGI,QAJH,CADF;AAQD;;AAhC0E;;;;gBAAhEW,gB,kBACW;AACpBb,EAAAA,aAAa,EAAE,GADK;AAEpBc,EAAAA,UAAU,EAAE;AAFQ,C","sourcesContent":["import * as React from 'react';\nimport {\n Animated,\n Platform,\n processColor,\n StyleSheet,\n StyleProp,\n ViewStyle,\n} from 'react-native';\n\nimport createNativeWrapper from '../handlers/createNativeWrapper';\nimport GestureHandlerButton from './GestureHandlerButton';\nimport { State } from '../State';\n\nimport {\n GestureEvent,\n HandlerStateChangeEvent,\n} from '../handlers/gestureHandlerCommon';\nimport {\n NativeViewGestureHandlerPayload,\n NativeViewGestureHandlerProps,\n} from '../handlers/NativeViewGestureHandler';\n\nexport interface RawButtonProps extends NativeViewGestureHandlerProps {\n /**\n * Defines if more than one button could be pressed simultaneously. By default\n * set true.\n */\n exclusive?: boolean;\n // TODO: we should transform props in `createNativeWrapper`\n\n /**\n * Android only.\n *\n * Defines color of native ripple animation used since API level 21.\n */\n rippleColor?: any; // it was present in BaseButtonProps before but is used here in code\n\n /**\n * Android only.\n *\n * Defines radius of native ripple animation used since API level 21.\n */\n rippleRadius?: number | null;\n\n /**\n * Android only.\n *\n * Set this to true if you want the ripple animation to render outside the view bounds.\n */\n borderless?: boolean;\n\n /**\n * Android only.\n *\n * Defines whether the ripple animation should be drawn on the foreground of the view.\n */\n foreground?: boolean;\n\n /**\n * Android only.\n *\n * Set this to true if you don't want the system to play sound when the button is pressed.\n */\n touchSoundDisabled?: boolean;\n}\n\nexport interface BaseButtonProps extends RawButtonProps {\n /**\n * Called when the button gets pressed (analogous to `onPress` in\n * `TouchableHighlight` from RN core).\n */\n onPress?: (pointerInside: boolean) => void;\n\n /**\n * Called when button changes from inactive to active and vice versa. It\n * passes active state as a boolean variable as a first parameter for that\n * method.\n */\n onActiveStateChange?: (active: boolean) => void;\n style?: StyleProp<ViewStyle>;\n testID?: string;\n}\n\nexport interface RectButtonProps extends BaseButtonProps {\n /**\n * Background color that will be dimmed when button is in active state.\n */\n underlayColor?: string;\n\n /**\n * iOS only.\n *\n * Opacity applied to the underlay when button is in active state.\n */\n activeOpacity?: number;\n}\n\nexport interface BorderlessButtonProps extends BaseButtonProps {\n /**\n * iOS only.\n *\n * Opacity applied to the button when it is in an active state.\n */\n activeOpacity?: number;\n}\n\nexport const RawButton = createNativeWrapper(GestureHandlerButton, {\n shouldCancelWhenOutside: false,\n shouldActivateOnStart: false,\n});\n\nexport class BaseButton extends React.Component<BaseButtonProps> {\n private lastActive: boolean;\n\n constructor(props: BaseButtonProps) {\n super(props);\n this.lastActive = false;\n }\n\n private handleEvent = ({\n nativeEvent,\n }: HandlerStateChangeEvent<NativeViewGestureHandlerPayload>) => {\n const { state, oldState, pointerInside } = nativeEvent;\n const active = pointerInside && state === State.ACTIVE;\n\n if (active !== this.lastActive && this.props.onActiveStateChange) {\n this.props.onActiveStateChange(active);\n }\n\n if (\n oldState === State.ACTIVE &&\n state !== State.CANCELLED &&\n this.lastActive &&\n this.props.onPress\n ) {\n this.props.onPress(active);\n }\n\n this.lastActive = active;\n };\n\n // Normally, the parent would execute it's handler first, then forward the\n // event to listeners. However, here our handler is virtually only forwarding\n // events to listeners, so we reverse the order to keep the proper order of\n // the callbacks (from \"raw\" ones to \"processed\").\n private onHandlerStateChange = (\n e: HandlerStateChangeEvent<NativeViewGestureHandlerPayload>\n ) => {\n this.props.onHandlerStateChange?.(e);\n this.handleEvent(e);\n };\n\n private onGestureEvent = (\n e: GestureEvent<NativeViewGestureHandlerPayload>\n ) => {\n this.props.onGestureEvent?.(e);\n this.handleEvent(\n e as HandlerStateChangeEvent<NativeViewGestureHandlerPayload>\n ); // TODO: maybe it is not correct\n };\n\n render() {\n const { rippleColor, ...rest } = this.props;\n\n return (\n <RawButton\n rippleColor={processColor(rippleColor)}\n {...rest}\n onGestureEvent={this.onGestureEvent}\n onHandlerStateChange={this.onHandlerStateChange}\n />\n );\n }\n}\n\nconst AnimatedBaseButton = Animated.createAnimatedComponent(BaseButton);\n\nconst btnStyles = StyleSheet.create({\n underlay: {\n position: 'absolute',\n left: 0,\n right: 0,\n bottom: 0,\n top: 0,\n },\n});\n\nexport class RectButton extends React.Component<RectButtonProps> {\n static defaultProps = {\n activeOpacity: 0.105,\n underlayColor: 'black',\n };\n\n private opacity: Animated.Value;\n\n constructor(props: RectButtonProps) {\n super(props);\n this.opacity = new Animated.Value(0);\n }\n\n private onActiveStateChange = (active: boolean) => {\n if (Platform.OS !== 'android') {\n this.opacity.setValue(active ? this.props.activeOpacity! : 0);\n }\n\n this.props.onActiveStateChange?.(active);\n };\n\n render() {\n const { children, style, ...rest } = this.props;\n\n const resolvedStyle = StyleSheet.flatten(style ?? {});\n\n return (\n <BaseButton\n {...rest}\n style={resolvedStyle}\n onActiveStateChange={this.onActiveStateChange}>\n <Animated.View\n style={[\n btnStyles.underlay,\n {\n opacity: this.opacity,\n backgroundColor: this.props.underlayColor,\n borderRadius: resolvedStyle.borderRadius,\n borderTopLeftRadius: resolvedStyle.borderTopLeftRadius,\n borderTopRightRadius: resolvedStyle.borderTopRightRadius,\n borderBottomLeftRadius: resolvedStyle.borderBottomLeftRadius,\n borderBottomRightRadius: resolvedStyle.borderBottomRightRadius,\n },\n ]}\n />\n {children}\n </BaseButton>\n );\n }\n}\n\nexport class BorderlessButton extends React.Component<BorderlessButtonProps> {\n static defaultProps = {\n activeOpacity: 0.3,\n borderless: true,\n };\n\n private opacity: Animated.Value;\n\n constructor(props: BorderlessButtonProps) {\n super(props);\n this.opacity = new Animated.Value(1);\n }\n\n private onActiveStateChange = (active: boolean) => {\n if (Platform.OS !== 'android') {\n this.opacity.setValue(active ? this.props.activeOpacity! : 1);\n }\n\n this.props.onActiveStateChange?.(active);\n };\n\n render() {\n const { children, style, ...rest } = this.props;\n\n return (\n <AnimatedBaseButton\n {...rest}\n onActiveStateChange={this.onActiveStateChange}\n style={[style, Platform.OS === 'ios' && { opacity: this.opacity }]}>\n {children}\n </AnimatedBaseButton>\n );\n }\n}\n\nexport { default as PureNativeButton } from './GestureHandlerButton';\n"]}
@@ -238,6 +238,8 @@ class GenericTouchable extends React.Component {
238
238
  }
239
239
 
240
240
  render() {
241
+ var _this$props$touchSoun;
242
+
241
243
  const coreProps = {
242
244
  accessible: this.props.accessible !== false,
243
245
  accessibilityLabel: this.props.accessibilityLabel,
@@ -260,7 +262,8 @@ class GenericTouchable extends React.Component {
260
262
  hitSlop: this.props.hitSlop,
261
263
  shouldActivateOnStart: this.props.shouldActivateOnStart,
262
264
  disallowInterruption: this.props.disallowInterruption,
263
- testID: this.props.testID
265
+ testID: this.props.testID,
266
+ touchSoundDisabled: (_this$props$touchSoun = this.props.touchSoundDisabled) !== null && _this$props$touchSoun !== void 0 ? _this$props$touchSoun : false
264
267
  }, this.props.extraButtonProps), /*#__PURE__*/React.createElement(_reactNative.Animated.View, _extends({}, coreProps, {
265
268
  style: this.props.style
266
269
  }), this.props.children));