react-native-gesture-handler 2.20.0 → 2.20.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,5 +8,5 @@ import com.facebook.react.uimanager.events.Event
8
8
 
9
9
  fun ReactContext.dispatchEvent(event: Event<*>) {
10
10
  val fabricUIManager = UIManagerHelper.getUIManager(this, UIManagerType.FABRIC) as FabricUIManager
11
- fabricUIManager.getEventDispatcher().dispatchEvent(event)
11
+ fabricUIManager.eventDispatcher.dispatchEvent(event)
12
12
  }
@@ -6,7 +6,7 @@ import com.facebook.react.uimanager.events.Event
6
6
 
7
7
  fun ReactContext.dispatchEvent(event: Event<*>) {
8
8
  try {
9
- this.getNativeModule(UIManagerModule::class.java)!!.getEventDispatcher().dispatchEvent(event)
9
+ this.getNativeModule(UIManagerModule::class.java)!!.eventDispatcher.dispatchEvent(event)
10
10
  } catch (e: NullPointerException) {
11
11
  throw Exception("Couldn't get an instance of UIManagerModule. Gesture Handler is unable to send an event.", e)
12
12
  }
@@ -464,9 +464,13 @@
464
464
  withVelocity:[recognizer velocityInView:recognizer.view.window]
465
465
  withNumberOfTouches:recognizer.numberOfTouches
466
466
  withPointerType:_pointerType
467
+ #if !TARGET_OS_TV
467
468
  withStylusData:[panRecognizer.stylusData toDictionary]]; // In Objective-C calling method on nil returns
468
469
  // nil, therefore this line does not crash.
470
+ #else
471
+ withStylusData:nil];
472
+ #endif // TARGET_OS_TV
469
473
  }
470
- #endif
474
+ #endif // TARGET_OS_OSX
471
475
 
472
476
  @end
@@ -9,14 +9,30 @@
9
9
  #import "RNGestureHandler.h"
10
10
 
11
11
  #if TARGET_OS_OSX
12
+
13
+ #if RCT_NEW_ARCH_ENABLED
14
+
15
+ #include <react/renderer/core/LayoutMetrics.h>
16
+
17
+ @protocol RCTComponentViewProtocol;
18
+
19
+ #endif // RCT_NEW_ARCH_ENABLED
20
+
12
21
  @interface RNGestureHandlerButton : NSControl
13
22
  #else
14
23
  @interface RNGestureHandlerButton : UIControl
15
- #endif
24
+ #endif // TARGET_OS_OSX
16
25
  /**
17
26
  * Insets used when hit testing inside this view.
18
27
  */
19
28
  @property (nonatomic, assign) UIEdgeInsets hitTestEdgeInsets;
20
29
  @property (nonatomic) BOOL userEnabled;
21
30
 
