react-native 0.74.0-rc.2 → 0.74.0-rc.4

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 (63) hide show
  1. package/Libraries/AppDelegate/RCTAppDelegate.h +5 -8
  2. package/Libraries/AppDelegate/RCTAppDelegate.mm +56 -130
  3. package/Libraries/AppDelegate/RCTRootViewFactory.h +123 -0
  4. package/Libraries/AppDelegate/RCTRootViewFactory.mm +253 -0
  5. package/Libraries/Components/View/ReactNativeStyleAttributes.js +1 -0
  6. package/Libraries/Core/ReactNativeVersion.js +1 -1
  7. package/Libraries/Core/registerCallableModule.d.ts +16 -0
  8. package/Libraries/LogBox/Data/parseLogBoxLog.js +1 -1
  9. package/Libraries/StyleSheet/StyleSheetTypes.d.ts +4 -0
  10. package/Libraries/StyleSheet/StyleSheetTypes.js +3 -0
  11. package/React/Base/RCTBridgeProxy+Cxx.h +20 -0
  12. package/React/Base/RCTBridgeProxy.h +2 -0
  13. package/React/Base/RCTBridgeProxy.mm +15 -0
  14. package/React/Base/RCTConvert.h +3 -0
  15. package/React/Base/RCTConvert.mm +9 -0
  16. package/React/Base/RCTVersion.m +1 -1
  17. package/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.h +7 -0
  18. package/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm +17 -2
  19. package/React/CoreModules/RCTRedBox.mm +7 -1
  20. package/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +32 -0
  21. package/React/Views/RCTCursor.h +13 -0
  22. package/React/Views/RCTView.h +3 -0
  23. package/React/Views/RCTView.m +30 -0
  24. package/React/Views/RCTViewManager.m +2 -0
  25. package/ReactAndroid/api/ReactAndroid.api +44 -0
  26. package/ReactAndroid/build.gradle.kts +26 -0
  27. package/ReactAndroid/cmake-utils/ReactNative-application.cmake +6 -0
  28. package/ReactAndroid/gradle.properties +1 -1
  29. package/ReactAndroid/src/main/java/com/facebook/react/ReactDelegate.java +22 -16
  30. package/ReactAndroid/src/main/java/com/facebook/react/ReactHost.kt +9 -0
  31. package/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java +5 -0
  32. package/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstance.java +1 -1
  33. package/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java +2 -1
  34. package/ReactAndroid/src/main/java/com/facebook/react/bridge/JSIModuleRegistry.java +2 -2
  35. package/ReactAndroid/src/main/java/com/facebook/react/bridge/NativeArrayInterface.java +1 -1
  36. package/ReactAndroid/src/main/java/com/facebook/react/bridge/queue/MessageQueueThreadHandler.java +0 -11
  37. package/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultReactHostDelegate.kt +1 -1
  38. package/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultReactNativeHost.kt +11 -6
  39. package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java +1 -1
  40. package/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessCatalystInstance.kt +201 -0
  41. package/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessReactContext.java +4 -6
  42. package/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.java +47 -0
  43. package/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.java +1 -1
  44. package/ReactAndroid/src/main/java/com/facebook/react/views/text/TextAttributeProps.java +2 -0
  45. package/ReactAndroid/src/main/jni/react/jni/JMessageQueueThread.cpp +0 -1
  46. package/ReactAndroid/src/main/jni/react/jni/JMessageQueueThread.h +0 -4
  47. package/ReactCommon/cxxreact/ReactNativeVersion.h +1 -1
  48. package/ReactCommon/react/renderer/components/view/BaseViewProps.cpp +9 -0
  49. package/ReactCommon/react/renderer/components/view/BaseViewProps.h +2 -0
  50. package/ReactCommon/react/renderer/components/view/ViewShadowNode.cpp +1 -1
  51. package/ReactCommon/react/renderer/components/view/conversions.h +22 -0
  52. package/ReactCommon/react/renderer/components/view/primitives.h +2 -0
  53. package/ReactCommon/react/renderer/imagemanager/platform/ios/react/renderer/imagemanager/RCTImagePrimitivesConversions.h +2 -2
  54. package/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm +45 -12
  55. package/ReactCommon/yoga/yoga/algorithm/AbsoluteLayout.cpp +64 -40
  56. package/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp +19 -20
  57. package/package.json +11 -11
  58. package/sdks/hermesc/osx-bin/hermes +0 -0
  59. package/sdks/hermesc/osx-bin/hermesc +0 -0
  60. package/sdks/hermesc/win64-bin/hermesc.exe +0 -0
  61. package/template/package.json +5 -5
  62. package/types/index.d.ts +1 -0
  63. package/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultBindingsInstaller.kt +0 -20
