react-native-macos 0.0.0-96be39d8c → 0.0.0-96f71c939

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 (111) 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/ReactNativeViewAttributes.js +1 -0
  5. package/Libraries/Components/View/ViewPropTypes.js +10 -6
  6. package/Libraries/Core/ReactNativeVersion.js +1 -1
  7. package/Libraries/Image/RCTImageView.mm +14 -10
  8. package/Libraries/Lists/FlatList.js +25 -2
  9. package/Libraries/Lists/VirtualizedList.js +118 -113
  10. package/Libraries/Lists/VirtualizedSectionList.js +9 -5
  11. package/Libraries/Text/BaseText/RCTBaseTextViewManager.m +1 -0
  12. package/Libraries/Text/RCTTextAttributes.h +2 -0
  13. package/Libraries/Text/RCTTextAttributes.m +9 -0
  14. package/Libraries/Text/Text/RCTDynamicTypeRamp.h +40 -0
  15. package/Libraries/Text/Text/RCTDynamicTypeRamp.m +77 -0
  16. package/Libraries/Text/Text/RCTTextView.m +123 -54
  17. package/Libraries/Text/Text.js +0 -8
  18. package/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.h +8 -0
  19. package/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.m +57 -4
  20. package/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputViewManager.m +13 -0
  21. package/Libraries/Text/TextInput/Multiline/RCTUITextView.h +2 -1
  22. package/Libraries/Text/TextInput/Multiline/RCTUITextView.m +69 -2
  23. package/Libraries/Text/TextInput/RCTBackedTextInputDelegate.h +7 -1
  24. package/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m +12 -3
  25. package/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h +1 -0
  26. package/Libraries/Text/TextInput/RCTBaseTextInputView.h +4 -1
  27. package/Libraries/Text/TextInput/RCTBaseTextInputView.m +97 -2
  28. package/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m +6 -1
  29. package/Libraries/Text/TextInput/Singleline/RCTUITextField.m +40 -0
  30. package/Libraries/Text/TextNativeComponent.js +2 -0
  31. package/Libraries/Text/TextProps.js +29 -0
  32. package/Libraries/Types/CoreEventTypes.js +0 -1
  33. package/React/Base/RCTAssert.h +30 -15
  34. package/React/Base/RCTAssert.m +59 -19
  35. package/React/Base/RCTBridge.m +5 -3
  36. package/React/Base/RCTConstants.h +6 -0
  37. package/React/Base/RCTConstants.m +15 -0
  38. package/React/Base/RCTConvert.m +7 -4
  39. package/React/Base/RCTEventDispatcherProtocol.h +5 -0
  40. package/React/Base/RCTTouchHandler.m +4 -0
  41. package/React/Base/RCTUIKit.h +8 -13
  42. package/React/Base/RCTUtils.m +6 -3
  43. package/React/Base/RCTVersion.m +1 -1
  44. package/React/Base/macOS/RCTUIKit.m +33 -0
  45. package/React/CoreModules/RCTEventDispatcher.mm +6 -1
  46. package/React/CoreModules/RCTPerfMonitor.mm +1 -1
  47. package/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.h +1 -0
  48. package/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.mm +69 -19
  49. package/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm +2 -1
  50. package/React/Fabric/Mounting/ComponentViews/SafeAreaView/RCTSafeAreaViewComponentView.mm +0 -1
  51. package/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm +1 -1
  52. package/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +35 -9
  53. package/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +9 -1
  54. package/React/Fabric/Mounting/RCTComponentViewFactory.mm +12 -3
  55. package/React/Fabric/Mounting/RCTMountingManager.h +1 -1
  56. package/React/Fabric/Mounting/RCTMountingManager.mm +11 -9
  57. package/React/Fabric/Mounting/RCTMountingTransactionObserverCoordinator.h +5 -3
  58. package/React/Fabric/Mounting/RCTMountingTransactionObserverCoordinator.mm +10 -8
  59. package/React/Fabric/Mounting/RCTMountingTransactionObserving.h +5 -3
  60. package/React/Fabric/RCTConversions.h +9 -1
  61. package/React/Fabric/RCTLocalizationProvider.mm +10 -4
  62. package/React/Fabric/RCTScheduler.h +7 -0
  63. package/React/Fabric/RCTScheduler.mm +15 -0
  64. package/React/Fabric/RCTSurfacePresenter.h +2 -0
  65. package/React/Fabric/RCTSurfacePresenter.mm +45 -21
  66. package/React/Fabric/RCTSurfaceTouchHandler.mm +0 -1
  67. package/React/Modules/RCTUIManager.m +4 -2
  68. package/React/React-RCTFabric.podspec +1 -1
  69. package/React/Views/RCTActivityIndicatorView.m +2 -1
  70. package/React/Views/RCTView.h +1 -0
  71. package/React/Views/RCTView.m +51 -17
  72. package/React/Views/RCTViewKeyboardEvent.m +9 -1
  73. package/React/Views/RCTViewManager.m +5 -14
  74. package/React/Views/ScrollView/RCTScrollContentView.h +4 -0
  75. package/React/Views/ScrollView/RCTScrollContentView.m +6 -0
  76. package/React/Views/ScrollView/RCTScrollContentViewManager.m +2 -0
  77. package/React/Views/ScrollView/RCTScrollView.h +2 -1
  78. package/React/Views/ScrollView/RCTScrollView.m +65 -63
  79. package/React/Views/ScrollView/RCTScrollViewManager.m +1 -1
  80. package/React/Views/UIView+React.h +2 -0
  81. package/React/Views/UIView+React.m +22 -13
  82. package/ReactAndroid/gradle.properties +1 -1
  83. package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java +1 -1
  84. package/ReactCommon/React-Fabric.podspec +1 -1
  85. package/ReactCommon/React-rncore.podspec +1 -1
  86. package/ReactCommon/cxxreact/ReactNativeVersion.h +1 -1
  87. package/ReactCommon/react/debug/react_native_assert.h +1 -1
  88. package/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropComponentDescriptor.mm +5 -0
  89. package/ReactCommon/react/renderer/components/legacyviewmanagerinterop/RCTLegacyViewManagerInteropCoordinator.mm +4 -2
  90. package/ReactCommon/react/renderer/core/EventDispatcher.cpp +21 -0
  91. package/ReactCommon/react/renderer/core/EventDispatcher.h +15 -0
  92. package/ReactCommon/react/renderer/core/EventListener.cpp +39 -0
  93. package/ReactCommon/react/renderer/core/EventListener.h +44 -0
  94. package/ReactCommon/react/renderer/graphics/React-graphics.podspec +1 -1
  95. package/ReactCommon/react/renderer/mounting/StubViewTree.cpp +1 -1
  96. package/ReactCommon/react/renderer/mounting/TelemetryController.cpp +6 -9
  97. package/ReactCommon/react/renderer/mounting/TelemetryController.h +7 -7
  98. package/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.cpp +3 -2
  99. package/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.h +7 -1
  100. package/ReactCommon/react/renderer/scheduler/Scheduler.cpp +18 -0
  101. package/ReactCommon/react/renderer/scheduler/Scheduler.h +9 -0
  102. package/ReactCommon/react/utils/ManagedObjectWrapper.h +1 -1
  103. package/ReactCommon/react/utils/ManagedObjectWrapper.mm +1 -3
  104. package/package.json +1 -1
  105. package/scripts/generate-artifacts.js +21 -17
  106. package/scripts/react_native_pods.rb +0 -3
  107. package/template/Gemfile.lock +4 -4
  108. package/template/package.json +1 -1
  109. package/ReactCommon/react/renderer/mounting/MountingTransactionMetadata.cpp +0 -12
  110. package/ReactCommon/react/renderer/mounting/MountingTransactionMetadata.h +0 -32
  111. package/third-party-podspecs/boost-for-react-native.podspec +0 -20
