react-native-macos 0.81.3 → 0.81.5

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 (38) hide show
  1. package/Libraries/Core/ReactNativeVersion.js +1 -1
  2. package/Libraries/LinkingIOS/RCTLinkingManager.mm +119 -0
  3. package/Libraries/LinkingIOS/React-RCTLinking.podspec +0 -4
  4. package/Libraries/StyleSheet/PlatformColorValueTypes.macos.js +2 -2
  5. package/React/Base/RCTBridge.mm +118 -69
  6. package/React/Base/RCTBridgeModule.h +17 -5
  7. package/React/Base/RCTDefines.h +11 -0
  8. package/React/Base/RCTRootView.m +7 -0
  9. package/React/Base/RCTUIKit.h +18 -7
  10. package/React/Base/RCTVersion.m +1 -1
  11. package/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm +9 -0
  12. package/React/Base/macOS/RCTUIKit.m +65 -8
  13. package/React/Fabric/Mounting/ComponentViews/ScrollView/RCTEnhancedScrollView.h +6 -0
  14. package/React/Fabric/Mounting/ComponentViews/ScrollView/RCTEnhancedScrollView.mm +77 -1
  15. package/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.h +4 -0
  16. package/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +69 -3
  17. package/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm +306 -8
  18. package/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm +6 -0
  19. package/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +26 -18
  20. package/React/Modules/RCTUIManager.mm +1 -1
  21. package/React/Views/RCTCursor.m +0 -1
  22. package/React/Views/RCTView.m +1 -2
  23. package/React/Views/ScrollView/RCTScrollView.m +25 -0
  24. package/React/Views/UIView+React.m +1 -1
  25. package/ReactAndroid/gradle.properties +1 -1
  26. package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.kt +1 -1
  27. package/ReactCommon/cxxreact/ReactNativeVersion.h +2 -2
  28. package/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.h +10 -0
  29. package/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.mm +72 -6
  30. package/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/PlatformColorParser.mm +18 -0
  31. package/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/RCTPlatformColorUtils.mm +144 -3
  32. package/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.h +2 -2
  33. package/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm +3 -3
  34. package/local-cli/generate-macos.js +0 -3
  35. package/local-cli/generator-common/index.js +5 -5
  36. package/local-cli/generator-macos/index.js +7 -22
  37. package/package.json +2 -2
  38. package/Libraries/LinkingIOS/macos/RCTLinkingManager.mm +0 -123
@@ -9,6 +9,7 @@
9
9
 
10
10
  #if TARGET_OS_OSX
11
11
 
12
+ #import <QuartzCore/QuartzCore.h>
12
13
  #import <React/RCTUIKit.h>
13
14
 
14
15
  #import <React/RCTAssert.h>
@@ -165,6 +166,8 @@ void UIBezierPathAppendPath(UIBezierPath *path, UIBezierPath *appendPath)
165
166
  BOOL _userInteractionEnabled;
166
167
  BOOL _mouseDownCanMoveWindow;
167
168
  BOOL _respondsToDisplayLayer;
169
+ CATransform3D _transform3D;
170
+ BOOL _hasCustomTransform3D;
168
171
  }
169
172
 
170
173
  + (NSSet<NSString *> *)keyPathsForValuesAffectingValueForKey:(NSString *)key
@@ -195,6 +198,8 @@ static RCTUIView *RCTUIViewCommonInit(RCTUIView *self)
195
198
  self->_enableFocusRing = YES;
196
199
  self->_mouseDownCanMoveWindow = YES;
197
200
  self->_respondsToDisplayLayer = [self respondsToSelector:@selector(displayLayer:)];
201
+ self->_transform3D = CATransform3DIdentity;
202
+ self->_hasCustomTransform3D = NO;
198
203
  }
199
204
  return self;
200
205
  }
@@ -271,20 +276,46 @@ static RCTUIView *RCTUIViewCommonInit(RCTUIView *self)
271
276
 
272
277
  - (void)setTransform:(CGAffineTransform)transform