@@ -7,6 +7,7 @@
7
7
 
8
8
  #import <React/RCTBridgeDelegate.h>
9
9
  #import <UIKit/UIKit.h>
10
+ #import "RCTRootViewFactory.h"
10
11
 
11
12
  @class RCTBridge;
12
13
  @protocol RCTBridgeDelegate;
@@ -57,9 +58,12 @@ NS_ASSUME_NONNULL_BEGIN
57
58
 
58
59
  /// The window object, used to render the UViewControllers
59
60
  @property (nonatomic, strong, nonnull) UIWindow *window;
60
- @property (nonatomic, strong, nullable) RCTBridge *bridge;
61
+ @property (nonatomic, nullable) RCTBridge *bridge;
61
62
  @property (nonatomic, strong, nullable) NSString *moduleName;
62
63
  @property (nonatomic, strong, nullable) NSDictionary *initialProps;
64
+ @property (nonatomic, strong, nonnull) RCTRootViewFactory *rootViewFactory;
65
+
66
+ @property (nonatomic, nullable) RCTSurfacePresenterBridgeAdapter *bridgeAdapter;
63
67
 
64
68
  /**
65
69
  * It creates a `RCTBridge` using a delegate and some launch options.
@@ -126,13 +130,6 @@ NS_ASSUME_NONNULL_BEGIN
126
130
  */
127
131
  - (void)setRootView:(UIView *)rootView toRootViewController:(UIViewController *)rootViewController;
128
132
 
129
- /// This method controls whether the App will use RuntimeScheduler. Only applicable in the legacy architecture.
130
- ///
131
- /// @return: `YES` to use RuntimeScheduler, `NO` to use JavaScript scheduler. The default value is `YES`.
132
- - (BOOL)runtimeSchedulerEnabled;
133
-
134
- @property (nonatomic, strong) RCTSurfacePresenterBridgeAdapter *bridgeAdapter;
135
-
136
133
  /// This method returns a map of Component Descriptors and Components classes that needs to be registered in the
137
134
  /// new renderer. The Component Descriptor is a string which represent the name used in JS to refer to the native
138
135
  /// component. The default implementation returns an empty dictionary. Subclasses can override this method to register
@@ -39,85 +39,28 @@
39
39
  #import <react/renderer/runtimescheduler/RuntimeSchedulerCallInvoker.h>
40
40
  #import <react/runtime/JSRuntimeFactory.h>
41
41
 
42
- @interface RCTAppDelegate () <
43
- RCTTurboModuleManagerDelegate,
44
- RCTComponentViewFactoryComponentProvider,
45
- RCTContextContainerHandling> {
46
- std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig;
47
- facebook::react::ContextContainer::Shared _contextContainer;
48
- }
42
+ @interface RCTAppDelegate () <RCTComponentViewFactoryComponentProvider, RCTTurboModuleManagerDelegate>
49
43
  @end
50
44
 
51
- static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabricEnabled)
52
- {
53
- NSMutableDictionary *mutableProps = [initialProps mutableCopy] ?: [NSMutableDictionary new];
54
- return mutableProps;
55
- }
56
-
57
- @interface RCTAppDelegate () <RCTCxxBridgeDelegate> {
58
- std::shared_ptr<facebook::react::RuntimeScheduler> _runtimeScheduler;
59
- }
60
- @end
61
-
62
- @implementation RCTAppDelegate {
63
- RCTHost *_reactHost;
64
- }
65
-
66
- - (instancetype)init
67
- {
68
- if (self = [super init]) {
69
- _contextContainer = std::make_shared<facebook::react::ContextContainer const>();
70
- _reactNativeConfig = std::make_shared<facebook::react::EmptyReactNativeConfig const>();
71
- _contextContainer->insert("ReactNativeConfig", _reactNativeConfig);
72
- }
73
- return self;
74
- }
45
+ @implementation RCTAppDelegate
75
46
 
