react-native-macos 0.0.0-b9fb2dd1a → 0.0.0-bc0c2c4d1

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 (100) hide show
  1. package/Libraries/Components/ScrollView/ScrollView.js +11 -45
  2. package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +1 -0
  3. package/Libraries/Components/TextInput/TextInput.js +79 -1
  4. package/Libraries/Components/View/ReactNativeStyleAttributes.js +1 -0
  5. package/Libraries/Components/View/ReactNativeViewAttributes.js +1 -0
  6. package/Libraries/Components/View/ReactNativeViewViewConfig.js +1 -0
  7. package/Libraries/Components/View/ReactNativeViewViewConfigMacOS.js +3 -3
  8. package/Libraries/Components/View/ViewPropTypes.js +10 -6
  9. package/Libraries/Core/ReactNativeVersion.js +1 -1
  10. package/Libraries/Image/RCTImageView.mm +14 -10
  11. package/Libraries/LinkingIOS/RCTLinkingManager.h +1 -0
  12. package/Libraries/LinkingIOS/macos/RCTLinkingManager.mm +12 -5
  13. package/Libraries/Lists/FlatList.js +25 -1
  14. package/Libraries/Lists/VirtualizedList.js +118 -113
  15. package/Libraries/Lists/VirtualizedSectionList.js +9 -5
  16. package/Libraries/StyleSheet/StyleSheetTypes.js +25 -0
  17. package/Libraries/Text/BaseText/RCTBaseTextViewManager.m +1 -0
  18. package/Libraries/Text/RCTTextAttributes.h +2 -0
  19. package/Libraries/Text/RCTTextAttributes.m +14 -5
  20. package/Libraries/Text/Text/RCTDynamicTypeRamp.h +40 -0
  21. package/Libraries/Text/Text/RCTDynamicTypeRamp.m +77 -0
  22. package/Libraries/Text/Text/RCTTextView.m +118 -47
  23. package/Libraries/Text/Text.js +0 -8
  24. package/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.h +8 -0
  25. package/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.m +57 -2
  26. package/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputViewManager.m +13 -0
  27. package/Libraries/Text/TextInput/Multiline/RCTUITextView.h +2 -1
  28. package/Libraries/Text/TextInput/Multiline/RCTUITextView.m +69 -2
  29. package/Libraries/Text/TextInput/RCTBackedTextInputDelegate.h +7 -1
  30. package/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m +12 -3
  31. package/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h +1 -0
  32. package/Libraries/Text/TextInput/RCTBaseTextInputView.h +4 -1
  33. package/Libraries/Text/TextInput/RCTBaseTextInputView.m +97 -2
  34. package/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m +6 -1
  35. package/Libraries/Text/TextInput/Singleline/RCTUITextField.m +40 -0
  36. package/Libraries/Text/TextNativeComponent.js +2 -0
  37. package/Libraries/Text/TextProps.js +29 -0
  38. package/Libraries/Types/CoreEventTypes.js +0 -1
  39. package/React/Base/RCTAssert.h +4 -3
  40. package/React/Base/RCTAssert.m +11 -2
  41. package/React/Base/RCTBridge.m +1 -1
  42. package/React/Base/RCTConstants.h +6 -0
  43. package/React/Base/RCTConstants.m +15 -0
  44. package/React/Base/RCTConvert.m +8 -4
  45. package/React/Base/RCTTouchHandler.m +4 -0
  46. package/React/Base/RCTUIKit.h +8 -13
  47. package/React/Base/RCTUtils.m +6 -3
  48. package/React/Base/RCTVersion.m +1 -1
  49. package/React/Base/macOS/RCTUIKit.m +40 -0
  50. package/React/CoreModules/RCTPerfMonitor.mm +1 -1
  51. package/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.mm +6 -2
  52. package/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm +1 -1
  53. package/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +17 -3
  54. package/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +8 -1
  55. package/React/Fabric/Mounting/RCTMountingManager.h +1 -1
  56. package/React/Fabric/Mounting/RCTMountingManager.mm +3 -3
  57. package/React/Fabric/RCTConversions.h +9 -1
  58. package/React/Fabric/RCTLocalizationProvider.mm +10 -4
  59. package/React/Fabric/RCTScheduler.h +5 -0
  60. package/React/Fabric/RCTScheduler.mm +10 -0
  61. package/React/Fabric/RCTSurfacePresenter.h +2 -0
  62. package/React/Fabric/RCTSurfacePresenter.mm +12 -11
  63. package/React/Fabric/RCTSurfaceTouchHandler.mm +0 -1
  64. package/React/Modules/RCTUIManager.m +2 -1
  65. package/React/React-RCTFabric.podspec +1 -1
  66. package/React/Views/RCTActivityIndicatorView.m +2 -1
  67. package/React/Views/RCTCursor.h +39 -0
  68. package/React/Views/RCTCursor.m +105 -0
  69. package/React/Views/RCTView.h +12 -0
  70. package/React/Views/RCTView.m +116 -43
  71. package/React/Views/RCTViewKeyboardEvent.m +9 -1
  72. package/React/Views/RCTViewManager.m +18 -13
  73. package/React/Views/ScrollView/RCTScrollContentView.h +4 -0
  74. package/React/Views/ScrollView/RCTScrollContentView.m +18 -0
  75. package/React/Views/ScrollView/RCTScrollContentViewManager.m +2 -0
  76. package/React/Views/ScrollView/RCTScrollView.h +2 -1
  77. package/React/Views/ScrollView/RCTScrollView.m +70 -63
  78. package/React/Views/ScrollView/RCTScrollViewManager.m +1 -1
  79. package/React/Views/UIView+React.h +2 -0
  80. package/React/Views/UIView+React.m +22 -13
  81. package/ReactAndroid/gradle.properties +1 -1
  82. package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java +1 -1
  83. package/ReactCommon/React-Fabric.podspec +1 -1
  84. package/ReactCommon/React-rncore.podspec +1 -1
  85. package/ReactCommon/cxxreact/ReactNativeVersion.h +1 -1
  86. package/ReactCommon/react/renderer/core/EventDispatcher.cpp +21 -0
  87. package/ReactCommon/react/renderer/core/EventDispatcher.h +15 -0
  88. package/ReactCommon/react/renderer/core/EventListener.cpp +39 -0
  89. package/ReactCommon/react/renderer/core/EventListener.h +44 -0
  90. package/ReactCommon/react/renderer/graphics/React-graphics.podspec +1 -1
  91. package/ReactCommon/react/renderer/scheduler/Scheduler.cpp +14 -0
  92. package/ReactCommon/react/renderer/scheduler/Scheduler.h +6 -0
  93. package/ReactCommon/react/utils/ManagedObjectWrapper.h +1 -1
  94. package/ReactCommon/react/utils/ManagedObjectWrapper.mm +1 -3
  95. package/package.json +1 -1
  96. package/scripts/generate-artifacts.js +21 -17
  97. package/scripts/react_native_pods.rb +0 -3
  98. package/template/Gemfile.lock +7 -7
  99. package/template/package.json +1 -1
  100. package/third-party-podspecs/boost-for-react-native.podspec +0 -20