@@ -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
  }
@@ -554,6 +562,15 @@ static inline UIViewAnimationOptions animationOptionsWithCurve(UIViewAnimationCu
554
562
  {
555
563
  [_scrollView setAccessibilityRole:accessibilityRole];
556
564
  }
565
+
566
+ - (void)setInverted:(BOOL)inverted
567
+ {
568
+ BOOL changed = _inverted != inverted;
569
+ _inverted = inverted;
570
+ if (changed && _onInvertedDidChange) {
571
+ _onInvertedDidChange(@{});
572
+ }
573
+ }
557
574
  #endif // ]TODO(macOS GH#774)
558
575
 
559
576
  RCT_NOT_IMPLEMENTED(-(instancetype)initWithFrame : (CGRect)frame)
@@ -1261,74 +1278,58 @@ RCT_SCROLL_EVENT_HANDLER(scrollViewDidScrollToTop, onScrollToTop)
1261
1278
  }];
1262
1279
  }
1263
1280
 
1264
- #if TARGET_OS_OSX // [TODO(macOS GH#774)
1265
-
1266
- - (NSString*)keyCommandFromKeyCode:(NSInteger)keyCode modifierFlags:(NSEventModifierFlags)modifierFlags
1267
- {
1268
- switch (keyCode)
1269
- {
1270
- case 36:
1271
- return @"ENTER";
1272
-
1273
- case 115:
1274
- return @"HOME";
1275
-
1276
- case 116:
1277
- return @"PAGE_UP";
1278
-
1279
- case 119:
1280
- return @"END";
1281
-
1282
- case 121:
1283
- return @"PAGE_DOWN";
1284
-
1285
- case 123:
1286
- return @"LEFT_ARROW";
1287
-
1288
- case 124:
1289
- return @"RIGHT_ARROW";
1281
+ // [TODO(macOS GH#774)
1282
+ #pragma mark - Keyboard Events
1290
1283
 
1291
- case 125:
1292
- if (modifierFlags & NSEventModifierFlagOption) {
1293
- return @"OPTION_DOWN";
1294
- } else {
1295
- return @"DOWN_ARROW";
1296
- }
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
+ }
1297
1294
 
1298
- case 126:
1299
- if (modifierFlags & NSEventModifierFlagOption) {
1300
- return @"OPTION_UP";
1301
- } else {
1302
- return @"UP_ARROW";
1303
- }
1304
- }
1305
- return @"";
1295
+ return [RCTViewKeyboardEvent keyEventFromEvent:event reactTag:self.reactTag];
1306
1296
  }
