react-native-macos 0.81.4 → 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 (34) 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/React/Base/RCTRootView.m +7 -0
  5. package/React/Base/RCTUIKit.h +18 -7
  6. package/React/Base/RCTVersion.m +1 -1
  7. package/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm +9 -0
  8. package/React/Base/macOS/RCTUIKit.m +65 -8
  9. package/React/Fabric/Mounting/ComponentViews/ScrollView/RCTEnhancedScrollView.h +6 -0
  10. package/React/Fabric/Mounting/ComponentViews/ScrollView/RCTEnhancedScrollView.mm +77 -1
  11. package/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.h +4 -0
  12. package/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +69 -3
  13. package/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm +306 -8
  14. package/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm +6 -0
  15. package/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +26 -18
  16. package/React/Modules/RCTUIManager.mm +1 -1
  17. package/React/Views/RCTCursor.m +0 -1
  18. package/React/Views/RCTView.m +1 -2
  19. package/React/Views/ScrollView/RCTScrollView.m +25 -0
  20. package/React/Views/UIView+React.m +1 -1
  21. package/ReactAndroid/gradle.properties +1 -1
  22. package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.kt +1 -1
  23. package/ReactCommon/cxxreact/ReactNativeVersion.h +2 -2
  24. package/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.h +10 -0
  25. package/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.mm +72 -6
  26. package/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/PlatformColorParser.mm +18 -0
  27. package/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/RCTPlatformColorUtils.mm +144 -3
  28. package/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.h +2 -2
  29. package/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm +3 -3
  30. package/local-cli/generate-macos.js +0 -3
  31. package/local-cli/generator-common/index.js +5 -5
  32. package/local-cli/generator-macos/index.js +7 -22
  33. package/package.json +2 -2
  34. package/Libraries/LinkingIOS/macos/RCTLinkingManager.mm +0 -123
@@ -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
 
@@ -29,8 +29,33 @@
29
29
  #import "RCTConversions.h"
30
30
  #import "RCTFabricComponentsPlugins.h"
31
31
 
32
+ #if TARGET_OS_OSX // [macOS
33
+ #import <React/RCTSurfaceTouchHandler.h>
34
+ #endif // macOS]
35
+
32
36
  using namespace facebook::react;
33
37
 
38
+ #if TARGET_OS_OSX // [macOS
39
+ // Cancel React Native's touch handling by finding the RCTSurfaceTouchHandler
40
+ // gesture recognizer in the view hierarchy and toggling its enabled state.
41
+ // This matches what RCTSurfaceTouchHandler._cancelTouches does internally.
42
+ static void RCTCancelTouchesForView(RCTPlatformView *view)
43
+ {
44
+ while (view) {
45
+ for (id gestureHandler in view.gestureRecognizers) {
46
+ if ([gestureHandler isKindOfClass:[RCTSurfaceTouchHandler class]]) {
47
+ [gestureHandler setEnabled:NO];
48
+ [gestureHandler setEnabled:YES];
49
+ return;
50
+ }
51
+ }
52
+ view = view.superview;
53
+ }
54
+ }
55
+ #endif // macOS]
56
+
57
+ #pragma mark - RCTParagraphTextView (default, non-selectable) // [macOS]
58
+
34
59
  // ParagraphTextView is an auxiliary view we set as contentView so the drawing
35
60
  // can happen on top of the layers manipulated by RCTViewComponentView (the parent view)
36
61
  @interface RCTParagraphTextView : RCTUIView // [macOS]
@@ -41,6 +66,22 @@ using namespace facebook::react;
41
66
 
42
67
  @end
43
68
 
69
+ // [macOS Platform-native text view used when selectable={true}.
70
+ // Handles both text rendering and native text selection.
71
+ #if TARGET_OS_OSX // [macOS
72
+ @interface RCTParagraphSelectableTextView : NSTextView
73
+
74
+ - (void)setNeedsDisplay;
75
+
76
+ #else
77
+ @interface RCTParagraphSelectableTextView : UITextView
78
+ #endif
79
+
80
+ @end
81
+ // macOS]
82
+
83
+ #pragma mark - RCTParagraphComponentView // [macOS]
84
+
44
85
  #if !TARGET_OS_OSX // [macOS]