@@ -165,6 +165,7 @@ static NSString *RCTRecursiveAccessibilityLabel(RCTUIView *view) // TODO(macOS I
165
165
  _hitTestEdgeInsets = UIEdgeInsetsZero;
166
166
  #if TARGET_OS_OSX // TODO(macOS GH#774)
167
167
  _transform3D = CATransform3DIdentity;
168
+ _shadowColor = nil;
168
169
  #endif // TODO(macOS GH#774)
169
170
 
170
171
  _backgroundColor = super.backgroundColor;
@@ -716,20 +717,49 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : unused)
716
717
  #endif // TODO(macOS GH#774)
717
718
 
718
719
  #if TARGET_OS_OSX // [TODO(macOS GH#774)
719
- // Workaround AppKit issue with directly manipulating the view layer's shadow.
720
- - (NSShadow*)shadow
720
+ - (void)setShadowColor:(NSColor *)shadowColor
721
721
  {
722
- CALayer *layer = self.layer;
723
- NSShadow *shadow = nil;
722
+ if (_shadowColor != shadowColor)
723
+ {
724
+ _shadowColor = shadowColor;
725
+ [self didUpdateShadow];
726
+ }
727
+ }
724
728
 
725
- if (layer.shadowColor != nil && layer.shadowOpacity > 0) {
726
- shadow = [NSShadow new];
729
+ - (void)setShadowOffset:(CGSize)shadowOffset
730
+ {
731
+ if (!CGSizeEqualToSize(_shadowOffset, shadowOffset))
732
+ {
733
+ _shadowOffset = shadowOffset;
734
+ [self didUpdateShadow];
735
+ }
736
+ }
727
737
 
728
- shadow.shadowColor = [[NSColor colorWithCGColor:layer.shadowColor] colorWithAlphaComponent:layer.shadowOpacity];
729
- shadow.shadowOffset = layer.shadowOffset;
730
- shadow.shadowBlurRadius = layer.shadowRadius;
731
- }
732
- return shadow;
738
+ - (void)setShadowOpacity:(CGFloat)shadowOpacity
739
+ {
740
+ if (_shadowOpacity != shadowOpacity)
741
+ {
742
+ _shadowOpacity = shadowOpacity;
743
+ [self didUpdateShadow];
744
+ }
745
+ }
746
+
747
+ - (void)setShadowRadius:(CGFloat)shadowRadius
748
+ {
749
+ if (_shadowRadius != shadowRadius)
750
+ {
751
+ _shadowRadius = shadowRadius;
752
+ [self didUpdateShadow];
753
+ }
754
+ }
755
+
756
+ -(void)didUpdateShadow
757
+ {
758
+ NSShadow *shadow = [NSShadow new];
759
+ shadow.shadowColor = [[self shadowColor] colorWithAlphaComponent:[self shadowOpacity]];
760
+ shadow.shadowOffset = [self shadowOffset];
761
+ shadow.shadowBlurRadius = [self shadowRadius];
762
+ [self setShadow:shadow];
733
763
  }
734
764
 
735
765
  - (void)viewDidMoveToWindow
@@ -749,6 +779,9 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : unused)
749
779
  name:NSViewBoundsDidChangeNotification
750
780
  object:[[self enclosingScrollView] contentView]];
751
781
  }