1307
1297
 
1308
- - (void)keyDown:(UIEvent*)theEvent
1309
- {
1310
- // Don't emit a scroll event if tab was pressed while the scrollview is first responder
1311
- if (!(self == [[self window] firstResponder] && theEvent.keyCode == 48)) {
1312
- NSString *keyCommand = [self keyCommandFromKeyCode:theEvent.keyCode modifierFlags:theEvent.modifierFlags];
1313
- if (![keyCommand isEqual: @""]) {
1314
- RCT_SEND_SCROLL_EVENT(onScrollKeyDown, (@{ @"key": keyCommand}));
1315
- } else {
1316
- [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;
1317
1304
  }
1318
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
+ }
1319
1328
 
1320
- // AX: if a tab key was pressed and the first responder is currently clipped by the scroll view,
1321
- // automatically scroll to make the view visible to make it navigable via keyboard.
1322
- if ([theEvent keyCode] == 48) { //tab key
1323
- id firstResponder = [[self window] firstResponder];
1324
- if ([firstResponder isKindOfClass:[NSView class]] &&
1325
- [firstResponder isDescendantOf:[_scrollView documentView]]) {
1326
- NSView *view = (NSView*)firstResponder;
1327
- NSRect visibleRect = ([view superview] == [_scrollView documentView]) ? NSInsetRect(view.frame, -1, -1) :
1328
- [view convertRect:view.frame toView:_scrollView.documentView];
1329
- [[_scrollView documentView] scrollRectToVisible:visibleRect];
1330
- }
1331
- }
1329
+ - (void)keyUp:(NSEvent *)event {
1330
+ if (![self handleKeyboardEvent:event]) {
1331
+ [super keyUp:event];
1332
+ }
1332
1333
  }
1333
1334
 
1334
1335
  static NSString *RCTStringForScrollerStyle(NSScrollerStyle scrollerStyle) {
@@ -1343,7 +1344,8 @@ static NSString *RCTStringForScrollerStyle(NSScrollerStyle scrollerStyle) {
1343
1344
  - (void)preferredScrollerStyleDidChange:(__unused NSNotification *)notification {
1344
1345
  RCT_SEND_SCROLL_EVENT(onPreferredScrollerStyleDidChange, (@{ @"preferredScrollerStyle": RCTStringForScrollerStyle([NSScroller preferredScrollerStyle])}));
1345
1346
  }
1346
- #endif // ]TODO(macOS GH#774)
1347
+ #endif
1348
+ // ]TODO(macOS GH#774)
1347
1349
 
1348
1350
  // Note: setting several properties of UIScrollView has the effect of
1349
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
  */
@@ -267,18 +267,17 @@
267
267
  }
268
268
  #endif // TODO(macOS GH#774)
269
269
 
270
- /**
271
- * Focus manipulation.
272
- */
273
- - (BOOL)reactIsFocusNeeded
270
+ // [TODO(macOS GH#1412)
271
+ - (void)reactViewDidMoveToWindow
274
272
  {
275
- return [(NSNumber *)objc_getAssociatedObject(self, @selector(reactIsFocusNeeded)) boolValue];
273
+ [self reactFocusIfNeeded];
276
274
  }
275
+ // TODO(macOS GH#1412)]
277
276
 
278
- - (void)setReactIsFocusNeeded:(BOOL)isFocusNeeded
279
- {
280
- objc_setAssociatedObject(self, @selector(reactIsFocusNeeded), @(isFocusNeeded), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
281
- }
277
+ /**
278
+ * Focus manipulation.
279
+ */
280
+ static __weak RCTPlatformView *_pendingFocusView; // TODO(macOS GH#1412)
282
281
 
283
282
  - (void)reactFocus
284
283
  {
@@ -287,19 +286,23 @@
287
286
  #else
288
287
  if (![self becomeFirstResponder]) {
289
288
  #endif // TODO(macOS GH#774)]
290
- self.reactIsFocusNeeded = YES;
291
- }
289
+ // [TODO(macOS GH#1412)
290
+ _pendingFocusView = self;
291
+ } else {
292
+ _pendingFocusView = nil;
293
+ }
294
+ // TODO(macOS GH#1412)]
292
295
  }
293
296
 
294
297
  - (void)reactFocusIfNeeded
295
298
  {
296
- if (self.reactIsFocusNeeded) {
299
+ if ([self isEqual:_pendingFocusView]) { // TODO(macOS GH#1412)
297
300
  #if TARGET_OS_OSX // [TODO(macOS GH#774)
298
301
  if ([[self window] makeFirstResponder:self]) {
299
302
  #else
300
303
  if ([self becomeFirstResponder]) {
301
304
  #endif // TODO(macOS GH#774)]
302
- self.reactIsFocusNeeded = NO;
305
+ _pendingFocusView = nil; // TODO(macOS GH#1412)
303
306
  }
304
307
  }
305
308
  }
@@ -313,6 +316,12 @@
313
316
  #else
314
317
  [self resignFirstResponder];
315
318
  #endif // TODO(macOS GH#774)]
319
+
320
+ // [TODO(macOS GH#1412)
321
+ if ([self isEqual:_pendingFocusView]) {
322
+ _pendingFocusView = nil;
323
+ }
324
+ // TODO(macOS GH#1412)]
316
325
  }
317
326
 
318
327
  #pragma mark - Layout
@@ -1,4 +1,4 @@
1
- VERSION_NAME=0.0.0-96be39d8c
1
+ VERSION_NAME=0.0.0-96f71c939
2
2
  GROUP=com.facebook.react
3
3
 
4
4
  POM_NAME=ReactNative
@@ -22,5 +22,5 @@ public class ReactNativeVersion {
22
22
  "major", 0,
23
23
  "minor", 0,
24
24
  "patch", 0,
25
- "prerelease", "96be39d8c");
25
+ "prerelease", "96f71c939");
26
26
  }
@@ -29,7 +29,7 @@ Pod::Spec.new do |s|
29
29
  s.homepage = "https://reactnative.dev/"
30
30
  s.license = package["license"]
31
31
  s.author = "Facebook, Inc. and its affiliates"
32
- s.platforms = { :ios => "11.0" }
32
+ s.platforms = { :ios => "11.0", :osx => "10.15" } # TODO(macOS GH#774)
33
33
  s.source = source
34
34
  s.source_files = "dummyFile.cpp"
35
35
  s.pod_target_xcconfig = { "USE_HEADERMAP" => "YES",
@@ -25,7 +25,7 @@ Pod::Spec.new do |s|
25
25
  s.homepage = "https://reactnative.dev/"
26
26
  s.license = package["license"]
27
27
  s.author = "Facebook, Inc. and its affiliates"
28
- s.platforms = { :ios => "11.0" }
28
+ s.platforms = { :ios => "11.0", :osx => "10.15" } # TODO(macOS GH#774)
29
29
  s.source = source
30
30
  s.source_files = "dummyFile.cpp"
31
31
  s.pod_target_xcconfig = { "USE_HEADERMAP" => "YES",
@@ -22,7 +22,7 @@ constexpr struct {
22
22
  int32_t Major = 0;
23
23
  int32_t Minor = 0;
24
24
  int32_t Patch = 0;
25
- std::string_view Prerelease = "96be39d8c";
25
+ std::string_view Prerelease = "96f71c939";
26
26
  } ReactNativeVersion;
27
27
 
28
28
  } // namespace facebook::react
@@ -55,7 +55,7 @@ void react_native_assert_fail(
55
55
  #define react_native_assert(cond) \
56
56
  if (!(cond)) { \
57
57
  LOG(ERROR) << "react_native_assert failure: " << #cond; \
58
- google::FlushLogFiles(google::INFO); \
58
+ google::FlushLogFiles(google::GLOG_INFO); \
59
59
  assert(cond); \
60
60
  }
61
61
 
@@ -43,6 +43,11 @@ static std::string moduleNameFromComponentName(const std::string &componentName)
43
43
  return componentName + "Manager";
44
44
  }
45
45
 
46
+ std::string rnPrefix("RN");
47
+ if (std::mismatch(rnPrefix.begin(), rnPrefix.end(), componentName.begin()).first == rnPrefix.end()) {
48
+ return componentName + "Manager";
49
+ }
50
+
46
51
  return "RCT" + componentName + "Manager";
47
52
  }
48
53
 
@@ -86,8 +86,10 @@ using namespace facebook::react;
86
86
 
87
87
  - (void)setProps:(folly::dynamic const &)props forView:(UIView *)view
88
88
  {
89
- NSDictionary<NSString *, id> *convertedProps = convertFollyDynamicToId(props);
90
- [_componentData setProps:convertedProps forView:view];
89
+ if (props.isObject()) {
90
+ NSDictionary<NSString *, id> *convertedProps = convertFollyDynamicToId(props);
91
+ [_componentData setProps:convertedProps forView:view];
92
+ }
91
93
  }
92
94
 
93
95
  - (NSString *)componentViewName
@@ -36,6 +36,10 @@ EventDispatcher::EventDispatcher(
36
36
 
37
37
  void EventDispatcher::dispatchEvent(RawEvent &&rawEvent, EventPriority priority)
38
38
  const {
39
+ // Allows the event listener to interrupt default event dispatch
40
+ if (eventListeners_.willDispatchEvent(rawEvent)) {
41
+ return;
42
+ }
39
43
  getEventQueue(priority).enqueueEvent(std::move(rawEvent));
40
44
  }
41
45
 
@@ -46,6 +50,10 @@ void EventDispatcher::dispatchStateUpdate(
46
50
  }
47
51
 
48
52
  void EventDispatcher::dispatchUniqueEvent(RawEvent &&rawEvent) const {
53
+ // Allows the event listener to interrupt default event dispatch
54
+ if (eventListeners_.willDispatchEvent(rawEvent)) {
55
+ return;
56
+ }
49
57
  asynchronousBatchedQueue_->enqueueUniqueEvent(std::move(rawEvent));
50
58
  }
51
59
 
@@ -62,5 +70,18 @@ const EventQueue &EventDispatcher::getEventQueue(EventPriority priority) const {
62
70
  }
63
71
  }
64
72
 
73
+ void EventDispatcher::addListener(
74
+ const std::shared_ptr<EventListener const> &listener) const {
75
+ eventListeners_.addListener(listener);
76
+ }
77
+
78
+ /*
79
+ * Removes provided event listener to the event dispatcher.
80
+ */
81
+ void EventDispatcher::removeListener(
82
+ const std::shared_ptr<EventListener const> &listener) const {
83
+ eventListeners_.removeListener(listener);
84
+ }
85
+
65
86
  } // namespace react
66
87
  } // namespace facebook