31
+ #if TARGET_OS_OSX && RCT_NEW_ARCH_ENABLED
32
+ - (void)mountChildComponentView:(RNGHUIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index;
33
+ - (void)unmountChildComponentView:(RNGHUIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index;
34
+ - (void)updateLayoutMetrics:(const facebook::react::LayoutMetrics &)layoutMetrics
35
+ oldLayoutMetrics:(const facebook::react::LayoutMetrics &)oldLayoutMetrics;
36
+ #endif
37
+
22
38
  @end
@@ -10,6 +10,15 @@
10
10
 
11
11
  #if !TARGET_OS_OSX
12
12
  #import <UIKit/UIKit.h>
13
+ #else
14
+ #import <React/RCTUIKit.h>
15
+ #endif
16
+
17
+ #if RCT_NEW_ARCH_ENABLED
18
+
19
+ #import <React/RCTConversions.h>
20
+ #import <React/RCTFabricComponentsPlugins.h>
21
+
13
22
  #endif
14
23
 
15
24
  /**
@@ -82,4 +91,59 @@
82
91
  }
83
92
  #endif
84
93
 
94
+ #if TARGET_OS_OSX && RCT_NEW_ARCH_ENABLED
95
+ - (void)mountChildComponentView:(RNGHUIView *)childComponentView index:(NSInteger)index
96
+ {
97
+ if (childComponentView.superview != nil) {
98
+ return;
99
+ }
100
+
101
+ if (index < [[self subviews] count]) {
102
+ // Get the view currently at your desired index
103
+ NSView *existingView = [[self subviews] objectAtIndex:index];
104
+
105
+ // Now use this to insert your new view above the existing one
106
+ [self addSubview:childComponentView positioned:NSWindowAbove relativeTo:existingView];
107
+ } else {
108
+ // if the index is out of bounds, add the new subview at the end
109
+ [self addSubview:childComponentView];
110
+ }
111
+ }
112
+
113
+ - (void)unmountChildComponentView:(RNGHUIView *)childComponentView index:(NSInteger)index
114
+ {
115
+ [childComponentView removeFromSuperview];
116
+ }
117
+
118
+ - (void)updateLayoutMetrics:(const facebook::react::LayoutMetrics &)layoutMetrics
119
+ oldLayoutMetrics:(const facebook::react::LayoutMetrics &)oldLayoutMetrics
120
+ {
121
+ bool forceUpdate = oldLayoutMetrics == facebook::react::EmptyLayoutMetrics;
122
+
123
+ if (forceUpdate || (layoutMetrics.frame != oldLayoutMetrics.frame)) {
124
+ CGRect frame = RCTCGRectFromRect(layoutMetrics.frame);
125
+
126
+ if (!std::isfinite(frame.origin.x) || !std::isfinite(frame.origin.y) || !std::isfinite(frame.size.width) ||
127
+ !std::isfinite(frame.size.height)) {
128
+ // CALayer will crash if we pass NaN or Inf values.
129
+ // It's unclear how to detect this case on cross-platform manner holistically, so we have to do it on the mounting
130
+ // layer as well. NaN/Inf is a kinda valid result of some math operations. Even if we can (and should) detect (and
131
+ // report early) incorrect (NaN and Inf) values which come from JavaScript side, we sometimes cannot backtrace the
132
+ // sources of a calculation that produced an incorrect/useless result.
133
+ RCTLogWarn(
134
+ @"-[UIView(ComponentViewProtocol) updateLayoutMetrics:oldLayoutMetrics:]: Received invalid layout metrics (%@) for a view (%@).",
135
+ NSStringFromCGRect(frame),
136
+ self);
137
+ } else {
138
+ self.frame = frame;
139
+ self.bounds = CGRect{CGPointZero, frame.size};
140
+ }
141
+ }
142
+
143
+ if (forceUpdate || (layoutMetrics.displayType != oldLayoutMetrics.displayType)) {
144
+ self.hidden = layoutMetrics.displayType == facebook::react::DisplayType::None;
145
+ }
146
+ }
147
+ #endif
148
+
85
149
  @end
@@ -1,6 +1,10 @@
1
1
  #ifdef RCT_NEW_ARCH_ENABLED
2
2
 
3
+ #if !TARGET_OS_OSX
3
4
  #import <UIKit/UIKit.h>
5
+ #else
6
+ #import <React/RCTUIKit.h>
7
+ #endif
4
8
 
5
9
  #import <React/RCTViewComponentView.h>
6
10
 
@@ -21,6 +21,15 @@ using namespace facebook::react;
21
21
  RNGestureHandlerButton *_buttonView;
22
22
  }
23
23
 
24
+ #if TARGET_OS_OSX
25
+ // Here we want to disable view recycling on buttons. Listeners are not removed from views when they're being unmounted,
26
+ // therefore after navigating through other screens buttons may have different actions then they are supposed to have.
27
+ + (BOOL)shouldBeRecycled
28
+ {
29
+ return NO;
30
+ }
31
+ #endif
32
+
24
33
  // Needed because of this: https://github.com/facebook/react-native/pull/37274
25
34
  + (void)load
26
35
  {
@@ -40,12 +49,12 @@ using namespace facebook::react;
40
49
  return self;
41
50
  }
42
51
 
43
- - (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
52
+ - (void)mountChildComponentView:(RNGHUIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
44
53
  {
45
54
  [_buttonView mountChildComponentView:childComponentView index:index];
46
55
  }
47
56
 
48
- - (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
57
+ - (void)unmountChildComponentView:(RNGHUIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
49
58
  {
50
59
  [_buttonView unmountChildComponentView:childComponentView index:index];
51
60
  }
@@ -97,7 +106,7 @@ using namespace facebook::react;
97
106
  const auto &newProps = *std::static_pointer_cast<const RNGestureHandlerButtonProps>(props);
98
107
 
99
108
  _buttonView.userEnabled = newProps.enabled;
100
- #if !TARGET_OS_TV
109
+ #if !TARGET_OS_TV && !TARGET_OS_OSX
101
110
  _buttonView.exclusiveTouch = newProps.exclusive;
102
111
  #endif
103
112
  _buttonView.hitTestEdgeInsets = UIEdgeInsetsMake(
@@ -30,7 +30,7 @@ RCT_CUSTOM_VIEW_PROPERTY(hitSlop, UIEdgeInsets, RNGestureHandlerButton)
30
30
 
31
31
  - (RNGHUIView *)view
32
32
  {
33
- return [RNGestureHandlerButton new];
33
+ return (RNGHUIView *)[RNGestureHandlerButton new];
34
34
  }
35
35
 
36
36
  @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gesture-handler",
3
- "version": "2.20.0",
3
+ "version": "2.20.2",
4
4
  "description": "Experimental implementation of a new declarative API for gesture handling in react-native",
5
5
  "scripts": {
6
6
  "prepare": "bob build && husky install",