45
86
  @interface RCTParagraphComponentView () <UIEditMenuInteractionDelegate>
46
87
 
@@ -48,9 +89,9 @@ using namespace facebook::react;
48
89
 
49
90
  @end
50
91
  #else // [macOS
51
- @interface RCTParagraphComponentView ()
92
+ @interface RCTParagraphComponentView () <NSTextViewDelegate>
52
93
  @end
53
- #endif // [macOS]
94
+ #endif // macOS]
54
95
 
55
96
  @implementation RCTParagraphComponentView {
56
97
  ParagraphAttributes _paragraphAttributes;
@@ -59,6 +100,7 @@ using namespace facebook::react;
59
100
  UILongPressGestureRecognizer *_longPressGestureRecognizer;
60
101
  #endif // [macOS]
61
102
  RCTParagraphTextView *_textView;
103
+ RCTParagraphSelectableTextView *_selectableTextView; // [macOS]
62
104
  }
63
105
 
64
106
  - (instancetype)initWithFrame:(CGRect)frame
@@ -121,13 +163,14 @@ using namespace facebook::react;
121
163
  _textView.paragraphAttributes = _paragraphAttributes;
122
164
 
123
165
  if (newParagraphProps.isSelectable != oldParagraphProps.isSelectable) {
124
- #if !TARGET_OS_OSX // [macOS]
166
+ // [macOS Replaced enableContextMenu/disableContextMenu with _enableSelection/_disableSelection
167
+ // to swap in a native text view that supports text selection.
125
168
  if (newParagraphProps.isSelectable) {
126
- [self enableContextMenu];
169
+ [self _enableSelection];
127
170
  } else {
128
- [self disableContextMenu];
171
+ [self _disableSelection];
129
172
  }
130
- #endif // [macOS]
173
+ // macOS]
131
174
  }
132
175
 
133
176
  [super updateProps:props oldProps:oldProps];
@@ -138,6 +181,10 @@ using namespace facebook::react;
138
181
  _textView.state = std::static_pointer_cast<const ParagraphShadowNode::ConcreteState>(state);
139
182
  [_textView setNeedsDisplay];
140
183
  [self setNeedsLayout];
184
+
185
+ if (_selectableTextView) {
186
+ [self updateSelectableTextStorage];
187
+ }
141
188
  }
142
189
 
143
190
  - (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics
@@ -149,11 +196,18 @@ using namespace facebook::react;
149
196
  _textView.layoutMetrics = _layoutMetrics;
150
197
  [_textView setNeedsDisplay];
151
198
  [self setNeedsLayout];
199
+
200
+ if (_selectableTextView) {
201
+ [self updateSelectableTextStorage];
202
+ }
152
203
  }
153
204
 
154
205
  - (void)prepareForRecycle
155
206
  {
156
207
  [super prepareForRecycle];
208
+ if (_selectableTextView) {
209
+ [self _disableSelection];
210
+ }
157
211
  _textView.state = nullptr;
158
212
  _accessibilityProvider = nil;
159
213
  }