76
47
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
77
48
  {
78
49
  RCTSetNewArchEnabled([self newArchEnabled]);
79
- BOOL enableTM = self.turboModuleEnabled;
80
- BOOL fabricEnabled = self.fabricEnabled;
81
- BOOL enableBridgeless = self.bridgelessEnabled;
82
-
83
- NSDictionary *initProps = updateInitialProps([self prepareInitialProps], fabricEnabled);
50
+ RCTAppSetupPrepareApp(application, self.turboModuleEnabled);
84
51
 
85
- RCTAppSetupPrepareApp(application, enableTM);
52
+ self.rootViewFactory = [self createRCTRootViewFactory];
86
53
 
87
- UIView *rootView;
88
- if (enableBridgeless) {
89
- // Enable native view config interop only if both bridgeless mode and Fabric is enabled.
90
- RCTSetUseNativeViewConfigsInBridgelessMode(fabricEnabled);
54
+ UIView *rootView = [self.rootViewFactory viewWithModuleName:self.moduleName
55
+ initialProperties:self.initialProps
56
+ launchOptions:launchOptions];
91
57
 
92
- // Enable TurboModule interop by default in Bridgeless mode
93
- RCTEnableTurboModuleInterop(YES);
94
- RCTEnableTurboModuleInteropBridgeProxy(YES);
95
-
96
- [self createReactHost];
58
+ if (self.newArchEnabled || self.fabricEnabled) {
97
59
  [RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self;
98
- RCTFabricSurface *surface = [_reactHost createSurfaceWithModuleName:self.moduleName initialProperties:initProps];
99
-
100
- RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView = [[RCTSurfaceHostingProxyRootView alloc]
101
- initWithSurface:surface
102
- sizeMeasureMode:RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact];
103
-
104
- rootView = (RCTRootView *)surfaceHostingProxyRootView;
105
- rootView.backgroundColor = [UIColor systemBackgroundColor];
106
- } else {
107
- if (!self.bridge) {
108
- self.bridge = [self createBridgeWithDelegate:self launchOptions:launchOptions];
109
- }
110
- if ([self newArchEnabled]) {
111
- self.bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:self.bridge
112
- contextContainer:_contextContainer];
113
- self.bridge.surfacePresenter = self.bridgeAdapter.surfacePresenter;
114
-
115
- [RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self;
116
- }
117
- rootView = [self createRootViewWithBridge:self.bridge moduleName:self.moduleName initProps:initProps];
118
60
  }
119
61
  [self _logWarnIfCreateRootViewWithBridgeIsOverridden];
120
62
  [self customizeRootView:(RCTRootView *)rootView];
63
+
121
64
  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
122
65
  UIViewController *rootViewController = [self createRootViewController];
123
66
  [self setRootView:rootView toRootViewController:rootViewController];
@@ -140,21 +83,11 @@ static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabri
140
83
  return nil;
141
84
  }
142
85
 
143
- - (NSDictionary *)prepareInitialProps
144
- {
145
- return self.initialProps;
146
- }
147
-
148
86
  - (RCTBridge *)createBridgeWithDelegate:(id<RCTBridgeDelegate>)delegate launchOptions:(NSDictionary *)launchOptions
149
87
  {
150
88
  return [[RCTBridge alloc] initWithDelegate:delegate launchOptions:launchOptions];
151
89
  }
152
90
 
153
- - (void)customizeRootView:(RCTRootView *)rootView
154
- {
155
- // Override point for customization after application launch.
156
- }
157
-
158
91
  - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge
159
92
  moduleName:(NSString *)moduleName
160
93
  initProps:(NSDictionary *)initProps
@@ -192,9 +125,9 @@ static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabri
192
125
  rootViewController.view = rootView;
193
126
  }
194
127
 
195
- - (BOOL)runtimeSchedulerEnabled
128
+ - (void)customizeRootView:(RCTRootView *)rootView
196
129
  {
197
- return YES;
130
+ // Override point for customization after application launch.
198
131
  }
199
132
 
200
133
  #pragma mark - UISceneDelegate
@@ -207,25 +140,6 @@ static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabri
207
140
  [[NSNotificationCenter defaultCenter] postNotificationName:RCTWindowFrameDidChangeNotification object:self];
208
141
  }
209
142
 
210
- #pragma mark - RCTCxxBridgeDelegate
211
-
212
- - (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
213
- {
214
- _runtimeScheduler = std::make_shared<facebook::react::RuntimeScheduler>(RCTRuntimeExecutorFromBridge(bridge));
215
- if ([self newArchEnabled]) {
216
- std::shared_ptr<facebook::react::CallInvoker> callInvoker =
217
- std::make_shared<facebook::react::RuntimeSchedulerCallInvoker>(_runtimeScheduler);
218
- RCTTurboModuleManager *turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge
219
- delegate:self
220
- jsInvoker:callInvoker];
221
- _contextContainer->erase("RuntimeScheduler");
222
- _contextContainer->insert("RuntimeScheduler", _runtimeScheduler);
223
- return RCTAppSetupDefaultJsExecutorFactory(bridge, turboModuleManager, _runtimeScheduler);
224
- } else {
225
- return RCTAppSetupJsExecutorFactoryForOldArch(bridge, _runtimeScheduler);
226
- }
227
- }
228
-
229
143
  #pragma mark - New Arch Enabled settings
230
144
 
231
145
  - (BOOL)newArchEnabled
