react-native-macos 0.73.32 → 0.73.34

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.
@@ -12,6 +12,6 @@
12
12
  exports.version = {
13
13
  major: 0,
14
14
  minor: 73,
15
- patch: 32,
15
+ patch: 34,
16
16
  prerelease: null,
17
17
  };
@@ -85,16 +85,24 @@
85
85
 
86
86
  NSNumber *tag = self.reactTag;
87
87
  NSMutableArray<NSNumber *> *descendantViewTags = [NSMutableArray new];
88
- [textStorage enumerateAttribute:RCTBaseTextShadowViewEmbeddedShadowViewAttributeName
89
- inRange:NSMakeRange(0, textStorage.length)
90
- options:0
91
- usingBlock:^(RCTShadowView *shadowView, NSRange range, __unused BOOL *stop) {
92
- if (!shadowView) {
93
- return;
94
- }
88
+ NSMutableArray<NSNumber *> *virtualSubviewTags = [NSMutableArray new]; // [macOS]
89
+
90
+ // [macOS - Enumerate embedded shadow views and virtual subviews in one loop
91
+ [textStorage enumerateAttributesInRange:NSMakeRange(0, textStorage.length)
92
+ options:0
93
+ usingBlock:^(NSDictionary<NSAttributedStringKey, id> *_Nonnull attrs, NSRange range, __unused BOOL * _Nonnull stop) {
94
+ id embeddedViewAttribute = attrs[RCTBaseTextShadowViewEmbeddedShadowViewAttributeName];
95
+ if ([embeddedViewAttribute isKindOfClass:[RCTShadowView class]]) {
96
+ RCTShadowView *embeddedShadowView = (RCTShadowView *)embeddedViewAttribute;
97
+ [descendantViewTags addObject:embeddedShadowView.reactTag];
98
+ }
95
99
 
96
- [descendantViewTags addObject:shadowView.reactTag];
97
- }];
100
+ id tagAttribute = attrs[RCTTextAttributesTagAttributeName];
101
+ if ([tagAttribute isKindOfClass:[NSNumber class]] && ![tagAttribute isEqualToNumber:tag]) {
102
+ [virtualSubviewTags addObject:tagAttribute];
103
+ }
104
+ }];
105
+ // macOS]
98
106
 
99
107
  [_bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTUIView *> *viewRegistry) { // [macOS]
100
108
  RCTTextView *textView = (RCTTextView *)viewRegistry[tag];
@@ -113,11 +121,25 @@
113
121
  [descendantViews addObject:descendantView];
114
122
  }];
115
123
 
124
+ // [macOS
125
+ NSMutableArray<RCTVirtualTextView *> *virtualSubviews = [NSMutableArray arrayWithCapacity:virtualSubviewTags.count];
126
+ [virtualSubviewTags
127
+ enumerateObjectsUsingBlock:^(NSNumber *_Nonnull virtualSubviewTag, NSUInteger index, BOOL *_Nonnull stop) {
128
+ RCTPlatformView *virtualSubview = viewRegistry[virtualSubviewTag];
129
+ if ([virtualSubview isKindOfClass:[RCTVirtualTextView class]]) {
130
+ [virtualSubviews addObject:(RCTVirtualTextView *)virtualSubview];
131
+ }
132
+ }];
133
+ // macOS]
134
+
116
135
  // Removing all references to Shadow Views to avoid unnecessary retaining.
117
136
  [textStorage removeAttribute:RCTBaseTextShadowViewEmbeddedShadowViewAttributeName
118
137
  range:NSMakeRange(0, textStorage.length)];
119
138
 
120
- [textView setTextStorage:textStorage contentFrame:contentFrame descendantViews:descendantViews];
139
+ [textView setTextStorage:textStorage
140
+ contentFrame:contentFrame
141
+ descendantViews:descendantViews
142
+ virtualSubviews:virtualSubviews]; // [macOS]
121
143
  }];
122
144
  }
123
145
 
@@ -7,6 +7,7 @@
7
7
 
8
8
  #import <React/RCTComponent.h>
9
9
  #import <React/RCTEventDispatcher.h> // [macOS]
10
+ #import <React/RCTVirtualTextView.h> // [macOS]
10
11
 
11
12
  #import <React/RCTUIKit.h> // [macOS]
12
13
 
@@ -22,6 +23,13 @@ NS_ASSUME_NONNULL_BEGIN
22
23
  contentFrame:(CGRect)contentFrame
23
24
  descendantViews:(NSArray<RCTPlatformView *> *)descendantViews; // [macOS]
24
25
 