@@ -162,7 +216,114 @@ using namespace facebook::react;
162
216
  {
163
217
  [super layoutSubviews];
164
218
 
219
+ if (_selectableTextView) {
220
+ _selectableTextView.frame = self.bounds;
221
+ } else {
222
+ _textView.frame = self.bounds;
223
+ }
224
+ }
225
+
226
+ #pragma mark - Selection Management
227
+
228
+ - (void)_enableSelection
229
+ {
230
+ if (_selectableTextView) {
231
+ return;
232
+ }
233
+
234
+ _selectableTextView = [[RCTParagraphSelectableTextView alloc] initWithFrame:self.bounds];
235
+
236
+ #if TARGET_OS_OSX // [macOS
237
+ _selectableTextView.delegate = self;
238
+ _selectableTextView.usesFontPanel = NO;
239
+ _selectableTextView.drawsBackground = NO;
240
+ _selectableTextView.linkTextAttributes = @{};
241
+ _selectableTextView.editable = NO;
242
+ _selectableTextView.selectable = YES;
243
+ _selectableTextView.verticallyResizable = NO;
244
+ _selectableTextView.layoutManager.usesFontLeading = NO;
245
+ #else // macOS]
246
+ _selectableTextView.editable = NO;
247
+ _selectableTextView.selectable = YES;
248
+ _selectableTextView.scrollEnabled = NO;
249
+ _selectableTextView.textContainerInset = UIEdgeInsetsZero;
250
+ _selectableTextView.textContainer.lineFragmentPadding = 0;
251
+ _selectableTextView.backgroundColor = [UIColor clearColor];
252
+ #endif // macOS]
253
+
254
+ // Sync text content into the native text view.
255
+ [self updateSelectableTextStorage];
256
+
257
+ // Swap: remove the default text view, install the selectable one.
258
+ [_textView removeFromSuperview];
259
+ self.contentView = _selectableTextView;
260
+
261
+ #if !TARGET_OS_OSX // [macOS]
262
+ // On iOS, also enable the context menu (long press to copy).
263
+ [self enableContextMenu];
264
+ #endif // [macOS]
265
+ }
266
+
267
+ - (void)_disableSelection
268
+ {
269
+ if (!_selectableTextView) {
270
+ return;
271
+ }
272
+
273
+ #if !TARGET_OS_OSX // [macOS]
274
+ [self disableContextMenu];
275
+ #endif // [macOS]
276
+
277
+ // Swap back: remove the selectable text view, restore the default one.
278
+ [_selectableTextView removeFromSuperview];
279
+ _selectableTextView = nil;
280
+
281
+ self.contentView = _textView;
165
282
  _textView.frame = self.bounds;
283
+ [_textView setNeedsDisplay];
284
+ }
285
+
286
+ - (void)updateSelectableTextStorage
287
+ {
288
+ if (!_selectableTextView || !_textView.state) {
289
+ return;
290
+ }
291
+
292
+ const auto &stateData = _textView.state->getData();
293
+ auto textLayoutManager = stateData.layoutManager.lock();
294
+ if (!textLayoutManager) {
295
+ return;
296
+ }
297
+
298
+ RCTTextLayoutManager *nativeTextLayoutManager =
299
+ (RCTTextLayoutManager *)unwrapManagedObject(textLayoutManager->getNativeTextLayoutManager());
300
+ CGRect frame = RCTCGRectFromRect(_layoutMetrics.getContentFrame());
301
+
302
+ NSTextStorage *textStorage = [nativeTextLayoutManager getTextStorageForAttributedString:stateData.attributedString
303
+ paragraphAttributes:_paragraphAttributes
304
+ size:frame.size];
305
+
306
+ #if TARGET_OS_OSX // [macOS
307
+ // Sync the layout infrastructure into the NSTextView.
308
+ NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject;
309
+ NSTextContainer *textContainer = layoutManager.textContainers.firstObject;
310
+ [_selectableTextView replaceTextContainer:textContainer];
311
+
312
+ // Detach layout managers from the source text storage before syncing content.
313
+ NSArray<NSLayoutManager *> *managers = [[textStorage layoutManagers] copy];
314
+ for (NSLayoutManager *manager in managers) {
315
+ [textStorage removeLayoutManager:manager];
316
+ }
317
+
318
+ _selectableTextView.minSize = frame.size;
319
+ _selectableTextView.maxSize = frame.size;
320
+ _selectableTextView.frame = frame;
321
+ [[_selectableTextView textStorage] setAttributedString:textStorage];
322
+ #else // macOS]
323
+ // On iOS, set the attributed text directly. UITextView manages its own layout.
324
+ _selectableTextView.attributedText = textStorage;
325
+ _selectableTextView.frame = frame;
326
+ #endif // macOS]
166
327
  }
167
328
 
168
329
  #pragma mark - Accessibility
@@ -189,7 +350,7 @@ using namespace facebook::react;
189
350
  return NO;
190
351
  }
191
352
 
192
- #if !TARGET_OS_OSX // [macOS
353
+ #if !TARGET_OS_OSX // [macOS]
193
354
  - (NSArray *)accessibilityElements