782
+
783
+ [self reactViewDidMoveToWindow]; // TODO(macOS GH#1412)
784
+
752
785
  [super viewDidMoveToWindow];
753
786
  }
754
787
 
@@ -758,16 +791,16 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : unused)
758
791
  // the mouseExited: event does not get called on the view where mouseEntered: was previously called.
759
792
  // This creates an unnatural pairing of mouse enter and exit events and can cause problems.
760
793
  // We therefore explicitly check for this here and handle them by calling the appropriate callbacks.
761
-
794
+
762
795
  if (!_hasMouseOver && self.onMouseEnter)
763
796
  {
764
797
  NSPoint locationInWindow = [[self window] mouseLocationOutsideOfEventStream];
765
798
  NSPoint locationInView = [self convertPoint:locationInWindow fromView:nil];
766
-
799
+
767
800
  if (NSPointInRect(locationInView, [self bounds]))
768
801
  {
769
802
  _hasMouseOver = YES;
770
-
803
+
771
804
  [self sendMouseEventWithBlock:self.onMouseEnter
772
805
  locationInfo:[self locationInfoFromDraggingLocation:locationInWindow]
773
806
  modifierFlags:0
@@ -778,11 +811,11 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : unused)
778
811
  {
779
812
  NSPoint locationInWindow = [[self window] mouseLocationOutsideOfEventStream];
780
813
  NSPoint locationInView = [self convertPoint:locationInWindow fromView:nil];
781
-
814
+
782
815
  if (!NSPointInRect(locationInView, [self bounds]))
783
816
  {
784
817
  _hasMouseOver = NO;
785
-
818
+
786
819
  [self sendMouseEventWithBlock:self.onMouseLeave
787
820
  locationInfo:[self locationInfoFromDraggingLocation:locationInWindow]
788
821
  modifierFlags:0
@@ -1381,6 +1414,15 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
1381
1414
  #pragma mark - macOS Event Handler
1382
1415
 
1383
1416
  #if TARGET_OS_OSX
1417
+ - (void)resetCursorRects
1418
+ {
1419
+ [self discardCursorRects];
1420
+ NSCursor *cursor = [RCTConvert NSCursor:self.cursor];
1421
+ if (cursor) {
1422
+ [self addCursorRect:self.bounds cursor:cursor];
1423
+ }
1424
+ }
1425
+
1384
1426
  - (void)setOnDoubleClick:(RCTDirectEventBlock)block
1385
1427
  {
1386
1428
  if (_onDoubleClick != block) {
@@ -1398,9 +1440,14 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
1398
1440
  }
1399
1441
  }
1400
1442
 
1443
+ - (BOOL)needsPanelToBecomeKey {
1444
+ // We need to override this so that mouse clicks don't move keyboard focus on focusable views by default.
1445
+ return false;
1446
+ }
1447
+
1401
1448
  - (BOOL)acceptsFirstResponder
1402
1449
  {
1403
- return ([self focusable] && [NSApp isFullKeyboardAccessEnabled]) || [super acceptsFirstResponder];
1450
+ return [self focusable] || [super acceptsFirstResponder];
1404
1451
  }
1405
1452
 
1406
1453
  - (void)updateTrackingAreas
@@ -1408,7 +1455,7 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
1408
1455
  if (_trackingArea) {
1409
1456
  [self removeTrackingArea:_trackingArea];
1410
1457
  }
1411
-
1458
+
1412
1459
  if (self.onMouseEnter || self.onMouseLeave) {
1413
1460
  _trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds
1414
1461
  options:NSTrackingActiveAlways|NSTrackingMouseEnteredAndExited
@@ -1416,7 +1463,7 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
1416
1463
  userInfo:nil];
1417
1464
  [self addTrackingArea:_trackingArea];
1418
1465
  }
1419
-
1466
+
1420
1467
  [super updateTrackingAreas];
1421
1468
  }
1422
1469
 
@@ -1442,7 +1489,7 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
1442
1489
  {
1443
1490
  NSPoint locationInWindow = event.locationInWindow;
1444
1491
  NSPoint locationInView = [self convertPoint:locationInWindow fromView:nil];
1445
-
1492
+
1446
1493
  return @{@"screenX": @(locationInWindow.x),
1447
1494
  @"screenY": @(locationInWindow.y),
1448
1495
  @"clientX": @(locationInView.x),
@@ -1473,25 +1520,21 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
1473
1520
  if (modifierFlags & NSEventModifierFlagCommand) {
1474
1521
  body[@"metaKey"] = @YES;
1475
1522
  }
1476
-
1523
+
1477
1524
  if (locationInfo) {
1478
1525
  [body addEntriesFromDictionary:locationInfo];
1479
1526
  }
1480
-
1527
+
1481
1528
  if (additionalData) {
1482
1529
  [body addEntriesFromDictionary:additionalData];
1483
1530
  }
1484
-
1531
+
1485
1532
  block(body);
1486
1533
  }
1487
1534
 
1488
- - (NSDictionary*)dataTransferInfoFromPastboard:(NSPasteboard*)pastboard
1535
+ - (NSDictionary*)dataTransferInfoFromPasteboard:(NSPasteboard*)pasteboard
1489
1536
  {
1490
- if (![pastboard.types containsObject:NSFilenamesPboardType]) {
1491
- return @{};
1492
- }
1493
-
1494
- NSArray *fileNames = [pastboard propertyListForType:NSFilenamesPboardType];
1537
+ NSArray *fileNames = [pasteboard propertyListForType:NSFilenamesPboardType] ?: @[];
1495
1538
  NSMutableArray *files = [[NSMutableArray alloc] initWithCapacity:fileNames.count];
1496
1539
  NSMutableArray *items = [[NSMutableArray alloc] initWithCapacity:fileNames.count];
1497
1540
  NSMutableArray *types = [[NSMutableArray alloc] initWithCapacity:fileNames.count];
@@ -1511,27 +1554,57 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
1511
1554
  MIMETypeString = (__bridge_transfer NSString *)MIMEType;
1512
1555
  }
1513
1556
  }
1514
-
1557
+
1515
1558
  NSNumber *fileSizeValue = nil;
1516
1559
  NSError *fileSizeError = nil;
1517
1560
  BOOL success = [fileURL getResourceValue:&fileSizeValue
1518
1561
  forKey:NSURLFileSizeKey
1519
1562
  error:&fileSizeError];
1520
-
1563
+
1564
+ NSNumber *width = nil;
1565
+ NSNumber *height = nil;
1566
+ if ([MIMETypeString hasPrefix:@"image/"]) {
1567
+ NSImage *image = [[NSImage alloc] initWithContentsOfURL:fileURL];
1568
+ width = @(image.size.width);
1569
+ height = @(image.size.height);
1570
+ }
1571
+
1521
1572
  [files addObject:@{@"name": RCTNullIfNil(fileURL.lastPathComponent),
1522
1573
  @"type": RCTNullIfNil(MIMETypeString),
1523
- @"uri": RCTNullIfNil(fileURL.absoluteString),
1524
- @"size": success ? fileSizeValue : (id)kCFNull
1574
+ @"uri": RCTNullIfNil(fileURL.path),
1575
+ @"size": success ? fileSizeValue : (id)kCFNull,
1576
+ @"width": RCTNullIfNil(width),
1577
+ @"height": RCTNullIfNil(height)
1525
1578
  }];
1526
-
1579
+
1527
1580
  [items addObject:@{@"kind": @"file",
1528
1581
  @"type": RCTNullIfNil(MIMETypeString),
1529
1582
  }];
1530
-
1583
+
1531
1584
  [types addObject:RCTNullIfNil(MIMETypeString)];
1532
1585
  }
1533
1586
  }
1534
-
1587
+
1588
+ NSPasteboardType imageType = [pasteboard availableTypeFromArray:@[NSPasteboardTypePNG, NSPasteboardTypeTIFF]];
1589
+ if (imageType && fileNames.count == 0) {
1590
+ NSString *MIMETypeString = imageType == NSPasteboardTypePNG ? @"image/png" : @"image/tiff";
1591
+ NSData *imageData = [pasteboard dataForType:imageType];
1592
+ NSImage *image = [[NSImage alloc] initWithData:imageData];
1593
+
1594
+ [files addObject:@{@"type": RCTNullIfNil(MIMETypeString),
1595
+ @"uri": RCTDataURL(MIMETypeString, imageData).absoluteString,
1596
+ @"size": @(imageData.length),
1597
+ @"width": @(image.size.width),
1598
+ @"height": @(image.size.height),
1599
+ }];
1600
+
1601
+ [items addObject:@{@"kind": @"image",
1602
+ @"type": RCTNullIfNil(MIMETypeString),
1603
+ }];
1604
+
1605
+ [types addObject:RCTNullIfNil(MIMETypeString)];
1606
+ }
1607
+
1535
1608
  return @{@"dataTransfer": @{@"files": files,
1536
1609
  @"items": items,
1537
1610
  @"types": types}};
@@ -1540,7 +1613,7 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
1540
1613
  - (NSDictionary*)locationInfoFromDraggingLocation:(NSPoint)locationInWindow
1541
1614
  {
1542
1615
  NSPoint locationInView = [self convertPoint:locationInWindow fromView:nil];
1543
-
1616
+
1544
1617
  return @{@"screenX": @(locationInWindow.x),
1545
1618
  @"screenY": @(locationInWindow.y),
1546
1619
  @"clientX": @(locationInView.x),
@@ -1552,13 +1625,13 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
1552
1625
  {
1553
1626
  NSPasteboard *pboard = sender.draggingPasteboard;
1554
1627
  NSDragOperation sourceDragMask = sender.draggingSourceOperationMask;
1555
-
1628
+
1556
1629
  [self sendMouseEventWithBlock:self.onDragEnter
1557
1630
  locationInfo:[self locationInfoFromDraggingLocation:sender.draggingLocation]
1558
1631
  modifierFlags:0
1559
- additionalData:[self dataTransferInfoFromPastboard:pboard]];
1560
-
1561
- if ([pboard.types containsObject:NSFilenamesPboardType]) {
1632
+ additionalData:[self dataTransferInfoFromPasteboard:pboard]];
1633
+
1634
+ if ([pboard availableTypeFromArray:self.registeredDraggedTypes]) {
1562
1635
  if (sourceDragMask & NSDragOperationLink) {
1563
1636
  return NSDragOperationLink;
1564
1637
  } else if (sourceDragMask & NSDragOperationCopy) {
@@ -1573,7 +1646,7 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
1573
1646
  [self sendMouseEventWithBlock:self.onDragLeave
1574
1647
  locationInfo:[self locationInfoFromDraggingLocation:sender.draggingLocation]
1575
1648
  modifierFlags:0
1576
- additionalData:[self dataTransferInfoFromPastboard:sender.draggingPasteboard]];
1649
+ additionalData:[self dataTransferInfoFromPasteboard:sender.draggingPasteboard]];
1577
1650
  }
1578
1651
 
1579
1652
  - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
@@ -1581,7 +1654,7 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
1581
1654
  [self sendMouseEventWithBlock:self.onDrop
1582
1655
  locationInfo:[self locationInfoFromDraggingLocation:sender.draggingLocation]
1583
1656
  modifierFlags:0
1584
- additionalData:[self dataTransferInfoFromPastboard:[sender draggingPasteboard]]];
1657
+ additionalData:[self dataTransferInfoFromPasteboard:sender.draggingPasteboard]];
1585
1658
  return YES;
1586
1659
  }
1587
1660
  #endif // ]TODO(macOS GH#774)
@@ -52,7 +52,15 @@
52
52
  return @"Backspace";
53
53
  } else if (code == NSDeleteFunctionKey) {
54
54
  return @"Delete";
55
- }
55
+ } else if (code == NSHomeFunctionKey) {
56
+ return @"Home";
57
+ } else if (code == NSEndFunctionKey) {
58
+ return @"End";
59
+ } else if (code == NSPageUpFunctionKey) {
60
+ return @"PageUp";
61
+ } else if (code == NSPageDownFunctionKey) {
62
+ return @"PageDown";
63
+ }
56
64
 