26
+ // [macOS
27
+ - (void)setTextStorage:(NSTextStorage *)textStorage
28
+ contentFrame:(CGRect)contentFrame
29
+ descendantViews:(NSArray<RCTPlatformView *> *)descendantViews
30
+ virtualSubviews:(NSArray<RCTVirtualTextView *> *_Nullable)virtualSubviews;
31
+ // macOS]
32
+
25
33
  #if TARGET_OS_OSX // [macOS
26
34
  - (NSRect)getRectForCharRange:(NSRange)charRange;
27
35
  #endif // macOS]
@@ -12,6 +12,7 @@
12
12
  #endif // [macOS]
13
13
 
14
14
  #import <React/RCTAssert.h> // [macOS]
15
+ #import <React/RCTUIManager.h> // [macOS]
15
16
  #import <React/RCTUtils.h>
16
17
  #import <React/UIView+React.h>
17
18
  #import <React/RCTFocusChangeEvent.h> // [macOS]
@@ -62,6 +63,8 @@
62
63
 
63
64
  id<RCTEventDispatcherProtocol> _eventDispatcher; // [macOS]
64
65
  NSArray<RCTUIView *> *_Nullable _descendantViews; // [macOS]
66
+ NSArray<RCTVirtualTextView *> *_Nullable _virtualSubviews; // [macOS]
67
+ RCTUIView *_Nullable _currentHoveredSubview; // [macOS]
65
68
  NSTextStorage *_Nullable _textStorage;
66
69
  CGRect _contentFrame;
67
70
  }
@@ -99,6 +102,7 @@
99
102
  _textView.layoutManager.usesFontLeading = NO;
100
103
  _textStorage = _textView.textStorage;
101
104
  [self addSubview:_textView];
105
+ _currentHoveredSubview = nil;
102
106
  #endif // macOS]
103
107
  RCTUIViewSetContentModeRedraw(self); // [macOS]
104
108
  }
@@ -162,6 +166,20 @@
162
166
  contentFrame:(CGRect)contentFrame
163
167
  descendantViews:(NSArray<RCTPlatformView *> *)descendantViews // [macOS]
164
168
  {
169
+ // [macOS - to keep track of virtualSubviews as well
170
+ [self setTextStorage:textStorage
171
+ contentFrame:contentFrame
172
+ descendantViews:descendantViews
173
+ virtualSubviews:nil];
174
+ }
175
+
176
+ - (void)setTextStorage:(NSTextStorage *)textStorage
177
+ contentFrame:(CGRect)contentFrame
178
+ descendantViews:(NSArray<RCTPlatformView *> *)descendantViews
179
+ virtualSubviews:(NSArray<RCTVirtualTextView *> *)virtualSubviews
180
+ {
181
+ // macOS]
182
+
165
183
  // This lets the textView own its text storage on macOS
166
184
  // We update and replace the text container `_textView.textStorage.attributedString` when text/layout changes
167
185
  #if !TARGET_OS_OSX // [macOS]
@@ -204,6 +222,8 @@
204
222
  [self addSubview:view];
205
223
  }
206
224
 
225
+ _virtualSubviews = virtualSubviews; // [macOS]
226
+
207
227
  [self setNeedsDisplay];
208
228
  }
209
229
 
@@ -414,6 +434,21 @@
414
434
  }
415
435
  #else // [macOS
416
436
 
437
+ - (BOOL)hasMouseHoverEvent
438
+ {
439
+ if ([super hasMouseHoverEvent]) {
440
+ return YES;
441
+ }
442
+
443
+ // We only care about virtual subviews here.
444
+ // Embedded views (e.g., <Text> <View /> </Text>) handle mouse hover events themselves.
445
+ NSUInteger indexOfChildWithMouseHoverEvent = [_virtualSubviews indexOfObjectPassingTest:^BOOL(RCTVirtualTextView *_Nonnull childView, NSUInteger idx, BOOL *_Nonnull stop) {
446
+ *stop = [childView hasMouseHoverEvent];
447
+ return *stop;
448
+ }];
449
+ return indexOfChildWithMouseHoverEvent != NSNotFound;
450
+ }
451
+
417
452
  - (NSView *)hitTest:(NSPoint)point
418
453
  {
419
454
  // We will forward mouse click events to the NSTextView ourselves to prevent NSTextView from swallowing events that may be handled in JS (e.g. long press).
@@ -428,6 +463,110 @@
428
463
  return isTextViewClick ? self : hitView;
429
464
  }
430
465
 