@@ -252,11 +166,33 @@ static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabri
252
166
  return [self newArchEnabled];
253
167
  }
254
168
 
255
- #pragma mark - RCTComponentViewFactoryComponentProvider
169
+ - (NSURL *)bundleURL
170
+ {
171
+ [NSException raise:@"RCTAppDelegate::bundleURL not implemented"
172
+ format:@"Subclasses must implement a valid getBundleURL method"];
173
+ return nullptr;
174
+ }
256
175
 
257
- - (NSDictionary<NSString *, Class<RCTComponentViewProtocol>> *)thirdPartyFabricComponents
176
+ #pragma mark - Bridge and Bridge Adapter properties
177
+
178
+ - (RCTBridge *)bridge
258
179
  {
259
- return @{};
180
+ return self.rootViewFactory.bridge;
181
+ }
182
+
183
+ - (RCTSurfacePresenterBridgeAdapter *)bridgeAdapter
184
+ {
185
+ return self.rootViewFactory.bridgeAdapter;
186
+ }
187
+
188
+ - (void)setBridge:(RCTBridge *)bridge
189
+ {
190
+ self.rootViewFactory.bridge = bridge;
191
+ }
192
+
193
+ - (void)setBridgeAdapter:(RCTSurfacePresenterBridgeAdapter *)bridgeAdapter
194
+ {
195
+ self.rootViewFactory.bridgeAdapter = bridgeAdapter;
260
196
  }
261
197
 
262
198
  #pragma mark - RCTTurboModuleManagerDelegate
@@ -288,43 +224,33 @@ static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabri
288
224
  return RCTAppSetupDefaultModuleFromClass(moduleClass);
289
225
  }
290
226
 
291
- #pragma mark - New Arch Utilities
227
+ #pragma mark - RCTComponentViewFactoryComponentProvider
292
228
 
293
- - (void)createReactHost
229
+ - (NSDictionary<NSString *, Class<RCTComponentViewProtocol>> *)thirdPartyFabricComponents
294
230
  {
295
- __weak __typeof(self) weakSelf = self;
296
- _reactHost = [[RCTHost alloc] initWithBundleURL:[self bundleURL]
297
- hostDelegate:nil
298
- turboModuleManagerDelegate:self
299
- jsEngineProvider:^std::shared_ptr<facebook::react::JSRuntimeFactory>() {
300
- return [weakSelf createJSRuntimeFactory];
301
- }];
302
- [_reactHost setBundleURLProvider:^NSURL *() {
303
- return [weakSelf bundleURL];
304
- }];
305
- [_reactHost setContextContainerHandler:self];
306
- [_reactHost start];
231
+ return @{};
307
232
  }
308
233
 
309
- - (std::shared_ptr<facebook::react::JSRuntimeFactory>)createJSRuntimeFactory
234
+ - (RCTRootViewFactory *)createRCTRootViewFactory
310
235
  {
311
- #if USE_HERMES
312
- return std::make_shared<facebook::react::RCTHermesInstance>(_reactNativeConfig, nullptr);
313
- #else
314
- return std::make_shared<facebook::react::RCTJscInstance>();
315
- #endif
316
- }
236
+ RCTRootViewFactoryConfiguration *configuration =
237
+ [[RCTRootViewFactoryConfiguration alloc] initWithBundleURL:self.bundleURL
238
+ newArchEnabled:self.fabricEnabled
239
+ turboModuleEnabled:self.turboModuleEnabled
240
+ bridgelessEnabled:self.bridgelessEnabled];
317
241
 
318
- - (void)didCreateContextContainer:(std::shared_ptr<facebook::react::ContextContainer>)contextContainer
319
- {
320
- contextContainer->insert("ReactNativeConfig", _reactNativeConfig);
321
- }
242
+ __weak __typeof(self) weakSelf = self;
243
+ configuration.createRootViewWithBridge = ^UIView *(RCTBridge *bridge, NSString *moduleName, NSDictionary *initProps)
244
+ {
245
+ return [weakSelf createRootViewWithBridge:bridge moduleName:moduleName initProps:initProps];
246
+ };
322
247
 
323
- - (NSURL *)bundleURL
324
- {
325
- [NSException raise:@"RCTAppDelegate::bundleURL not implemented"
326
- format:@"Subclasses must implement a valid getBundleURL method"];
327
- return nullptr;
248
+ configuration.createBridgeWithDelegate = ^RCTBridge *(id<RCTBridgeDelegate> delegate, NSDictionary *launchOptions)
249
+ {
250
+ return [weakSelf createBridgeWithDelegate:delegate launchOptions:launchOptions];
251
+ };
252
+
253
+ return [[RCTRootViewFactory alloc] initWithConfiguration:configuration andTurboModuleManagerDelegate:self];
328
254
  }