194
355
  {
195
356
  const auto &paragraphProps = static_cast<const ParagraphProps &>(*_props);
@@ -352,6 +513,89 @@ using namespace facebook::react;
352
513
  }
353
514
  #endif // [macOS]
354
515
 
516
+ #pragma mark - macOS Mouse Event Handling
517
+
518
+ #if TARGET_OS_OSX // [macOS
519
+
520
+ - (NSView *)hitTest:(NSPoint)point
521
+ {
522
+ NSView *hitView = [super hitTest:point];
523
+
524
+ if (!_selectableTextView) {
525
+ return hitView;
526
+ }
527
+
528
+ // Intercept clicks on the selectable text view so we can manage selection ourselves,
529
+ // preventing it from swallowing events that may be handled in JS (e.g. onPress).
530
+ NSEventType eventType = NSApp.currentEvent.type;
531
+ BOOL isMouseClickEvent = NSEvent.pressedMouseButtons > 0;
532
+ BOOL isMouseMoveEventType = eventType == NSEventTypeMouseMoved ||
533
+ eventType == NSEventTypeMouseEntered ||
534
+ eventType == NSEventTypeMouseExited ||
535
+ eventType == NSEventTypeCursorUpdate;
536
+ BOOL isMouseMoveEvent = !isMouseClickEvent && isMouseMoveEventType;
537
+ BOOL isTextViewClick = (hitView && hitView == _selectableTextView) && !isMouseMoveEvent;
538
+
539
+ return isTextViewClick ? self : hitView;
540
+ }
541
+
542
+ - (void)rightMouseDown:(NSEvent *)event
543
+ {
544
+ if (!_selectableTextView) {
545
+ [super rightMouseDown:event];
546
+ return;
547
+ }
548
+
549
+ RCTCancelTouchesForView(self);
550
+ [_selectableTextView rightMouseDown:event];
551
+ }
552
+
553
+ - (void)mouseDown:(NSEvent *)event
554
+ {
555
+ if (!_selectableTextView) {
556
+ [super mouseDown:event];
557
+ return;
558
+ }
559
+
560
+ // Double/triple-clicks should be forwarded to the NSTextView for word/line selection.
561
+ BOOL shouldForward = event.clickCount > 1;
562
+
563
+ if (!shouldForward) {
564
+ // Peek at next event to know if a drag (selection) is beginning.
565
+ NSEvent *nextEvent = [self.window nextEventMatchingMask:NSEventMaskLeftMouseUp | NSEventMaskLeftMouseDragged
566
+ untilDate:[NSDate distantFuture]
567
+ inMode:NSEventTrackingRunLoopMode
568
+ dequeue:NO];
569
+ shouldForward = nextEvent.type == NSEventTypeLeftMouseDragged;
570
+ }
571
+
572
+ if (shouldForward) {
573
+ NSView *contentView = self.window.contentView;
574
+ // -[NSView hitTest:] takes coordinates in a view's superview coordinate system.
575
+ NSPoint point = [contentView.superview convertPoint:event.locationInWindow fromView:nil];
576
+
577
+ if ([contentView hitTest:point] == self) {
578
+ RCTCancelTouchesForView(self);
579
+ [self.window makeFirstResponder:_selectableTextView];
580
+ [_selectableTextView mouseDown:event];
581
+ }
582
+ } else {
583
+ // Clear selection for single clicks.
584
+ _selectableTextView.selectedRange = NSMakeRange(NSNotFound, 0);
585
+ }
586
+ }
587
+
588
+ #pragma mark - NSTextViewDelegate
589
+
590
+ - (void)textDidEndEditing:(NSNotification *)notification
591
+ {
592
+ _selectableTextView.selectedRange = NSMakeRange(NSNotFound, 0);
593
+ }
594
+
595
+ #endif // macOS]
596
+
597
+ #pragma mark - Responder Chain
598
+
355
599
  - (BOOL)canBecomeFirstResponder
356
600
  {
357
601
  const auto &paragraphProps = static_cast<const ParagraphProps &>(*_props);
@@ -369,7 +613,19 @@ using namespace facebook::react;
369
613
 
370
614
  return [self.nextResponder canPerformAction:action withSender:sender];
371
615
  }