273
278
  {
274
- self.layer.affineTransform = transform;
279
+ self.transform3D = CATransform3DMakeAffineTransform(transform);
280
+ }
281
+
282
+ - (CATransform3D)transform3D
283
+ {
284
+ return _transform3D;
285
+ }
286
+
287
+ - (void)setTransform3D:(CATransform3D)transform3D
288
+ {
289
+ // On macOS, layer.anchorPoint defaults to {0, 0} instead of {0.5, 0.5} on iOS.
290
+ // Compensate so transforms are applied from the view's center as expected.
291
+ CGPoint anchorPoint = self.layer.anchorPoint;
292
+ if (CGPointEqualToPoint(anchorPoint, CGPointZero) && !CATransform3DEqualToTransform(transform3D, CATransform3DIdentity)) {
293
+ CATransform3D originAdjust = CATransform3DTranslate(CATransform3DIdentity, self.frame.size.width / 2, self.frame.size.height / 2, 0);
294
+ transform3D = CATransform3DConcat(CATransform3DConcat(CATransform3DInvert(originAdjust), transform3D), originAdjust);
295
+ }
296
+
297
+ _transform3D = transform3D;
298
+ _hasCustomTransform3D = !CATransform3DEqualToTransform(transform3D, CATransform3DIdentity);
299
+ self.layer.transform = transform3D;
275
300
  }
276
301
 
277
302
  - (NSView *)hitTest:(NSPoint)point
278
303
  {
279
- // IMPORTANT point is passed in super coordinates by OSX, but expected to be passed in local coordinates
280
- NSView *superview = [self superview];
281
- NSPoint pointInSelf = superview != nil ? [self convertPoint:point fromView:superview] : point;
282
- return [self hitTest:pointInSelf withEvent:nil];
304
+ // NSView's hitTest: receives a point in superview coordinates. Convert to local
305
+ // coordinates using CALayer, which correctly accounts for layer.transform.
306
+ // NSView's convertPoint:fromView: does NOT account for layer transforms.
307
+ CGPoint localPoint;
308
+ if (self.layer.superlayer) {
309
+ localPoint = [self.layer convertPoint:point fromLayer:self.layer.superlayer];
310
+ } else {
311
+ localPoint = point;
312
+ }
313
+ return [self hitTest:localPoint withEvent:nil];
283
314
  }
284
315
 
285
316
  - (BOOL)wantsUpdateLayer
286
317
  {
287
- return [self respondsToSelector:@selector(displayLayer:)];
318
+ return _respondsToDisplayLayer || _hasCustomTransform3D;
288
319
  }
289
320
 
290
321
  - (void)updateLayer
@@ -297,8 +328,13 @@ static RCTUIView *RCTUIViewCommonInit(RCTUIView *self)
297
328
  [layer setBackgroundColor:[_backgroundColor CGColor]];
298
329
  }
299
330
 
300
- // In Fabric, wantsUpdateLayer is always enabled and doesn't guarantee that
301
- // the instance has a displayLayer method.
331
+ // On macOS, AppKit's layer-backed view system resets layer.transform to identity
332
+ // during its layout/display cycle because NSView has no built-in transform property
333
+ // (unlike UIView on iOS). We must re-apply the stored transform after each cycle.
334
+ if (_hasCustomTransform3D && !CATransform3DEqualToTransform(layer.transform, _transform3D)) {
335
+ layer.transform = _transform3D;
336
+ }
337
+
302
338
  if (_respondsToDisplayLayer) {
303
339
  [(id<CALayerDelegate>)self displayLayer:layer];
304
340
  }
@@ -905,4 +941,25 @@ static RCTUIView *RCTUIViewCommonInit(RCTUIView *self)
905
941
 
906
942
  @end
907
943
 
944
+ // NSColor (RCTAppearanceResolving)
945
+
946
+ @implementation NSColor (RCTAppearanceResolving)
947
+
948
+ - (NSColor *)resolvedColorWithAppearance:(NSAppearance *)appearance
949
+ {
950
+ __block NSColor *resolved = self;
951
+ [appearance performAsCurrentDrawingAppearance:^{
952
+ CGColorRef cgColor = self.CGColor;
953
+ if (cgColor) {
954
+ NSColor *fromCG = [NSColor colorWithCGColor:cgColor];
955
+ if (fromCG) {
956
+ resolved = fromCG;
957
+ }
958
+ }
959
+ }];
960
+ return resolved;
961
+ }
962
+
963
+ @end
964
+
908
965
  #endif
@@ -52,6 +52,12 @@ NS_ASSUME_NONNULL_BEGIN
52
52
  @property (nonatomic, assign) BOOL snapToEnd;
53
53
  @property (nonatomic, copy) NSArray<NSNumber *> *snapToOffsets;
54
54
 