329
255
 
330
256
  @end
@@ -0,0 +1,123 @@
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
+ #import <React/RCTBridge.h>
9
+ #import <React/RCTRootView.h>
10
+ #import <React/RCTUtils.h>
11
+
12
+ @protocol RCTCxxBridgeDelegate;
13
+ @protocol RCTComponentViewFactoryComponentProvider;
14
+ @protocol RCTTurboModuleManagerDelegate;
15
+ @class RCTBridge;
16
+ @class RCTRootView;
17
+ @class RCTSurfacePresenterBridgeAdapter;
18
+
19
+ NS_ASSUME_NONNULL_BEGIN
20
+
21
+ #pragma mark - Blocks' definitions
22
+ typedef UIView *_Nonnull (
23
+ ^RCTCreateRootViewWithBridgeBlock)(RCTBridge *bridge, NSString *moduleName, NSDictionary *initProps);
24
+ typedef RCTBridge *_Nonnull (
25
+ ^RCTCreateBridgeWithDelegateBlock)(id<RCTBridgeDelegate> delegate, NSDictionary *launchOptions);
26
+
27
+ #pragma mark - RCTRootViewFactory Configuration
28
+ @interface RCTRootViewFactoryConfiguration : NSObject
29
+
30
+ /// This property controls whether the App will use the Fabric renderer of the New Architecture or not.
31
+ @property (nonatomic, assign, readonly) BOOL fabricEnabled;
32
+
33
+ /// This property controls whether React Native's new initialization layer is enabled.
34
+ @property (nonatomic, assign, readonly) BOOL bridgelessEnabled;
35
+
36
+ /// This method controls whether the `turboModules` feature of the New Architecture is turned on or off
37
+ @property (nonatomic, assign, readonly) BOOL turboModuleEnabled;
38
+
39
+ /// Return the bundle URL for the main bundle.
40
+ @property (nonatomic) NSURL *bundleURL;
41
+
42
+ /**
43
+ * Use this method to initialize a new instance of `RCTRootViewFactoryConfiguration` by passing a `bundleURL`
44
+ *
45
+ * Which is the location of the JavaScript source file. When running from the packager
46
+ * this should be an absolute URL, e.g. `http://localhost:8081/index.ios.bundle`.
47
+ * When running from a locally bundled JS file, this should be a `file://` url
48
+ * pointing to a path inside the app resources, e.g. `file://.../main.jsbundle`.
49
+ *
50
+ */
51
+ - (instancetype)initWithBundleURL:(NSURL *)bundleURL
52
+ newArchEnabled:(BOOL)newArchEnabled
53
+ turboModuleEnabled:(BOOL)turboModuleEnabled
54
+ bridgelessEnabled:(BOOL)bridgelessEnabled;
55
+
56
+ /**
57
+ * Block that allows to override logic of creating root view instance.
58
+ * It creates a `UIView` starting from a bridge, a module name and a set of initial properties.
59
+ * By default, it is invoked using the bridge created by `RCTCreateBridgeWithDelegateBlock` (or the default
60
+ * implementation) and the `moduleName` variable comes from `viewWithModuleName:initialProperties:launchOptions` of
61
+ * `RCTRootViewFactory`.
62
+ *
63
+ * @parameter: bridge - an instance of the `RCTBridge` object.
64
+ * @parameter: moduleName - the name of the app, used by Metro to resolve the module.
65
+ * @parameter: initProps - a set of initial properties.
66
+ *
67
+ * @returns: a UIView properly configured with a bridge for React Native.
68
+ */
69
+ @property (nonatomic, nullable) RCTCreateRootViewWithBridgeBlock createRootViewWithBridge;
70
+
71
+ /**
72
+ * Block that allows to override default behavior of creating bridge.
73
+ * It should return `RCTBridge` using a delegate and some launch options.
74
+ *
75
+ * By default, it is invoked passing `self` as a delegate.
76
+ *
77
+ * @parameter: delegate - an object that implements the `RCTBridgeDelegate` protocol.
78
+ * @parameter: launchOptions - a dictionary with a set of options.
79
+ *
80
+ * @returns: a newly created instance of RCTBridge.
81
+ */
82
+ @property (nonatomic, nullable) RCTCreateBridgeWithDelegateBlock createBridgeWithDelegate;
83
+
84
+ @end
85
+
86
+ #pragma mark - RCTRootViewFactory
87
+ /**
88
+ * The RCTRootViewFactory is an utility class that encapsulates the logic of creating a new RCTRootView based on the
89
+ * current state of the environment. It allows you to initialize your app root view for old architecture, new
90
+ * architecture and bridgless mode.
91
+ *
92
+ * This class is used to initalize rootView in RCTAppDelegate, but you can also use it separately.
93
+ *
94
+ * Create a new instance of this class (make sure to retain it) and call the
95
+ * `viewWithModuleName:initialProperties:launchOptions` method to create new RCTRootView.
96
+ */
97
+ @interface RCTRootViewFactory : NSObject
98
+
99
+ @property (nonatomic, strong, nullable) RCTBridge *bridge;
100
+ @property (nonatomic, strong, nullable) RCTSurfacePresenterBridgeAdapter *bridgeAdapter;
101
+
102
+ - (instancetype)initWithConfiguration:(RCTRootViewFactoryConfiguration *)configuration
103
+ andTurboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)turboModuleManagerDelegate;
104
+
105
+ /**
106
+ * This method can be used to create new RCTRootViews on demand.
107
+ *
108
+ * @parameter: moduleName - the name of the app, used by Metro to resolve the module.
109
+ * @parameter: initialProperties - a set of initial properties.
110
+ * @parameter: moduleName - a dictionary with a set of options.
111
+ */
112
+ - (UIView *_Nonnull)viewWithModuleName:(NSString *)moduleName
113
+ initialProperties:(NSDictionary *__nullable)initialProperties
114
+ launchOptions:(NSDictionary *__nullable)launchOptions;
115
+
116
+ - (UIView *_Nonnull)viewWithModuleName:(NSString *)moduleName
117
+ initialProperties:(NSDictionary *__nullable)initialProperties;
118
+
119
+ - (UIView *_Nonnull)viewWithModuleName:(NSString *)moduleName;
120
+
121
+ @end
122
+
123
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,253 @@
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
+ #import "RCTRootViewFactory.h"
9
+ #import <React/RCTCxxBridgeDelegate.h>
10
+ #import <React/RCTLog.h>
11
+ #import <React/RCTRootView.h>
12
+ #import <React/RCTSurfacePresenterBridgeAdapter.h>
13
+ #import <React/RCTUtils.h>
14
+ #import <react/renderer/runtimescheduler/RuntimeScheduler.h>
15
+ #import "RCTAppDelegate.h"
16
+ #import "RCTAppSetupUtils.h"
17
+
18
+ #if RN_DISABLE_OSS_PLUGIN_HEADER
19
+ #import <RCTTurboModulePlugin/RCTTurboModulePlugin.h>
20
+ #else
21
+ #import <React/CoreModulesPlugins.h>
22
+ #endif
23
+ #import <React/RCTBundleURLProvider.h>
24
+ #import <React/RCTComponentViewFactory.h>
25
+ #import <React/RCTComponentViewProtocol.h>
26
+ #import <React/RCTFabricSurface.h>
27
+ #import <React/RCTSurfaceHostingProxyRootView.h>
28
+ #import <React/RCTSurfacePresenter.h>
29
+ #import <ReactCommon/RCTContextContainerHandling.h>
30
+ #if USE_HERMES
31
+ #import <ReactCommon/RCTHermesInstance.h>
32
+ #else
33
+ #import <ReactCommon/RCTJscInstance.h>
34
+ #endif
35
+ #import <ReactCommon/RCTHost+Internal.h>
36
+ #import <ReactCommon/RCTHost.h>
37
+ #import <ReactCommon/RCTTurboModuleManager.h>
38
+ #import <react/config/ReactNativeConfig.h>
39
+ #import <react/renderer/runtimescheduler/RuntimeScheduler.h>
40
+ #import <react/renderer/runtimescheduler/RuntimeSchedulerCallInvoker.h>
41
+ #import <react/runtime/JSRuntimeFactory.h>
42
+
43
+ static NSString *const kRNConcurrentRoot = @"concurrentRoot";
44
+
45
+ static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabricEnabled)
46
+ {
47
+ NSMutableDictionary *mutableProps = initialProps != NULL ? [initialProps mutableCopy] : [NSMutableDictionary new];
48
+ // Hardcoding the Concurrent Root as it it not recommended to
49
+ // have the concurrentRoot turned off when Fabric is enabled.
50
+ mutableProps[kRNConcurrentRoot] = @(isFabricEnabled);
51
+ return mutableProps;
52
+ }
53
+
54
+ @implementation RCTRootViewFactoryConfiguration
55
+
56
+ - (instancetype)initWithBundleURL:(NSURL *)bundleURL
57
+ newArchEnabled:(BOOL)newArchEnabled
58
+ turboModuleEnabled:(BOOL)turboModuleEnabled
59
+ bridgelessEnabled:(BOOL)bridgelessEnabled
60
+ {
61
+ if (self = [super init]) {
62
+ _bundleURL = bundleURL;
63
+ _fabricEnabled = newArchEnabled;
64
+ _turboModuleEnabled = turboModuleEnabled;
65
+ _bridgelessEnabled = bridgelessEnabled;
66
+ }
67
+ return self;
68
+ }
69
+
70
+ @end
71
+
72
+ @interface RCTRootViewFactory () <RCTContextContainerHandling> {
73
+ std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig;
74
+ facebook::react::ContextContainer::Shared _contextContainer;
75
+ }
76
+ @end
77
+
78
+ @interface RCTRootViewFactory () <RCTCxxBridgeDelegate> {
79
+ std::shared_ptr<facebook::react::RuntimeScheduler> _runtimeScheduler;
80
+ }
81
+ @end
82
+
83
+ @implementation RCTRootViewFactory {
84
+ RCTHost *_reactHost;
85
+ RCTRootViewFactoryConfiguration *_configuration;
86
+ __weak id<RCTTurboModuleManagerDelegate> _turboModuleManagerDelegate;
87
+ }
88
+
89
+ - (instancetype)initWithConfiguration:(RCTRootViewFactoryConfiguration *)configuration
90
+ andTurboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)turboModuleManagerDelegate
91
+ {
92
+ if (self = [super init]) {
93
+ _configuration = configuration;
94
+ _contextContainer = std::make_shared<facebook::react::ContextContainer const>();
95
+ _reactNativeConfig = std::make_shared<facebook::react::EmptyReactNativeConfig const>();
96
+ _contextContainer->insert("ReactNativeConfig", _reactNativeConfig);
97
+ _turboModuleManagerDelegate = turboModuleManagerDelegate;
98
+ }
99
+ return self;
100
+ }
101
+
102
+ - (UIView *)viewWithModuleName:(NSString *)moduleName initialProperties:(NSDictionary *)initialProperties
103
+ {
104
+ return [self viewWithModuleName:moduleName initialProperties:initialProperties launchOptions:nil];
105
+ }
106
+
107
+ - (UIView *)viewWithModuleName:(NSString *)moduleName
108
+ {
109
+ return [self viewWithModuleName:moduleName initialProperties:nil launchOptions:nil];
110
+ }
111
+
112
+ - (UIView *)viewWithModuleName:(NSString *)moduleName
113
+ initialProperties:(NSDictionary *)initialProperties
114
+ launchOptions:(NSDictionary *)launchOptions
115
+ {
116
+ NSDictionary *initProps = updateInitialProps(initialProperties, self->_configuration.fabricEnabled);
117
+
118
+ if (self->_configuration.bridgelessEnabled) {
119
+ // Enable native view config interop only if both bridgeless mode and Fabric is enabled.
120
+ RCTSetUseNativeViewConfigsInBridgelessMode(self->_configuration.fabricEnabled);
121
+
122
+ // Enable TurboModule interop by default in Bridgeless mode
123
+ RCTEnableTurboModuleInterop(YES);
124
+ RCTEnableTurboModuleInteropBridgeProxy(YES);
125
+
126
+ [self createReactHostIfNeeded];
127
+
128
+ RCTFabricSurface *surface = [_reactHost createSurfaceWithModuleName:moduleName initialProperties:initProps];
129
+
130
+ RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView = [[RCTSurfaceHostingProxyRootView alloc]
131
+ initWithSurface:surface
132
+ sizeMeasureMode:RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact];
133
+
134
+ return surfaceHostingProxyRootView;
135
+ }
136
+
137
+ [self createBridgeIfNeeded:launchOptions];
138
+ [self createBridgeAdapterIfNeeded];
139
+
140
+ if (self->_configuration.createRootViewWithBridge != nil) {
141
+ return self->_configuration.createRootViewWithBridge(self.bridge, moduleName, initProps);
142
+ }
143
+
144
+ return [self createRootViewWithBridge:self.bridge moduleName:moduleName initProps:initProps];
145
+ }
146
+
147
+ - (RCTBridge *)createBridgeWithDelegate:(id<RCTBridgeDelegate>)delegate launchOptions:(NSDictionary *)launchOptions
148
+ {
149
+ return [[RCTBridge alloc] initWithDelegate:delegate launchOptions:launchOptions];
150
+ }
151
+
152
+ - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge
153
+ moduleName:(NSString *)moduleName
154
+ initProps:(NSDictionary *)initProps
155
+ {
156
+ BOOL enableFabric = self->_configuration.fabricEnabled;
157
+ UIView *rootView = RCTAppSetupDefaultRootView(bridge, moduleName, initProps, enableFabric);
158
+
159
+ rootView.backgroundColor = [UIColor systemBackgroundColor];
160
+
161
+ return rootView;
162
+ }
163
+
164
+ #pragma mark - RCTCxxBridgeDelegate
165
+ - (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
166
+ {
167
+ _runtimeScheduler = std::make_shared<facebook::react::RuntimeScheduler>(RCTRuntimeExecutorFromBridge(bridge));
168
+ if (RCTIsNewArchEnabled()) {
169
+ std::shared_ptr<facebook::react::CallInvoker> callInvoker =
170
+ std::make_shared<facebook::react::RuntimeSchedulerCallInvoker>(_runtimeScheduler);
171
+ RCTTurboModuleManager *turboModuleManager =
172
+ [[RCTTurboModuleManager alloc] initWithBridge:bridge
173
+ delegate:_turboModuleManagerDelegate
174
+ jsInvoker:callInvoker];
175
+ _contextContainer->erase("RuntimeScheduler");
176
+ _contextContainer->insert("RuntimeScheduler", _runtimeScheduler);
177
+ return RCTAppSetupDefaultJsExecutorFactory(bridge, turboModuleManager, _runtimeScheduler);
178
+ } else {
179
+ return RCTAppSetupJsExecutorFactoryForOldArch(bridge, _runtimeScheduler);
180
+ }
181
+ }
182
+
183
+ - (void)createBridgeIfNeeded:(NSDictionary *)launchOptions
184
+ {
185
+ if (self.bridge != nil) {
186
+ return;
187
+ }
188
+
189
+ if (self->_configuration.createBridgeWithDelegate != nil) {
190
+ self.bridge = self->_configuration.createBridgeWithDelegate(self, launchOptions);
191
+ } else {
192
+ self.bridge = [self createBridgeWithDelegate:self launchOptions:launchOptions];
193
+ }
194
+ }
195
+
196
+ - (void)createBridgeAdapterIfNeeded
197
+ {
198
+ if (!self->_configuration.fabricEnabled || self.bridgeAdapter) {
199
+ return;
200
+ }
201
+
202
+ self.bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:self.bridge
203
+ contextContainer:_contextContainer];
204
+ self.bridge.surfacePresenter = self.bridgeAdapter.surfacePresenter;
205
+ }
206
+
207
+ #pragma mark - New Arch Utilities
208
+
209
+ - (void)createReactHostIfNeeded
210
+ {
211
+ if (_reactHost) {
212
+ return;
213
+ }
214
+
215
+ __weak __typeof(self) weakSelf = self;
216
+ _reactHost = [[RCTHost alloc] initWithBundleURL:[self bundleURL]
217
+ hostDelegate:nil
218
+ turboModuleManagerDelegate:_turboModuleManagerDelegate
219
+ jsEngineProvider:^std::shared_ptr<facebook::react::JSRuntimeFactory>() {
220
+ return [weakSelf createJSRuntimeFactory];
221
+ }];
222
+ [_reactHost setBundleURLProvider:^NSURL *() {
223
+ return [weakSelf bundleURL];
224
+ }];
225
+ [_reactHost setContextContainerHandler:self];
226
+ [_reactHost start];
227
+ }
228
+
229
+ - (std::shared_ptr<facebook::react::JSRuntimeFactory>)createJSRuntimeFactory
230
+ {
231
+ #if USE_HERMES
232
+ return std::make_shared<facebook::react::RCTHermesInstance>(_reactNativeConfig, nullptr);
233
+ #else
234
+ return std::make_shared<facebook::react::RCTJscInstance>();
235
+ #endif
236
+ }
237
+
238
+ - (void)didCreateContextContainer:(std::shared_ptr<facebook::react::ContextContainer>)contextContainer
239
+ {
240
+ contextContainer->insert("ReactNativeConfig", _reactNativeConfig);
241
+ }
242
+
243
+ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
244
+ {
245
+ return [self bundleURL];
246
+ }
247
+
248
+ - (NSURL *)bundleURL
249
+ {
250
+ return self->_configuration.bundleURL;
251
+ }
252
+
253
+ @end
@@ -144,6 +144,7 @@ const ReactNativeStyleAttributes: {[string]: AnyAttributeType, ...} = {
144
144
  borderTopLeftRadius: true,
145
145
  borderTopRightRadius: true,
146
146
  borderTopStartRadius: true,
147
+ cursor: true,
147
148
  opacity: true,
148
149
  pointerEvents: true,
149
150
 
@@ -17,7 +17,7 @@ const version: $ReadOnly<{
17
17
  major: 0,
18
18
  minor: 74,
19
19
  patch: 0,
20
- prerelease: 'rc.2',
20
+ prerelease: 'rc.4',
21
21
  };
22
22
 
23
23
  module.exports = {version};