372
- #endif // [macOS]
616
+ #else // [macOS
617
+
618
+ - (BOOL)resignFirstResponder
619
+ {
620
+ // Don't relinquish first responder while selecting text.
621
+ if (_selectableTextView && NSRunLoop.currentRunLoop.currentMode == NSEventTrackingRunLoopMode) {
622
+ return NO;
623
+ }
624
+
625
+ return [super resignFirstResponder];
626
+ }
627
+
628
+ #endif // macOS]
373
629
 
374
630
  - (void)copy:(id)sender
375
631
  {
@@ -404,6 +660,8 @@ Class<RCTComponentViewProtocol> RCTParagraphCls(void)
404
660
  return RCTParagraphComponentView.class;
405
661
  }
406
662
 
663
+ #pragma mark - RCTParagraphTextView Implementation
664
+
407
665
  @implementation RCTParagraphTextView {
408
666
  CAShapeLayer *_highlightLayer;
409
667
  }
@@ -450,3 +708,43 @@ Class<RCTComponentViewProtocol> RCTParagraphCls(void)
450
708
  }
451
709
 
452
710
  @end
711
+
712
+ // [macOS
713
+ #pragma mark - RCTParagraphSelectableTextView Implementation
714
+
715
+ @implementation RCTParagraphSelectableTextView
716
+
717
+ #if TARGET_OS_OSX
718
+
719
+ - (void)setNeedsDisplay
720
+ {
721
+ [self setNeedsDisplay:YES];
722
+ }
723
+
724
+ - (BOOL)canBecomeKeyView
725
+ {
726
+ // Prevent this NSTextView from participating in the key view loop directly.
727
+ // The parent RCTParagraphComponentView manages focus instead.
728
+ return NO;
729
+ }
730
+
731
+ - (BOOL)resignFirstResponder
732
+ {
733
+ // Don't relinquish first responder while the user is actively selecting text.
734
+ if (self.selectable && NSRunLoop.currentRunLoop.currentMode == NSEventTrackingRunLoopMode) {
735
+ return NO;
736
+ }
737
+
738
+ return [super resignFirstResponder];
739
+ }
740
+
741
+ #else
742
+
743
+ // On iOS, let UITextView handle touches natively for selection support.
744
+ // No hitTest override needed — UITextView's built-in gesture recognizers
745
+ // handle long-press-to-select and other selection interactions.
746
+
747
+ #endif
748
+
749
+ @end
750
+ // macOS]
@@ -411,6 +411,12 @@ static NSSet<NSNumber *> *returnKeyTypesSet;
411
411
  NSArray<NSPasteboardType> *types = RCTPasteboardTypeArrayFromProps(newTextInputProps.traits.pastedTypes);
412
412
  [_backedTextInputView setReadablePasteBoardTypes:types];
413
413
  }
414
+
415
+ if (newTextInputProps.enableFocusRing != oldTextInputProps.enableFocusRing) {
416
+ if ([_backedTextInputView respondsToSelector:@selector(setEnableFocusRing:)]) {
417
+ [_backedTextInputView setEnableFocusRing:newTextInputProps.enableFocusRing];
418
+ }
419
+ }
414
420
  #endif // macOS]
415
421
 
416
422
  [super updateProps:props oldProps:oldProps];
@@ -167,7 +167,7 @@ const CGFloat BACKGROUND_COLOR_ZPOSITION = -1024.0f;
167
167
  [self invalidateLayer];
168
168
  }
169
169
  }
170
- #else // [macOS SAAD
170
+ #else // [macOS
171
171
  - (void)viewDidChangeEffectiveAppearance
172
172
  {
173
173
  [super viewDidChangeEffectiveAppearance];
@@ -341,11 +341,6 @@ const CGFloat BACKGROUND_COLOR_ZPOSITION = -1024.0f;
341
341
  needsInvalidateLayer = YES;
342
342
  }
343
343
 
344
- // `cursor`
345
- if (oldViewProps.cursor != newViewProps.cursor) {
346
- needsInvalidateLayer = YES;
347
- }
348
-
349
344
  // `shouldRasterize`
