@rnx-kit/react-native-host 0.4.2 → 0.4.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.
@@ -67,13 +67,13 @@
67
67
 
68
68
  // MARK: - RCTTurboModuleManagerDelegate details
69
69
 
70
- - (Class)getModuleClassFromName:(const char *)name
70
+ - (Class)getModuleClassFromName:(char const *)name
71
71
  {
72
72
  return RCTCoreModulesClassProvider(name);
73
73
  }
74
74
 
75
75
  - (std::shared_ptr<facebook::react::TurboModule>)
76
- getTurboModule:(const std::string &)name
76
+ getTurboModule:(std::string const &)name
77
77
  jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
78
78
  {
79
79
  return nullptr;
@@ -7,6 +7,7 @@
7
7
  #import <React/RCTFabricSurface.h>
8
8
  #import <React/RCTSurfaceHostingProxyRootView.h>
9
9
  #endif // __has_include(<React/RCTFabricSurfaceHostingProxyRootView.h>)
10
+ static NSString *const kReactConcurrentRoot = @"concurrentRoot";
10
11
  #else
11
12
  #import <React/RCTRootView.h>
12
13
  #endif // USE_FABRIC
@@ -36,15 +37,27 @@
36
37
  initialProperties:(NSDictionary *)initialProperties;
37
38
  {
38
39
  #ifdef USE_FABRIC
40
+ // Having `concurrentRoot` disabled when Fabric is enabled is not recommended:
41
+ // https://github.com/facebook/react-native/commit/7eaabfb174b14a30c30c7017195e8110348e5f44
42
+ // As of 0.74, it won't be possible to opt-out:
43
+ // https://github.com/facebook/react-native/commit/30d186c3683228d4fb7a42f804eb2fdfa7c8ac03
44
+ NSMutableDictionary *initialProps =
45
+ initialProperties == nil
46
+ ? [NSMutableDictionary dictionaryWithObjectsAndKeys:@YES, kReactConcurrentRoot, nil]
47
+ : [initialProperties mutableCopy];
48
+ if (initialProps[kReactConcurrentRoot] == nil) {
49
+ initialProps[kReactConcurrentRoot] = @YES;
50
+ }
51
+
39
52
  #if __has_include(<React/RCTFabricSurfaceHostingProxyRootView.h>)
40
53
  return [[RCTFabricSurfaceHostingProxyRootView alloc] initWithBridge:self.bridge
41
54
  moduleName:moduleName
42
- initialProperties:initialProperties];
55
+ initialProperties:initialProps];
43
56
  #else
44
57
  RCTFabricSurface *surface =
45
58
  [[RCTFabricSurface alloc] initWithSurfacePresenter:self.surfacePresenter
46
59
  moduleName:moduleName
47
- initialProperties:initialProperties];
60
+ initialProperties:initialProps];
48
61
  return [[RCTSurfaceHostingProxyRootView alloc] initWithSurface:surface];
49
62
  #endif // __has_include(<React/RCTFabricSurfaceHostingProxyRootView.h>)
50
63
  #else
@@ -79,9 +79,10 @@ using ReactNativeConfig = facebook::react::EmptyReactNativeConfig const;
79
79
 
80
80
  - (RCTBridge *)bridge
81
81
  {
82
- #if USE_BRIDGELESS
83
- return nil;
84
- #else
82
+ if (self.isBridgelessEnabled) {
83
+ return nil;
84
+ }
85
+
85
86
  if (![_isShuttingDown tryLock]) {
86
87
  NSAssert(NO, @"Tried to access the bridge while shutting down");
87
88
  return nil;
@@ -98,7 +99,6 @@ using ReactNativeConfig = facebook::react::EmptyReactNativeConfig const;
98
99
  } @finally {
99
100
  [_isShuttingDown unlock];
100
101
  }
101
- #endif // USE_BRIDGELESS
102
102
  }
103
103
 