@@ -9,6 +9,7 @@
9
9
 
10
10
  #include <react/renderer/core/BatchedEventQueue.h>
11
11
  #include <react/renderer/core/EventBeat.h>
12
+ #include <react/renderer/core/EventListener.h>
12
13
  #include <react/renderer/core/EventPriority.h>
13
14
  #include <react/renderer/core/EventQueueProcessor.h>
14
15
  #include <react/renderer/core/StateUpdate.h>
@@ -52,6 +53,18 @@ class EventDispatcher {
52
53
  void dispatchStateUpdate(StateUpdate &&stateUpdate, EventPriority priority)
53
54
  const;
54
55
 
56
+ #pragma mark - Event listeners
57
+ /*
58
+ * Adds provided event listener to the event dispatcher.
59
+ */
60
+ void addListener(const std::shared_ptr<EventListener const> &listener) const;
61
+
62
+ /*
63
+ * Removes provided event listener to the event dispatcher.
64
+ */
65
+ void removeListener(
66
+ const std::shared_ptr<EventListener const> &listener) const;
67
+
55
68
  private:
56
69
  EventQueue const &getEventQueue(EventPriority priority) const;
57
70
 
@@ -59,6 +72,8 @@ class EventDispatcher {
59
72
  std::unique_ptr<BatchedEventQueue> synchronousBatchedQueue_;
60
73
  std::unique_ptr<UnbatchedEventQueue> asynchronousUnbatchedQueue_;
61
74
  std::unique_ptr<BatchedEventQueue> asynchronousBatchedQueue_;
75
+
76
+ mutable EventListenerContainer eventListeners_;
62
77
  };
63
78
 
64
79
  } // namespace react