350
345
  if (oldViewProps.shouldRasterize != newViewProps.shouldRasterize) {
351
346
  self.layer.shouldRasterize = newViewProps.shouldRasterize;
@@ -367,17 +362,12 @@ const CGFloat BACKGROUND_COLOR_ZPOSITION = -1024.0f;
367
362
  ![_propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN containsObject:@"transform"]) {
368
363
  auto newTransform = newViewProps.resolveTransform(_layoutMetrics);
369
364
  CATransform3D caTransform = RCTCATransform3DFromTransformMatrix(newTransform);
370
- #if TARGET_OS_OSX // [macOS
371
- CGPoint anchorPoint = self.layer.anchorPoint;
372
- if (CGPointEqualToPoint(anchorPoint, CGPointZero) && !CATransform3DEqualToTransform(caTransform, CATransform3DIdentity)) {
373
- // https://developer.apple.com/documentation/quartzcore/calayer/1410817-anchorpoint
374
- // This compensates for the fact that layer.anchorPoint is {0, 0} instead of {0.5, 0.5} on macOS for some reason.
375
- CATransform3D originAdjust = CATransform3DTranslate(CATransform3DIdentity, self.frame.size.width / 2, self.frame.size.height / 2, 0);
376
- caTransform = CATransform3DConcat(CATransform3DConcat(CATransform3DInvert(originAdjust), caTransform), originAdjust);
377
- }
365
+ #if !TARGET_OS_OSX // [macOS]
366
+ self.layer.transform = caTransform;
367
+ #else // [macOS
368
+ self.transform3D = caTransform;
378
369
  #endif // macOS]
379
370
 
380
- self.layer.transform = caTransform;
381
371
  // Enable edge antialiasing in rotation, skew, or perspective transforms
382
372
  self.layer.allowsEdgeAntialiasing = caTransform.m12 != 0.0f || caTransform.m21 != 0.0f || caTransform.m34 != 0.0f;
383
373
  }
@@ -718,7 +708,11 @@ const CGFloat BACKGROUND_COLOR_ZPOSITION = -1024.0f;
718
708
  if ((_props->transformOrigin.isSet() || _props->transform.operations.size() > 0) &&
719
709
  layoutMetrics.frame.size != oldLayoutMetrics.frame.size) {
720
710
  auto newTransform = _props->resolveTransform(layoutMetrics);
711
+ #if !TARGET_OS_OSX // [macOS]
721
712
  self.layer.transform = RCTCATransform3DFromTransformMatrix(newTransform);
713
+ #else // [macOS
714
+ self.transform3D = RCTCATransform3DFromTransformMatrix(newTransform);
715
+ #endif // macOS]
722
716
  }
723
717
  }
724
718
 
@@ -812,7 +806,7 @@ const CGFloat BACKGROUND_COLOR_ZPOSITION = -1024.0f;
812
806
  }
813
807
 