466
+ - (NSNumber *)reactTagAtMouseLocationFromEvent:(NSEvent *)event
467
+ {
468
+ NSPoint locationInSelf = [self convertPoint:event.locationInWindow fromView:nil];
469
+ NSPoint locationInInnerTextView = [self convertPoint:locationInSelf toView:_textView]; // This is needed if the parent <Text> view has padding
470
+ return [self reactTagAtPoint:locationInInnerTextView];
471
+ }
472
+
473
+ - (void)mouseEntered:(NSEvent *)event
474
+ {
475
+ // superclass invokes self.onMouseEnter, so do this first
476
+ [super mouseEntered:event];
477
+
478
+ [self updateHoveredSubviewWithEvent:event];
479
+ }
480
+
481
+ - (void)mouseExited:(NSEvent *)event
482
+ {
483
+ [self updateHoveredSubviewWithEvent:event];
484
+
485
+ // superclass invokes self.onMouseLeave, so do this last
486
+ [super mouseExited:event];
487
+ }
488
+
489
+ - (void)mouseMoved:(NSEvent *)event
490
+ {
491
+ [super mouseMoved:event];
492
+ [self updateHoveredSubviewWithEvent:event];
493
+ }
494
+
495
+ - (void)updateHoveredSubviewWithEvent:(NSEvent *)event
496
+ {
497
+ RCTUIView *hoveredView = nil;
498
+
499
+ if ([event type] != NSEventTypeMouseExited && _virtualSubviews != nil) {
500
+ NSNumber *reactTagOfHoveredView = [self reactTagAtMouseLocationFromEvent:event];
501
+
502
+ if (reactTagOfHoveredView == nil) {
503
+ // This happens if we hover over an embedded view, which will handle its own mouse events
504
+ return;
505
+ }
506
+
507
+ if ([reactTagOfHoveredView isEqualToNumber:self.reactTag]) {
508
+ // We're hovering over the root Text element
509
+ hoveredView = self;
510
+ } else {
511
+ // Maybe we're hovering over a child Text element?
512
+ NSUInteger index = [_virtualSubviews indexOfObjectPassingTest:^BOOL(RCTVirtualTextView *_Nonnull view, NSUInteger idx, BOOL *_Nonnull stop) {
513
+ *stop = [[view reactTag] isEqualToNumber:reactTagOfHoveredView];
514
+ return *stop;
515
+ }];
516
+ if (index != NSNotFound) {
517
+ hoveredView = _virtualSubviews[index];
518
+ }
519
+ }
520
+ }
521
+
522
+ if (_currentHoveredSubview == hoveredView) {
523
+ return;
524
+ }
525
+
526
+ // self will always be an ancestor of any views we pass in here, so it serves as a good default option.
527
+ // Also, if we do set from/to nil, we have to call the relevant events on the entire subtree.
528
+ RCTUIManager *uiManager = [[_eventDispatcher bridge] uiManager];
529
+ RCTShadowView *oldShadowView = [uiManager shadowViewForReactTag:[(_currentHoveredSubview ?: self) reactTag]];
530
+ RCTShadowView *newShadowView = [uiManager shadowViewForReactTag:[(hoveredView ?: self) reactTag]];
531
+
532
+ // Find the common ancestor between the two shadow views
533
+ RCTShadowView *commonAncestor = [oldShadowView ancestorSharedWithShadowView:newShadowView];
534
+
535
+ for (RCTShadowView *exitedShadowView = oldShadowView; exitedShadowView != commonAncestor && exitedShadowView != nil; exitedShadowView = [exitedShadowView reactSuperview]) {
536
+ RCTPlatformView *exitedView = [uiManager viewForReactTag:[exitedShadowView reactTag]];
537
+ if (![exitedView isKindOfClass:[RCTUIView class]]) {
538
+ RCTLogError(@"Unexpected view of type %@ found in hierarchy, must be RCTUIView or subclass", [exitedView class]);
539
+ continue;
540
+ }
541
+
542
+ RCTUIView *exitedReactView = (RCTUIView *)exitedView;
543
+ [self sendMouseEventWithBlock:[exitedReactView onMouseLeave]
544
+ locationInfo:[self locationInfoFromEvent:event]
545
+ modifierFlags:event.modifierFlags
546
+ additionalData:nil];
547
+ }
548
+
549
+ // We cache these so we can call them from outermost to innermost
550
+ NSMutableArray<RCTUIView *> *enteredViewHierarchy = [NSMutableArray new];
551
+ for (RCTShadowView *enteredShadowView = newShadowView; enteredShadowView != commonAncestor && enteredShadowView != nil; enteredShadowView = [enteredShadowView reactSuperview]) {
552
+ RCTPlatformView *enteredView = [uiManager viewForReactTag:[enteredShadowView reactTag]];
553
+ if (![enteredView isKindOfClass:[RCTUIView class]]) {
554
+ RCTLogError(@"Unexpected view of type %@ found in hierarchy, must be RCTUIView or subclass", [enteredView class]);
555
+ continue;
556
+ }
557
+
558
+ [enteredViewHierarchy addObject:(RCTUIView *)enteredView];
559
+ }
560
+ for (NSInteger i = [enteredViewHierarchy count] - 1; i >= 0; i--) {
561
+ [self sendMouseEventWithBlock:[[enteredViewHierarchy objectAtIndex:i] onMouseEnter]
562
+ locationInfo:[self locationInfoFromEvent:event]
563
+ modifierFlags:event.modifierFlags
564
+ additionalData:nil];
565
+ }
566
+
567
+ _currentHoveredSubview = hoveredView;
568
+ }
569
+
431
570
  - (void)rightMouseDown:(NSEvent *)event