57
65
  return key;
58
66
  }
@@ -21,6 +21,10 @@
21
21
  #import "RCTView.h"
22
22
  #import "UIView+React.h"
23
23
 
24
+ #if TARGET_OS_OSX // TODO(macOS GH#774)
25
+ #import "RCTCursor.h"
26
+ #endif // TODO(macOS GH774)
27
+
24
28
  #if !TARGET_OS_OSX // TODO(macOS GH#774)
25
29
  @implementation RCTConvert (UIAccessibilityTraits)
26
30
 
@@ -51,6 +55,7 @@ RCT_MULTI_ENUM_CONVERTER(
51
55
  // a set of RN accessibilityTraits are macOS specific accessiblity roles and map to nothing on iOS:
52
56
  @"disclosure" : @(UIAccessibilityTraitNone),
53
57
  @"group" : @(UIAccessibilityTraitNone),
58
+ @"table": @(UIAccessibilityTraitNone),
54
59
  // ]TODO(macOS GH#774)
55
60
  @"alert" : @(UIAccessibilityTraitNone),
56
61
  @"checkbox" : @(UIAccessibilityTraitNone),
@@ -90,7 +95,7 @@ RCT_EXPORT_MODULE()
90
95
 
91
96
  - (void)setBridge:(RCTBridge *)bridge
92
97
  {
93
- RCTWarnNotAllowedForNewArchitecture(self, @"RCTViewManager must not be initialized for the new architecture");
98
+ RCTErrorNotAllowedForNewArchitecture(self, @"RCTViewManager must not be initialized for the new architecture");
94
99
  _bridge = bridge;
95
100
  }
96
101
 
@@ -191,10 +196,19 @@ RCT_REMAP_VIEW_PROPERTY(opacity, alpha, CGFloat)
191
196
  #else // [TODO(macOS GH#774)
192
197
  RCT_REMAP_VIEW_PROPERTY(opacity, alphaValue, CGFloat)
193
198
  #endif // ]TODO(macOS GH#774)
199
+
200
+ #if !TARGET_OS_OSX // TODO(macOS GH#774)
194
201
  RCT_REMAP_VIEW_PROPERTY(shadowColor, layer.shadowColor, CGColor)
195
202
  RCT_REMAP_VIEW_PROPERTY(shadowOffset, layer.shadowOffset, CGSize)
196
203
  RCT_REMAP_VIEW_PROPERTY(shadowOpacity, layer.shadowOpacity, float)
197
204
  RCT_REMAP_VIEW_PROPERTY(shadowRadius, layer.shadowRadius, CGFloat)
205
+ #else // [TODO(macOS GH#774)
206
+ RCT_EXPORT_VIEW_PROPERTY(shadowColor, NSColor)
207
+ RCT_EXPORT_VIEW_PROPERTY(shadowOffset, CGSize)
208
+ RCT_EXPORT_VIEW_PROPERTY(shadowOpacity, CGFloat)
209
+ RCT_EXPORT_VIEW_PROPERTY(shadowRadius, CGFloat)
210
+ #endif // ]TODO(macOS GH#774)
211
+
198
212
  RCT_REMAP_VIEW_PROPERTY(needsOffscreenAlphaCompositing, layer.allowsGroupOpacity, BOOL)
199
213
  RCT_CUSTOM_VIEW_PROPERTY(overflow, YGOverflow, RCTView)
200
214
  {
@@ -471,6 +485,7 @@ RCT_EXPORT_VIEW_PROPERTY(onBlur, RCTBubblingEventBlock)
471
485
  #if TARGET_OS_OSX // [TODO(macOS GH#774)
472
486
  #pragma mark - macOS properties
473
487
 
488
+ RCT_EXPORT_VIEW_PROPERTY(cursor, RCTCursor)
474
489
  RCT_EXPORT_VIEW_PROPERTY(onDoubleClick, RCTDirectEventBlock)
475
490
  RCT_EXPORT_VIEW_PROPERTY(onClick, RCTDirectEventBlock)
476
491
  RCT_EXPORT_VIEW_PROPERTY(onMouseEnter, RCTDirectEventBlock)
@@ -480,18 +495,8 @@ RCT_EXPORT_VIEW_PROPERTY(onDragLeave, RCTDirectEventBlock)
480
495
  RCT_EXPORT_VIEW_PROPERTY(onDrop, RCTDirectEventBlock)
481
496
  RCT_EXPORT_VIEW_PROPERTY(onKeyDown, RCTDirectEventBlock) // macOS keyboard events
482
497
  RCT_EXPORT_VIEW_PROPERTY(onKeyUp, RCTDirectEventBlock) // macOS keyboard events
483
- RCT_CUSTOM_VIEW_PROPERTY(validKeysDown, NSArray<NSString*>, RCTView)
484
- {
485
- if ([view respondsToSelector:@selector(setValidKeysDown:)]) {
486
- view.validKeysDown = [RCTConvert NSArray:json];
487
- }
488
- }
489
- RCT_CUSTOM_VIEW_PROPERTY(validKeysUp, NSArray<NSString*>, RCTView)
490
- {
491
- if ([view respondsToSelector:@selector(setValidKeysUp:)]) {
492
- view.validKeysUp = [RCTConvert NSArray:json];
493
- }
494
- }
498
+ RCT_EXPORT_VIEW_PROPERTY(validKeysDown, NSArray<NSString*>)
499
+ RCT_EXPORT_VIEW_PROPERTY(validKeysUp, NSArray<NSString*>)
495
500
  #endif // ]TODO(macOS GH#774)
496
501
  #if TARGET_OS_OSX // [TODO(macOS GH#768)
497
502
  RCT_CUSTOM_VIEW_PROPERTY(nextKeyViewTag, NSNumber, RCTView)
@@ -11,4 +11,8 @@
11
11
 
12
12
  @interface RCTScrollContentView : RCTView
13
13
 
14
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
15
+ @property (nonatomic, assign, getter=isInverted) BOOL inverted;
16
+ #endif // ]TODO(macOS GH#774)
17
+
14
18
  @end
@@ -18,6 +18,12 @@
18
18
  #import "RCTScrollView.h"
19
19
 
20
20
  @implementation RCTScrollContentView
21
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
22
+ - (BOOL)isFlipped
23
+ {
24
+ return !self.inverted;
25
+ }
26
+ #endif // ]TODO(macOS GH#774)
21
27
 
22
28
  - (void)reactSetFrame:(CGRect)frame
23
29
  {
@@ -54,6 +60,18 @@
54
60
  horizontalScrollerHeight:verticalScrollerWidth];
55
61
  [[[scrollView bridge] uiManager] setLocalData:localData forView:self];
56
62
  }
63
+
64
+ if ([platformScrollView accessibilityRole] == NSAccessibilityTableRole) {
65
+ NSMutableArray *subViews = [[NSMutableArray alloc] initWithCapacity:[[self subviews] count]];
66
+ for (NSView *view in [self subviews]) {
67
+ if ([view isKindOfClass:[RCTView class]]) {
68
+ [subViews addObject:view];
69
+ }
70
+ }
71
+
72
+ [platformScrollView setAccessibilityRows:subViews];
73
+ }
74
+
57
75
  #endif // ]TODO(macOS GH#774)
58
76
  }