814
808
  for (RCTPlatformView *subview in [self.subviews reverseObjectEnumerator]) { // [macOS]
815
- RCTPlatformView *hitView = RCTUIViewHitTestWithEvent(subview, [subview convertPoint:point fromView:self], event); // [macOS]
809
+ RCTPlatformView *hitView = RCTUIViewHitTestWithEvent(subview, point, self, event); // [macOS]
816
810
  if (hitView) {
817
811
  return hitView;
818
812
  }
@@ -1177,7 +1171,7 @@ static RCTBorderStyle RCTBorderStyleFromOutlineStyle(OutlineStyle outlineStyle)
1177
1171
  #if !TARGET_OS_OSX // [macOS]
1178
1172
  RCTUIColor *backgroundColor = [_backgroundColor resolvedColorWithTraitCollection:self.traitCollection];
1179
1173
  #else // [macOS
1180
- RCTUIColor *backgroundColor = _backgroundColor;
1174
+ RCTUIColor *backgroundColor = [_backgroundColor resolvedColorWithAppearance:self.effectiveAppearance];
1181
1175
  #endif // macOS]
1182
1176
  // The reason we sometimes do not set self.layer's backgroundColor is because
1183
1177
  // we want to support non-uniform border radii, which apple does not natively
@@ -1208,6 +1202,9 @@ static RCTBorderStyle RCTBorderStyleFromOutlineStyle(OutlineStyle outlineStyle)
1208
1202
 
1209
1203
  layer.borderWidth = (CGFloat)borderMetrics.borderWidths.left;
1210
1204
  RCTUIColor *borderColor = RCTUIColorFromSharedColor(borderMetrics.borderColors.left); // [macOS]
1205
+ #if TARGET_OS_OSX // [macOS
1206
+ borderColor = [borderColor resolvedColorWithAppearance:self.effectiveAppearance];
1207
+ #endif // macOS]
1211
1208
  layer.borderColor = borderColor.CGColor;
1212
1209
  layer.cornerRadius = (CGFloat)borderMetrics.borderRadii.topLeft.horizontal;
1213
1210
 
@@ -1229,6 +1226,12 @@ static RCTBorderStyle RCTBorderStyleFromOutlineStyle(OutlineStyle outlineStyle)
1229
1226
  layer.cornerRadius = 0;
1230
1227
 
1231
1228
  RCTBorderColors borderColors = RCTCreateRCTBorderColorsFromBorderColors(borderMetrics.borderColors);
1229
+ #if TARGET_OS_OSX // [macOS
1230
+ borderColors.top = [borderColors.top resolvedColorWithAppearance:self.effectiveAppearance];
1231
+ borderColors.left = [borderColors.left resolvedColorWithAppearance:self.effectiveAppearance];
1232
+ borderColors.bottom = [borderColors.bottom resolvedColorWithAppearance:self.effectiveAppearance];
1233
+ borderColors.right = [borderColors.right resolvedColorWithAppearance:self.effectiveAppearance];
1234
+ #endif // macOS]
1232
1235
 
1233
1236
  RCTAddContourEffectToLayer(
1234
1237
  _borderLayer,
@@ -1255,10 +1258,16 @@ static RCTBorderStyle RCTBorderStyleFromOutlineStyle(OutlineStyle outlineStyle)
1255
1258
 
1256
1259
  if (borderMetrics.borderRadii.isUniform() && borderMetrics.borderRadii.topLeft.horizontal == 0) {
1257
1260
  RCTUIColor *outlineColor = RCTUIColorFromSharedColor(_props->outlineColor); // [macOS]
1261
+ #if TARGET_OS_OSX // [macOS
1262
+ outlineColor = [outlineColor resolvedColorWithAppearance:self.effectiveAppearance];
1263
+ #endif // macOS]
1258
1264
  _outlineLayer.borderWidth = _props->outlineWidth;
1259
1265
  _outlineLayer.borderColor = outlineColor.CGColor;
1260
1266
  } else {
1261
1267
  RCTUIColor *outlineColor = RCTUIColorFromSharedColor(_props->outlineColor); // [macOS]
1268
+ #if TARGET_OS_OSX // [macOS
1269
+ outlineColor = [outlineColor resolvedColorWithAppearance:self.effectiveAppearance];
1270
+ #endif // macOS]
1262
1271
 
1263
1272
  RCTAddContourEffectToLayer(
1264
1273
  _outlineLayer,
@@ -1707,7 +1716,6 @@ static NSString *RCTRecursiveAccessibilityLabel(RCTUIView *view) // [macOS]
1707
1716
  }
1708
1717
 
1709
1718
  #if TARGET_OS_OSX // [macOS
1710
-
1711
1719
  - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args
1712
1720
  {
1713
1721
  if ([commandName isEqualToString:@"focus"]) {
@@ -1186,7 +1186,7 @@ RCT_EXPORT_METHOD(findSubviewIn
1186
1186
  {
1187
1187
  [self addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTPlatformView *> *viewRegistry) { // [macOS]
1188
1188
  RCTPlatformView *view = viewRegistry[reactTag]; // [macOS]
1189
- RCTPlatformView *target = RCTUIViewHitTestWithEvent(view, point, nil); // [macOS]
1189
+ RCTPlatformView *target = RCTUIViewHitTestWithEvent(view, point, view, nil); // [macOS]
1190
1190
  CGRect frame = [target convertRect:target.bounds toView:view];
1191
1191
 
1192
1192
  while (target.reactTag == nil && target.superview != nil) {