432
571
  {
433
572
 
@@ -406,6 +406,7 @@ CGPathRef UIBezierPathCreateCGPathRef(UIBezierPath *path);
406
406
  - (void)setNeedsDisplay;
407
407
 
408
408
  // Methods related to mouse events
409
+ - (BOOL)hasMouseHoverEvent;
409
410
  - (NSDictionary*)locationInfoFromDraggingLocation:(NSPoint)locationInWindow;
410
411
  - (NSDictionary*)locationInfoFromEvent:(NSEvent*)event;
411
412
 
@@ -23,7 +23,7 @@ NSDictionary* RCTGetReactNativeVersion(void)
23
23
  __rnVersion = @{
24
24
  RCTVersionMajor: @(0),
25
25
  RCTVersionMinor: @(73),
26
- RCTVersionPatch: @(32),
26
+ RCTVersionPatch: @(34),
27
27
  RCTVersionPrerelease: [NSNull null],
28
28
  };
29
29
  });
@@ -217,6 +217,7 @@ CGPathRef UIBezierPathCreateCGPathRef(UIBezierPath *bezierPath)
217
217
  BOOL _clipsToBounds;
218
218
  BOOL _hasMouseOver;
219
219
  BOOL _userInteractionEnabled;
220
+ NSTrackingArea *_trackingArea;
220
221
  BOOL _mouseDownCanMoveWindow;
221
222
  }
222
223
 
@@ -349,6 +350,13 @@ static RCTUIView *RCTUIViewCommonInit(RCTUIView *self)
349
350
  }
350
351
  }
351
352
 
353
+ - (BOOL)hasMouseHoverEvent
354
+ {
355
+ // This can be overridden by subclasses as needed.
356
+ // e.g., RCTTextView, which consolidates its JS children into a single gigantic NSAttributedString
357
+ return self.onMouseEnter || self.onMouseLeave;
358
+ }
359
+
352
360
  - (NSDictionary*)locationInfoFromDraggingLocation:(NSPoint)locationInWindow
353
361
  {
354
362
  NSPoint locationInView = [self convertPoint:locationInWindow fromView:nil];
@@ -425,6 +433,28 @@ static RCTUIView *RCTUIViewCommonInit(RCTUIView *self)
425
433
  block(body);
426
434
  }
427
435
 
436
+ - (void)updateTrackingAreas
437
+ {
438
+ BOOL hasMouseHoverEvent = [self hasMouseHoverEvent];
439
+ BOOL wouldRecreateIdenticalTrackingArea = hasMouseHoverEvent && _trackingArea && NSEqualRects(self.bounds, [_trackingArea rect]);
440
+
441
+ if (!wouldRecreateIdenticalTrackingArea) {
442
+ if (_trackingArea) {
443
+ [self removeTrackingArea:_trackingArea];
444
+ }
445
+
446
+ if (hasMouseHoverEvent) {
447
+ _trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds
448
+ options:NSTrackingActiveAlways|NSTrackingMouseEnteredAndExited
449
+ owner:self
450
+ userInfo:nil];
451
+ [self addTrackingArea:_trackingArea];
452
+ }
453
+ }
454
+
455
+ [super updateTrackingAreas];
456
+ }
457
+
428
458
  - (BOOL)mouseDownCanMoveWindow{
429
459
  return _mouseDownCanMoveWindow;
430
460
  }