@@ -0,0 +1,39 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ #include "EventListener.h"
9
+
10
+ namespace facebook::react {
11
+
12
+ bool EventListenerContainer::willDispatchEvent(const RawEvent &event) {
13
+ std::shared_lock<butter::shared_mutex> lock(mutex_);
14
+
15
+ bool handled = false;
16
+ for (auto const &listener : eventListeners_) {
17
+ handled = handled || listener->operator()(event);
18
+ }
19
+ return handled;
20
+ }
21
+
22
+ void EventListenerContainer::addListener(
23
+ const std::shared_ptr<EventListener const> &listener) {
24
+ std::unique_lock<butter::shared_mutex> lock(mutex_);
25
+
26
+ eventListeners_.push_back(listener);
27
+ }
28
+
29
+ void EventListenerContainer::removeListener(
30
+ const std::shared_ptr<EventListener const> &listener) {
31
+ std::unique_lock<butter::shared_mutex> lock(mutex_);
32
+
33
+ auto it = std::find(eventListeners_.begin(), eventListeners_.end(), listener);
34
+ if (it != eventListeners_.end()) {
35
+ eventListeners_.erase(it);
36
+ }
37
+ }
38
+
39
+ } // namespace facebook::react
@@ -0,0 +1,44 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include <string>
11
+
12
+ #include <react/renderer/core/RawEvent.h>
13
+
14
+ #include <butter/mutex.h>
15
+
16
+ namespace facebook {
17
+ namespace react {
18
+
19
+ /**
20
+ * Listener for events dispatched to JS runtime.
21
+ * Return `true` to interrupt default dispatch to JS event emitter, `false` to
22
+ * pass through to default handlers.
23
+ */
24
+ using EventListener = std::function<bool(const RawEvent &event)>;
25
+
26
+ class EventListenerContainer {
27
+ public:
28
+ /*
29
+ * Invoke listeners in this container with the event.
30
+ * Returns true if event was handled by the listener, false to continue
31
+ * default dispatch.
32
+ */
33
+ bool willDispatchEvent(const RawEvent &event);
34
+
35
+ void addListener(const std::shared_ptr<EventListener const> &listener);
36
+ void removeListener(const std::shared_ptr<EventListener const> &listener);
37
+
38
+ private:
39
+ butter::shared_mutex mutex_;
40
+ std::vector<std::shared_ptr<EventListener const>> eventListeners_;
41
+ };
42
+
43
+ } // namespace react
44
+ } // namespace facebook
@@ -27,7 +27,7 @@ Pod::Spec.new do |s|
27
27
  s.homepage = "https://reactnative.dev/"