59
77
 
@@ -14,6 +14,8 @@
14
14
 
15
15
  RCT_EXPORT_MODULE()
16
16
 
17
+ RCT_EXPORT_OSX_VIEW_PROPERTY(inverted, BOOL) // TODO(macOS GH#774)
18
+
17
19
  - (RCTScrollContentView *)view
18
20
  {
19
21
  return [RCTScrollContentView new];
@@ -65,9 +65,10 @@
65
65
  @property (nonatomic, copy) RCTDirectEventBlock onScrollEndDrag;
66
66
  @property (nonatomic, copy) RCTDirectEventBlock onMomentumScrollBegin;
67
67
  @property (nonatomic, copy) RCTDirectEventBlock onMomentumScrollEnd;
68
- @property (nonatomic, copy) RCTDirectEventBlock onScrollKeyDown; // TODO(macOS GH#774)
69
68
  @property (nonatomic, copy) RCTDirectEventBlock onPreferredScrollerStyleDidChange; // TODO(macOS GH#774)
70
69
 
70
+ @property (nonatomic, copy) RCTDirectEventBlock onInvertedDidChange; // TODO(macOS GH#774)
71
+
71
72
  - (void)flashScrollIndicators; // TODO(macOS GH#774)
72
73
 
73
74
  @end
@@ -23,6 +23,8 @@
23
23
 
24
24
  #if !TARGET_OS_OSX // TODO(macOS GH#774)
25
25
  #import "RCTRefreshControl.h"
26
+ #else
27
+ #import "RCTViewKeyboardEvent.h"
26
28
  #endif // TODO(macOS GH#774)
27
29
 
28
30
  /**
@@ -43,6 +45,7 @@
43
45
  @property (nonatomic, assign) BOOL pinchGestureEnabled;
44
46
  #else // [TODO(macOS GH#774)
45
47
  + (BOOL)isCompatibleWithResponsiveScrolling;
48
+ @property (nonatomic, assign, getter=isInverted) BOOL inverted;
46
49
  @property (nonatomic, assign, getter=isScrollEnabled) BOOL scrollEnabled;
47
50
  @property (nonatomic, strong) NSPanGestureRecognizer *panGestureRecognizer;
48
51
  #endif // ]TODO(macOS GH#774)
@@ -106,9 +109,14 @@
106
109
  return YES;
107
110
  }
108
111
 
112
+ - (BOOL)isFlipped
113
+ {
114
+ return !self.inverted;
115
+ }
116
+
109
117
  - (void)scrollWheel:(NSEvent *)theEvent
110
118
  {
111
- if (!self.scrollEnabled) {
119
+ if (!self.isScrollEnabled) {
112
120
  [[self nextResponder] scrollWheel:theEvent];
113
121
  return;
114
122
  }
@@ -549,6 +557,20 @@ static inline UIViewAnimationOptions animationOptionsWithCurve(UIViewAnimationCu
549
557
  {
550
558
  [_scrollView setAccessibilityLabel:accessibilityLabel];
551
559
  }
560
+
561
+ - (void)setAccessibilityRole:(NSAccessibilityRole)accessibilityRole
562
+ {
563
+ [_scrollView setAccessibilityRole:accessibilityRole];
564
+ }
565
+
566
+ - (void)setInverted:(BOOL)inverted
567
+ {
568
+ BOOL changed = _inverted != inverted;
569
+ _inverted = inverted;
570
+ if (changed && _onInvertedDidChange) {
571
+ _onInvertedDidChange(@{});
572
+ }
573
+ }
552
574
  #endif // ]TODO(macOS GH#774)
553
575
 
554
576
  RCT_NOT_IMPLEMENTED(-(instancetype)initWithFrame : (CGRect)frame)
@@ -1256,74 +1278,58 @@ RCT_SCROLL_EVENT_HANDLER(scrollViewDidScrollToTop, onScrollToTop)
1256
1278
  }];
1257
1279
  }
1258
1280
 
1259
- #if TARGET_OS_OSX // [TODO(macOS GH#774)
1260
-
1261
- - (NSString*)keyCommandFromKeyCode:(NSInteger)keyCode modifierFlags:(NSEventModifierFlags)modifierFlags
1262
- {
1263
- switch (keyCode)
1264
- {
1265
- case 36:
1266
- return @"ENTER";
1267
-
1268
- case 115:
1269
- return @"HOME";
1270
-
1271
- case 116:
1272
- return @"PAGE_UP";
1273
-
1274
- case 119:
1275
- return @"END";
1276
-
1277
- case 121:
1278
- return @"PAGE_DOWN";
1279
-
1280
- case 123:
1281
- return @"LEFT_ARROW";
1282
-
1283
- case 124:
1284
- return @"RIGHT_ARROW";
1281
+ // [TODO(macOS GH#774)
1282
+ #pragma mark - Keyboard Events
1285
1283
 
1286
- case 125:
1287
- if (modifierFlags & NSEventModifierFlagOption) {
1288
- return @"OPTION_DOWN";
1289
- } else {
1290
- return @"DOWN_ARROW";
1291
- }
1284
+ #if TARGET_OS_OSX
1285
+ - (RCTViewKeyboardEvent*)keyboardEvent:(NSEvent*)event {
1286
+ BOOL keyDown = event.type == NSEventTypeKeyDown;
1287
+ NSArray<NSString *> *validKeys = keyDown ? self.validKeysDown : self.validKeysUp;
1288
+ NSString *key = [RCTViewKeyboardEvent keyFromEvent:event];
1289
+
1290
+ // Only post events for keys we care about
1291
+ if (![validKeys containsObject:key]) {
1292
+ return nil;
1293
+ }
1292
1294
 
1293
- case 126:
1294
- if (modifierFlags & NSEventModifierFlagOption) {
1295
- return @"OPTION_UP";
1296
- } else {
1297
- return @"UP_ARROW";
1298
- }
1299
- }
1300
- return @"";
1295
+ return [RCTViewKeyboardEvent keyEventFromEvent:event reactTag:self.reactTag];
1301
1296
  }
1302
1297
 
1303
- - (void)keyDown:(UIEvent*)theEvent
1304
- {
1305
- // Don't emit a scroll event if tab was pressed while the scrollview is first responder
1306
- if (!(self == [[self window] firstResponder] && theEvent.keyCode == 48)) {
1307
- NSString *keyCommand = [self keyCommandFromKeyCode:theEvent.keyCode modifierFlags:theEvent.modifierFlags];
1308
- if (![keyCommand isEqual: @""]) {
1309
- RCT_SEND_SCROLL_EVENT(onScrollKeyDown, (@{ @"key": keyCommand}));
1310
- } else {
1311
- [super keyDown:theEvent];
1298
+ - (BOOL)handleKeyboardEvent:(NSEvent *)event {
1299
+ if (event.type == NSEventTypeKeyDown ? self.onKeyDown : self.onKeyUp) {
1300
+ RCTViewKeyboardEvent *keyboardEvent = [self keyboardEvent:event];
1301
+ if (keyboardEvent) {
1302
+ [_eventDispatcher sendEvent:keyboardEvent];
1303
+ return YES;
1312
1304
  }
1313
1305
  }
1306
+ return NO;
1307
+ }
1308
+
1309
+ - (void)keyDown:(NSEvent *)event {
1310
+ if (![self handleKeyboardEvent:event]) {
1311
+ [super keyDown:event];
1312
+
1313
+ // AX: if a tab key was pressed and the first responder is currently clipped by the scroll view,
1314
+ // automatically scroll to make the view visible to make it navigable via keyboard.
1315
+ NSString *key = [RCTViewKeyboardEvent keyFromEvent:event];
1316
+ if ([key isEqualToString:@"Tab"]) {
1317
+ id firstResponder = [[self window] firstResponder];
1318
+ if ([firstResponder isKindOfClass:[NSView class]] &&
1319
+ [firstResponder isDescendantOf:[_scrollView documentView]]) {
1320
+ NSView *view = (NSView*)firstResponder;
1321
+ NSRect visibleRect = ([view superview] == [_scrollView documentView]) ? NSInsetRect(view.frame, -1, -1) :
1322
+ [view convertRect:view.frame toView:_scrollView.documentView];
1323
+ [[_scrollView documentView] scrollRectToVisible:visibleRect];
1324
+ }
1325
+ }
1326
+ }
1327
+ }
1314
1328
 
1315
- // AX: if a tab key was pressed and the first responder is currently clipped by the scroll view,
1316
- // automatically scroll to make the view visible to make it navigable via keyboard.
1317
- if ([theEvent keyCode] == 48) { //tab key
1318
- id firstResponder = [[self window] firstResponder];
1319
- if ([firstResponder isKindOfClass:[NSView class]] &&
1320
- [firstResponder isDescendantOf:[_scrollView documentView]]) {
1321
- NSView *view = (NSView*)firstResponder;
1322
- NSRect visibleRect = ([view superview] == [_scrollView documentView]) ? NSInsetRect(view.frame, -1, -1) :
1323
- [view convertRect:view.frame toView:_scrollView.documentView];
1324
- [[_scrollView documentView] scrollRectToVisible:visibleRect];
1325
- }
1326
- }
1329
+ - (void)keyUp:(NSEvent *)event {
1330
+ if (![self handleKeyboardEvent:event]) {
1331
+ [super keyUp:event];
1332
+ }
1327
1333
  }
1328
1334
 
1329
1335
  static NSString *RCTStringForScrollerStyle(NSScrollerStyle scrollerStyle) {
@@ -1338,7 +1344,8 @@ static NSString *RCTStringForScrollerStyle(NSScrollerStyle scrollerStyle) {
1338
1344
  - (void)preferredScrollerStyleDidChange:(__unused NSNotification *)notification {
1339
1345
  RCT_SEND_SCROLL_EVENT(onPreferredScrollerStyleDidChange, (@{ @"preferredScrollerStyle": RCTStringForScrollerStyle([NSScroller preferredScrollerStyle])}));
1340
1346
  }
1341
- #endif // ]TODO(macOS GH#774)
1347
+ #endif
1348
+ // ]TODO(macOS GH#774)
1342
1349
 
1343
1350
  // Note: setting several properties of UIScrollView has the effect of
1344
1351
  // resetting its contentOffset to {0, 0}. To prevent this, we generate
@@ -99,7 +99,7 @@ RCT_EXPORT_VIEW_PROPERTY(onScrollToTop, RCTDirectEventBlock)
99
99
  RCT_EXPORT_VIEW_PROPERTY(onScrollEndDrag, RCTDirectEventBlock)
100
100
  RCT_EXPORT_VIEW_PROPERTY(onMomentumScrollBegin, RCTDirectEventBlock)
101
101
  RCT_EXPORT_VIEW_PROPERTY(onMomentumScrollEnd, RCTDirectEventBlock)
102
- RCT_EXPORT_OSX_VIEW_PROPERTY(onScrollKeyDown, RCTDirectEventBlock) // TODO(macOS GH#774)
102
+ RCT_EXPORT_OSX_VIEW_PROPERTY(onInvertedDidChange, RCTDirectEventBlock) // TODO(macOS GH#774)
103
103
  RCT_EXPORT_OSX_VIEW_PROPERTY(onPreferredScrollerStyleDidChange, RCTDirectEventBlock) // TODO(macOS GH#774)
104
104
  RCT_EXPORT_VIEW_PROPERTY(inverted, BOOL)
105
105
  #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */
@@ -91,6 +91,8 @@
91
91
  - (void)reactAddControllerToClosestParent:(UIViewController *)controller;
92
92
  #endif // TODO(macOS GH#774)
93
93
 
94
+ - (void)reactViewDidMoveToWindow; // TODO(macOS GH#1412)
95
+
94
96
  /**
95
97
  * Focus manipulation.
96
98
  */