104
104
  - (RCTSurfacePresenter *)surfacePresenter
@@ -126,7 +126,7 @@ using ReactNativeConfig = facebook::react::EmptyReactNativeConfig const;
126
126
 
127
127
  - (void)usingModule:(Class)moduleClass block:(void (^)(id<RCTBridgeModule> _Nullable))block
128
128
  {
129
- const BOOL requiresMainQueueSetup =
129
+ BOOL const requiresMainQueueSetup =
130
130
  [moduleClass respondsToSelector:@selector(requiresMainQueueSetup)] &&
131
131
  [moduleClass requiresMainQueueSetup];
132
132
  if (requiresMainQueueSetup && !RCTIsMainQueue()) {
@@ -137,8 +137,15 @@ using ReactNativeConfig = facebook::react::EmptyReactNativeConfig const;
137
137
  return;
138
138
  }
139
139
 
140
- id<RCTBridgeModule> bridgeModule = [self.bridge moduleForClass:moduleClass];
141
- block(bridgeModule);
140
+ if (!self.isBridgelessEnabled) {
141
+ block([self.bridge moduleForClass:moduleClass]);
142
+ return;
143
+ }
144
+
145
+ #if USE_BRIDGELESS
146
+ const char *moduleName = RCTBridgeModuleNameForClass(moduleClass).UTF8String;
147
+ block([[_reactHost getModuleRegistry] moduleForName:moduleName]);
148
+ #endif // USE_BRIDGELESS
142
149
  }
143
150
 
144
151
  // MARK: - RCTBridgeDelegate details
@@ -193,6 +200,18 @@ using ReactNativeConfig = facebook::react::EmptyReactNativeConfig const;
193
200
 
194
201
  // MARK: - Private
195
202
 
203
+ - (BOOL)isBridgelessEnabled
204
+ {
205
+ #if USE_BRIDGELESS
206
+ // Bridgeless mode is enabled if it was turned on with a build flag, unless
207
+ // `isBridgelessEnabled` is explicitly implemented and returns false.
208
+ return ![_config respondsToSelector:@selector(isBridgelessEnabled)] ||
209
+ [_config isBridgelessEnabled];
210
+ #else
211
+ return NO;
212
+ #endif // USE_BRIDGELESS
213
+ }
214
+
196
215
  - (void)enableTurboModule
197
216
  {
198
217
  #if USE_FABRIC
@@ -203,15 +222,12 @@ using ReactNativeConfig = facebook::react::EmptyReactNativeConfig const;
203
222
 
204
223
  - (void)initializeReactHost
205
224
  {
206
- #if USE_BRIDGELESS
207
- // Bridgeless mode is enabled if it was turned on with a build flag, unless
208
- // `isBridgelessEnabled` is explicitly implemented and returns false.
209
- if ([_config respondsToSelector:@selector(isBridgelessEnabled)] &&
210
- ![_config isBridgelessEnabled]) {
225
+ if (!self.isBridgelessEnabled) {
211
226
  (void)self.bridge; // Initialize the bridge now
212
227
  return;
213
228
  }
214
229
 
230
+ #if USE_BRIDGELESS
215
231
  RCTSetUseNativeViewConfigsInBridgelessMode(YES);
216
232
  RCTEnableTurboModuleInterop(YES);
217
233
  RCTEnableTurboModuleInteropBridgeProxy(YES);
@@ -241,8 +257,6 @@ using ReactNativeConfig = facebook::react::EmptyReactNativeConfig const;
241
257
 
242
258
  [_reactHost setContextContainerHandler:self];
243
259
  [_reactHost start];
244
- #else
245
- (void)self.bridge;
246
260
  #endif // USE_BRIDGELESS
247
261
  }
248
262
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rnx-kit/react-native-host",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "Simplify React Native initialization",
5
5
  "homepage": "https://github.com/microsoft/rnx-kit/tree/main/packages/react-native-host#readme",
6
6
  "license": "MIT",