55
+ #if TARGET_OS_OSX // [macOS
56
+ - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;
57
+ - (void)zoomToRect:(CGRect)rect animated:(BOOL)animated;
58
+ - (void)flashScrollIndicators;
59
+ #endif // macOS]
60
+
55
61
  /*
56
62
  * Makes `setContentOffset:` method no-op when given `block` is executed.
57
63
  * The block is being executed synchronously.
@@ -41,7 +41,16 @@
41
41
  // because this attribute affects a position of vertical scrollbar; we don't want this
42
42
  // scrollbar flip because we also flip it with whole `UIScrollView` flip.
43
43
  self.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
44
- #endif // [macOS]
44
+ #else // [macOS
45
+ // Similar to iOS's contentInsetAdjustmentBehavior fix
46
+ // For example: When using NSWindowStyleMaskFullSizeContentView (hidden title bar) and ScrollView as root,
47
+ // NSScrollView.automaticallyAdjustsContentInsets (default YES) adds contentInset.top to push content below the toolbar.
48
+ // However, React Native doesn't know about this native contentInset adjustments,causing some caltulation issues
49
+ self.automaticallyAdjustsContentInsets = NO;
50
+ self.hasHorizontalScroller = YES;
51
+ self.hasVerticalScroller = YES;
52
+ self.autohidesScrollers = YES;
53
+ #endif // macOS]
45
54
 
46
55
  __weak __typeof(self) weakSelf = self;
47
56
  _delegateSplitter = [[RCTGenericDelegateSplitter alloc] initWithDelegateUpdateBlock:^(id delegate) {
@@ -98,16 +107,83 @@
98
107
  if (_isSetContentOffsetDisabled) {
99
108
  return;
100
109
  }
110
+ #if !TARGET_OS_OSX // [macOS]
101
111
  super.contentOffset = CGPointMake(
102
112
  RCTSanitizeNaNValue(contentOffset.x, @"scrollView.contentOffset.x"),
103
113
  RCTSanitizeNaNValue(contentOffset.y, @"scrollView.contentOffset.y"));
114
+ #else // [macOS
115
+ if (!NSEqualPoints(contentOffset, self.documentVisibleRect.origin)) {
116
+ [self.contentView scrollToPoint:contentOffset];
117
+ [self reflectScrolledClipView:self.contentView];
118
+ }
119
+ #endif // macOS]
104
120
  }
105
121
 
106
122
  - (void)setFrame:(CGRect)frame
107
123
  {
124
+ #if !TARGET_OS_OSX // [macOS]
108
125
  [super setFrame:frame];
109
126
  [self centerContentIfNeeded];
127
+ #else // [macOS
128
+ // Preserving and revalidating `contentOffset`.
129
+ CGPoint originalOffset = self.contentOffset;
130
+
131
+ [super setFrame:frame];
132
+
133
+ UIEdgeInsets contentInset = self.contentInset;
134
+ CGSize contentSize = self.contentSize;
135
+
136
+ // If contentSize has not been measured yet we can't check bounds.
137
+ if (CGSizeEqualToSize(contentSize, CGSizeZero)) {
138
+ self.contentOffset = originalOffset;
139
+ } else {
140
+ CGSize boundsSize = self.bounds.size;
141
+ CGFloat xMaxOffset = contentSize.width - boundsSize.width + contentInset.right;
142
+ CGFloat yMaxOffset = contentSize.height - boundsSize.height + contentInset.bottom;
143
+ // Make sure offset doesn't exceed bounds. This can happen on screen rotation.
144
+ if ((originalOffset.x >= -contentInset.left) && (originalOffset.x <= xMaxOffset) &&
145
+ (originalOffset.y >= -contentInset.top) && (originalOffset.y <= yMaxOffset)) {
146
+ return;
147
+ }
148
+ self.contentOffset = CGPointMake(
149
+ MAX(-contentInset.left, MIN(xMaxOffset, originalOffset.x)),
150
+ MAX(-contentInset.top, MIN(yMaxOffset, originalOffset.y)));
151
+ }
152
+ #endif // macOS]
153
+ }
154
+
155
+ #if TARGET_OS_OSX // [macOS
156
+ - (NSSize)contentSize
157
+ {
158
+ if (!self.documentView) {
159
+ return [super contentSize];
160
+ }
161
+
162
+ return self.documentView.frame.size;
163
+ }
164
+
165
+ - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
166
+ {
167
+ if (animated) {
168
+ [NSAnimationContext beginGrouping];
169
+ [[NSAnimationContext currentContext] setDuration:0.3];
170
+ [[self.contentView animator] setBoundsOrigin:contentOffset];
171
+ [NSAnimationContext endGrouping];
172
+ } else {
173
+ self.contentOffset = contentOffset;
174
+ }
175
+ }
176
+
177
+ - (void)zoomToRect:(CGRect)rect animated:(BOOL)animated
178
+ {
179
+ [self magnifyToFitRect:rect];
180
+ }
181
+
182
+ - (void)flashScrollIndicators
183
+ {
184
+ [self flashScrollers];
110
185
  }
186
+ #endif // macOS]
111
187
 
112
188
  - (void)didAddSubview:(RCTPlatformView *)subview // [macOS]
113
189
  {
@@ -54,6 +54,10 @@ NS_ASSUME_NONNULL_BEGIN
54
54
  @property (nonatomic, strong, readonly)
55
55
  RCTGenericDelegateSplitter<id<RCTUIScrollViewDelegate>> *scrollViewDelegateSplitter;
56
56
 
57
+ #if TARGET_OS_OSX // [macOS
58
+ @property (nonatomic, assign) UIEdgeInsets contentInset;
59
+ #endif // macOS]
60
+
57
61
  @end
58
62
 
59
63
  /*
@@ -95,6 +95,15 @@ RCTSendScrollEventForNativeAnimations_DEPRECATED(RCTUIScrollView *scrollView, NS
95
95
  RCTScrollableProtocol,
96
96
  RCTEnhancedScrollViewOverridingDelegate>
97
97
 
98
+ - (void)_preserveContentOffsetIfNeededWithBlock:(void (^)())block;
99
+ - (void)_remountChildrenIfNeeded;
100
+ - (void)_remountChildren;
101
+ - (void)_forceDispatchNextScrollEvent;
102
+ - (void)_handleScrollEndIfNeeded;
103
+ - (void)_handleFinishedScrolling:(RCTUIScrollView *)scrollView;
104
+ - (void)_prepareForMaintainVisibleScrollPosition;
105
+ - (void)_adjustForMaintainVisibleContentPosition;
106
+
98
107
  @end
99
108
 
100
109
  @implementation RCTScrollViewComponentView {
@@ -151,7 +160,7 @@ RCTSendScrollEventForNativeAnimations_DEPRECATED(RCTUIScrollView *scrollView, NS
151
160
  _containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
152
161
  [_scrollView setDocumentView:_containerView];
153
162
  #endif // macOS]
154
-
163
+
155
164
  #if !TARGET_OS_OSX // [macOS]
156
165
  [self.scrollViewDelegateSplitter addDelegate:self];
157
166
  #endif // [macOS]
@@ -279,6 +288,19 @@ static inline UIViewAnimationOptions animationOptionsWithCurve(UIViewAnimationCu
279
288
  }
280
289
  #endif
281
290
 
291
+ #if TARGET_OS_OSX // [macOS
292
+ - (void)setContentInset:(UIEdgeInsets)contentInset
293
+ {
294
+ if (UIEdgeInsetsEqualToEdgeInsets(contentInset, _contentInset)) {
295
+ return;
296
+ }
297
+
298
+ _contentInset = contentInset;
299
+ _scrollView.contentInset = contentInset;
300
+ _scrollView.scrollIndicatorInsets = contentInset;
301
+ }
302
+ #endif // macOS]
303
+
282
304
  - (RCTGenericDelegateSplitter<id<RCTUIScrollViewDelegate>> *)scrollViewDelegateSplitter
283
305
  {
284
306
  return ((RCTEnhancedScrollView *)_scrollView).delegateSplitter;
@@ -408,7 +430,11 @@ static inline UIViewAnimationOptions animationOptionsWithCurve(UIViewAnimationCu
408
430
  MAP_SCROLL_VIEW_PROP(zoomScale);
409
431
 
410
432
  if (oldScrollViewProps.contentInset != newScrollViewProps.contentInset) {
433
+ #if !TARGET_OS_OSX // [macOS]
411
434
  _scrollView.contentInset = RCTUIEdgeInsetsFromEdgeInsets(newScrollViewProps.contentInset);
435
+ #else // [macOS
436
+ self.contentInset = RCTUIEdgeInsetsFromEdgeInsets(newScrollViewProps.contentInset);
437
+ #endif // macOS]
412
438
  }
413
439
 
414
440
  RCTEnhancedScrollView *scrollView = (RCTEnhancedScrollView *)_scrollView;
@@ -452,7 +478,7 @@ static inline UIViewAnimationOptions animationOptionsWithCurve(UIViewAnimationCu
452
478
  _shouldUpdateContentInsetAdjustmentBehavior = NO;
453
479
  }
454
480
  #endif // [macOS]
455
-
481
+
456
482
  MAP_SCROLL_VIEW_PROP(disableIntervalMomentum);
457
483
  MAP_SCROLL_VIEW_PROP(snapToInterval);
458
484
 
@@ -536,7 +562,7 @@ static inline UIViewAnimationOptions animationOptionsWithCurve(UIViewAnimationCu
536
562
  }
537
563
 
538
564
  for (RCTPlatformView *subview in [_containerView.subviews reverseObjectEnumerator]) { // [macOS]
539
- RCTPlatformView *hitView = RCTUIViewHitTestWithEvent(subview, [subview convertPoint:point fromView:self], event); // [macOS]
565
+ RCTPlatformView *hitView = RCTUIViewHitTestWithEvent(subview, point, self, event); // [macOS]
540
566
  if (hitView) {
541
567
  return hitView;
542
568
  }
@@ -673,6 +699,22 @@ static inline UIViewAnimationOptions animationOptionsWithCurve(UIViewAnimationCu
673
699
  _firstVisibleView = nil;
674
700
  }
675
701
 
702
+ #if TARGET_OS_OSX // [macOS
703
+ #pragma mark - NSScrollView scroll notification
704
+
705
+ - (void)scrollViewDocumentViewBoundsDidChange:(__unused NSNotification *)notification
706
+ {
707
+ RCTEnhancedScrollView *scrollView = _scrollView;
708
+
709
+ if (scrollView.centerContent) {
710
+ // Update content centering through contentOffset setter
711
+ [scrollView setContentOffset:scrollView.contentOffset];
712
+ }
713
+
714
+ [self scrollViewDidScroll:scrollView];
715
+ }
716
+ #endif // macOS]
717
+
676
718
  #pragma mark - UIScrollViewDelegate
677
719
 
678
720
  #if !TARGET_OS_OSX // [macOS]
@@ -816,6 +858,22 @@ static inline UIViewAnimationOptions animationOptionsWithCurve(UIViewAnimationCu
816
858
  [super viewDidMoveToWindow];
817
859
  #endif // [macOS]
818
860
 
861
+ #if TARGET_OS_OSX // [macOS
862
+ NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
863
+ if (self.window == nil) {
864
+ // Unregister scrollview's clipview bounds change notifications
865
+ [defaultCenter removeObserver:self
866
+ name:NSViewBoundsDidChangeNotification
867
+ object:_scrollView.contentView];
868
+ } else {
869
+ // Register for scrollview's clipview bounds change notifications so we can track scrolling
870
+ [defaultCenter addObserver:self
871
+ selector:@selector(scrollViewDocumentViewBoundsDidChange:)
872
+ name:NSViewBoundsDidChangeNotification
873
+ object:_scrollView.contentView]; // NSClipView
874
+ }
875
+ #endif // macOS]
876
+
819
877
  if (!self.window) {
820
878
  // The view is being removed, ensure that the scroll end event is dispatched
821
879
  [self _handleScrollEndIfNeeded];
@@ -898,6 +956,8 @@ static inline UIViewAnimationOptions animationOptionsWithCurve(UIViewAnimationCu
898
956
  {
899
957
  #if !TARGET_OS_OSX // [macOS]
900
958
  [_scrollView flashScrollIndicators];
959
+ #else // [macOS
960
+ [(RCTEnhancedScrollView *)_scrollView flashScrollers];
901
961
  #endif // [macOS]
902
962
  }
903
963
 
@@ -997,7 +1057,11 @@ static inline UIViewAnimationOptions animationOptionsWithCurve(UIViewAnimationCu
997
1057
 
998
1058
  [self _forceDispatchNextScrollEvent];
999
1059
 
1060
+ #if !TARGET_OS_OSX // [macOS]
1000
1061
  [_scrollView setContentOffset:offset animated:animated];
1062
+ #else // [macOS
1063
+ [(RCTEnhancedScrollView *)_scrollView setContentOffset:offset animated:animated];
1064
+ #endif // macOS]
1001
1065
 
1002
1066
  if (!animated) {
1003
1067
  // When not animated, the expected workflow in ``scrollViewDidEndScrollingAnimation`` after scrolling is not going
@@ -1010,6 +1074,8 @@ static inline UIViewAnimationOptions animationOptionsWithCurve(UIViewAnimationCu
1010
1074
  {
1011
1075
  #if !TARGET_OS_OSX // [macOS]
1012
1076
  [_scrollView zoomToRect:rect animated:animated];
1077
+ #else // [macOS
1078
+ [(RCTEnhancedScrollView *)_scrollView zoomToRect:rect animated:animated];
1013
1079
  #endif // [macOS]
1014
1080
  }
1015
1081