@@ -241,6 +241,13 @@ typedef void (^RCTApplierBlock)(NSDictionary<NSNumber *, RCTPlatformView *> *vie
241
241
  */
242
242
  - (CGRect)measureLayoutRelativeToAncestor:(RCTShadowView *)ancestor;
243
243
 
244
+ // [macOS
245
+ /**
246
+ * Returns the closest ancestor shared by this shadow view and another specified shadow view.
247
+ */
248
+ - (RCTShadowView *)ancestorSharedWithShadowView:(RCTShadowView *)shadowView;
249
+ // macOS]
250
+
244
251
  /**
245
252
  * Checks if the current shadow view is a descendant of the provided `ancestor`
246
253
  */
@@ -182,6 +182,25 @@ static void RCTProcessMetaPropsBorder(const YGValue metaProps[META_PROP_COUNT],
182
182
  return (CGRect){offset, self.layoutMetrics.frame.size};
183
183
  }
184
184
 
185
+ // [macOS
186
+ - (RCTShadowView *)ancestorSharedWithShadowView:(RCTShadowView *)shadowView
187
+ {
188
+ // TODO: Can this be optimized by climbing up both hierarchies at the same time?
189
+ NSMutableSet<RCTShadowView *> *selfSuperviews = [NSMutableSet set];
190
+ for (RCTShadowView *view = self; view != nil; view = [view reactSuperview]) {
191
+ [selfSuperviews addObject:view];
192
+ }
193
+
194
+ for (RCTShadowView *candidateView = shadowView; candidateView != nil; candidateView = [candidateView reactSuperview]) {
195
+ if ([selfSuperviews containsObject:candidateView]) {
196
+ return candidateView;
197
+ }
198
+ }
199
+
200
+ return nil;
201
+ }
202
+ // macOS]
203
+
185
204
  - (BOOL)viewIsDescendantOf:(RCTShadowView *)ancestor
186
205
  {
187
206
  RCTShadowView *shadowView = self;
@@ -136,7 +136,6 @@ static NSString *RCTRecursiveAccessibilityLabel(RCTUIView *view) // [macOS]
136
136
  RCTUIColor *_backgroundColor; // [macOS]
137
137
  id<RCTEventDispatcherProtocol> _eventDispatcher; // [macOS]
138
138
  #if TARGET_OS_OSX // [macOS
139
- NSTrackingArea *_trackingArea;
140
139
  BOOL _mouseDownCanMoveWindow;
141
140
  #endif // macOS]
142
141
  NSMutableDictionary<NSString *, NSDictionary *> *accessibilityActionsNameMap;
@@ -1466,28 +1465,6 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
1466
1465
  return [self focusable] || [super acceptsFirstResponder];
1467
1466
  }
1468
1467
 
1469
- - (void)updateTrackingAreas
1470
- {
1471
- BOOL hasMouseHoverEvent = self.onMouseEnter || self.onMouseLeave;
1472
- BOOL wouldRecreateIdenticalTrackingArea = hasMouseHoverEvent && _trackingArea && NSEqualRects(self.bounds, [_trackingArea rect]);
1473
-
1474
- if (!wouldRecreateIdenticalTrackingArea) {
1475
- if (_trackingArea) {
1476
- [self removeTrackingArea:_trackingArea];
1477
- }
1478
-
1479
- if (hasMouseHoverEvent) {
1480
- _trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds
1481
- options:NSTrackingActiveAlways|NSTrackingMouseEnteredAndExited
1482
- owner:self
1483
- userInfo:nil];
1484
- [self addTrackingArea:_trackingArea];
1485
- }
1486
- }
1487
-
1488
- [super updateTrackingAreas];
1489
- }
1490
-
1491
1468
  - (BOOL)mouseDownCanMoveWindow{
1492
1469
  return _mouseDownCanMoveWindow;
1493
1470
  }
@@ -1,4 +1,4 @@
1
- VERSION_NAME=0.73.32
1
+ VERSION_NAME=0.73.34
2
2
  react.internal.publishingGroup=com.facebook.react
3
3
 
4
4
  android.useAndroidX=true
@@ -17,6 +17,6 @@ public class ReactNativeVersion {
17
17
  public static final Map<String, Object> VERSION = MapBuilder.<String, Object>of(
18
18
  "major", 0,
19
19
  "minor", 73,
20
- "patch", 32,
20
+ "patch", 34,
21
21
  "prerelease", null);
22
22
  }
@@ -17,7 +17,7 @@ namespace facebook::react {
17
17
  constexpr struct {
18
18
  int32_t Major = 0;
19
19
  int32_t Minor = 73;
20
- int32_t Patch = 32;
20
+ int32_t Patch = 34;
21
21
  std::string_view Prerelease = "";
22
22
  } ReactNativeVersion;
23
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-macos",
3
- "version": "0.73.32",
3
+ "version": "0.73.34",
4
4
  "description": "React Native for macOS",
5
5
  "license": "MIT",
6
6
  "repository": {