28
28
  s.license = package["license"]
29
29
  s.author = "Facebook, Inc. and its affiliates"
30
- s.platforms = { :ios => "11.0", :tvos => "11.0" }
30
+ s.platforms = { :ios => "11.0", :osx => "10.15" } # TODO(macOS GH#774)
31
31
  s.source = source
32
32
  s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags
33
33
  s.source_files = "**/*.{m,mm,cpp,h}"
@@ -250,7 +250,7 @@ void StubViewTree::mutate(ShadowViewMutationList const &mutations) {
250
250
 
251
251
  // For iOS especially: flush logs because some might be lost on iOS if an
252
252
  // assert is hit right after this.
253
- google::FlushLogFiles(google::INFO);
253
+ google::FlushLogFiles(google::GLOG_INFO);
254
254
  }
255
255
 
256
256
  bool operator==(StubViewTree const &lhs, StubViewTree const &rhs) {
@@ -17,10 +17,9 @@ TelemetryController::TelemetryController(
17
17
  : mountingCoordinator_(mountingCoordinator) {}
18
18
 
19
19
  bool TelemetryController::pullTransaction(
20
- std::function<void(MountingTransactionMetadata metadata)> const &willMount,
21
- std::function<void(ShadowViewMutationList const &mutations)> const &doMount,
22
- std::function<void(MountingTransactionMetadata metadata)> const &didMount)
23
- const {
20
+ MountingTransactionCallback const &willMount,
21
+ MountingTransactionCallback const &doMount,
22
+ MountingTransactionCallback const &didMount) const {
24
23
  auto optional = mountingCoordinator_.pullTransaction();
25
24
  if (!optional.has_value()) {
26
25
  return false;
@@ -28,8 +27,6 @@ bool TelemetryController::pullTransaction(
28
27
 
29
28
  auto transaction = std::move(*optional);
30
29
 
31
- auto surfaceId = transaction.getSurfaceId();
32
- auto number = transaction.getNumber();
33
30
  auto telemetry = transaction.getTelemetry();
34
31
  auto numberOfMutations = static_cast<int>(transaction.getMutations().size());
35
32
 
@@ -37,15 +34,15 @@ bool TelemetryController::pullTransaction(
37
34
  auto compoundTelemetry = compoundTelemetry_;
38
35
  mutex_.unlock();
39
36
 
40
- willMount({surfaceId, number, telemetry, compoundTelemetry});
37
+ willMount(transaction, compoundTelemetry);
41
38
 
42
39
  telemetry.willMount();
43
- doMount(transaction.getMutations());
40
+ doMount(transaction, compoundTelemetry);
44
41
  telemetry.didMount();
45
42
 
46
43
  compoundTelemetry.incorporate(telemetry, numberOfMutations);
47
44
 
48
- didMount({surfaceId, number, telemetry, compoundTelemetry});
45
+ didMount(transaction, compoundTelemetry);
49
46
 
50
47
  mutex_.lock();
51
48
  compoundTelemetry_ = compoundTelemetry;
@@ -11,7 +11,6 @@
11
11
  #include <mutex>
12
12
 
13
13
  #include <react/renderer/mounting/MountingTransaction.h>
14
- #include <react/renderer/mounting/MountingTransactionMetadata.h>
15
14
  #include <react/renderer/telemetry/TransactionTelemetry.h>
16
15
 
17
16
  namespace facebook {
@@ -19,6 +18,10 @@ namespace react {
19
18
 
20
19
  class MountingCoordinator;
21
20
 
21
+ using MountingTransactionCallback = std::function<void(
22
+ MountingTransaction const &transaction,
23
+ SurfaceTelemetry const &surfaceTelemetry)>;
24
+
22
25
  /*
23
26
  * Provides convenient tools for aggregating and accessing telemetry data
24
27
  * associated with running Surface.
@@ -43,12 +46,9 @@ class TelemetryController final {
43
46
  * Calls `MountingCoordinator::pullTransaction()` and aggregates telemetry.
44
47
  */
45
48
  bool pullTransaction(
46
- std::function<void(MountingTransactionMetadata metadata)> const
47
- &willMount,
48
- std::function<void(ShadowViewMutationList const &mutations)> const
49
- &doMount,
50
- std::function<void(MountingTransactionMetadata metadata)> const &didMount)
51
- const;
49
+ MountingTransactionCallback const &willMount,
50
+ MountingTransactionCallback const &doMount,
51
+ MountingTransactionCallback const &didMount) const;
52
52
 
53
53
  private:
54
54
  MountingCoordinator const &mountingCoordinator_;
@@ -22,10 +22,11 @@ RuntimeScheduler::RuntimeScheduler(
22
22
 
23
23
  void RuntimeScheduler::scheduleWork(
24
24
  std::function<void(jsi::Runtime &)> callback) const {
25
- shouldYield_ = true;
25
+ runtimeAccessRequests_ += 1;
26
+
26
27
  runtimeExecutor_(
27
28
  [this, callback = std::move(callback)](jsi::Runtime &runtime) {
28
- shouldYield_ = false;
29
+ runtimeAccessRequests_ -= 1;
29
30
  callback(runtime);
30
31
  startWorkLoop(runtime);
31
32
  });
@@ -106,6 +106,12 @@ class RuntimeScheduler final {
106
106
  RuntimeExecutor const runtimeExecutor_;
107
107
  mutable SchedulerPriority currentPriority_{SchedulerPriority::NormalPriority};
108
108
  mutable std::atomic_bool shouldYield_{false};
109
+
110
+ /*
111
+ * Counter indicating how many access to the runtime have been requested.
112
+ */
113
+ mutable std::atomic<uint_fast8_t> runtimeAccessRequests_{0};
114
+
109
115
  mutable std::atomic_bool isSynchronous_{false};
110
116
 
111
117
  void startWorkLoop(jsi::Runtime &runtime) const;
@@ -135,4 +141,4 @@ class RuntimeScheduler final {
135
141
  };
136
142
 
137
143
  } // namespace react
138
- } // namespace facebook
144
+ } // namespace facebook
@@ -351,5 +351,23 @@ ContextContainer::Shared Scheduler::getContextContainer() const {
351
351
  return contextContainer_;
352
352
  }
353
353
 
354
+ std::shared_ptr<UIManager> Scheduler::getUIManager() const {
355
+ return uiManager_;
356
+ }
357
+
358
+ void Scheduler::addEventListener(
359
+ const std::shared_ptr<EventListener const> &listener) {
360
+ if (eventDispatcher_->has_value()) {
361
+ eventDispatcher_->value().addListener(listener);
362
+ }
363
+ }
364
+
365
+ void Scheduler::removeEventListener(
366
+ const std::shared_ptr<EventListener const> &listener) {
367
+ if (eventDispatcher_->has_value()) {
368
+ eventDispatcher_->value().removeListener(listener);
369
+ }
370
+ }
371
+
354
372
  } // namespace react
355
373
  } // namespace facebook