@rnx-kit/react-native-host 0.4.8 → 0.4.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,6 +12,12 @@
12
12
 
13
13
  #import <react/config/ReactNativeConfig.h>
14
14
 
15
+ #if __has_include(<react/featureflags/ReactNativeFeatureFlags.h>)
16
+ #import <react/featureflags/ReactNativeFeatureFlags.h>
17
+ #import <react/featureflags/ReactNativeFeatureFlagsDefaults.h>
18
+ #define USE_FEATURE_FLAGS
19
+ #endif // __has_include(<react/featureflags/ReactNativeFeatureFlags.h>)
20
+
15
21
  #if __has_include(<react/runtime/JSEngineInstance.h>)
16
22
  using SharedJSRuntimeFactory = std::shared_ptr<facebook::react::JSEngineInstance>;
17
23
  #else
@@ -42,6 +48,28 @@ using SharedJSRuntimeFactory = std::shared_ptr<facebook::react::JSRuntimeFactory
42
48
  - (RCTSurfacePresenter *)getSurfacePresenter; // Deprecated in 0.74, and removed in 0.75
43
49
  @end
44
50
 
51
+ #ifdef USE_FEATURE_FLAGS
52
+ // https://github.com/facebook/react-native/blob/0.74-stable/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm#L272-L286
53
+ class RNXBridgelessFeatureFlags : public facebook::react::ReactNativeFeatureFlagsDefaults
54
+ {
55
+ public:
56
+ bool useModernRuntimeScheduler() override
57
+ {
58
+ return true;
59
+ }
60
+
61
+ bool enableMicrotasks() override
62
+ {
63
+ return true;
64
+ }
65
+
66
+ bool batchRenderingUpdatesInEventLoop() override
67
+ {
68
+ return true;
69
+ }
70
+ };
71
+ #endif // USE_FEATURE_FLAGS
72
+
45
73
  #elif USE_FABRIC
46
74
 
47
75
  #import <React/RCTSurfacePresenterBridgeAdapter.h>
@@ -1,11 +1,17 @@
1
1
  #import "ReactNativeHost.h"
2
2
 
3
+ @class RCTHost;
3
4
  @class RCTSurfacePresenter;
4
5
 
5
6
  NS_ASSUME_NONNULL_BEGIN
6
7
 
7
8
  @interface ReactNativeHost (Private)
8
9
 
10
+ /// Returns the current ``RCTHost`` instance.
11
+ ///
12
+ /// - Note: Returns `nil` if New Architecture is not enabled.
13
+ @property (nonatomic, readonly, nullable) RCTHost *reactHost;
14
+
9
15
  /// Returns the current ``RCTSurfacePresenter`` instance.
10
16
  ///
11
17
  /// - Note: Returns `nil` if New Architecture is not enabled.
@@ -7,8 +7,11 @@
7
7
  #import <React/RCTFabricSurface.h>
8
8
  #import <React/RCTSurfaceHostingProxyRootView.h>
9
9
  #endif // __has_include(<React/RCTFabricSurfaceHostingProxyRootView.h>)
10
+ #ifdef USE_BRIDGELESS
11
+ #import <ReactCommon/RCTHost.h>
12
+ #endif // USE_BRIDGELESS
10
13
  static NSString *const kReactConcurrentRoot = @"concurrentRoot";
11
- #else
14
+ #else // USE_FABRIC
12
15
  #import <React/RCTRootView.h>
13
16
  #endif // USE_FABRIC
14
17
 
@@ -53,6 +56,13 @@ static NSString *const kReactConcurrentRoot = @"concurrentRoot";
53
56
  return [[RCTFabricSurfaceHostingProxyRootView alloc] initWithBridge:self.bridge
54
57
  moduleName:moduleName
55
58
  initialProperties:initialProps];
59
+ #elif USE_BRIDGELESS
60
+ RCTFabricSurface *surface = [self.reactHost createSurfaceWithModuleName:moduleName
61
+ initialProperties:initialProps];
62
+ RCTSurfaceSizeMeasureMode sizeMeasureMode =
63
+ RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact;
64
+ return [[RCTSurfaceHostingProxyRootView alloc] initWithSurface:surface
65
+ sizeMeasureMode:sizeMeasureMode];
56
66
  #else
57
67
  RCTFabricSurface *surface =
58
68
  [[RCTFabricSurface alloc] initWithSurfacePresenter:self.surfacePresenter
@@ -49,6 +49,23 @@ using ReactNativeConfig = facebook::react::EmptyReactNativeConfig const;
49
49
  - (instancetype)initWithConfig:(id<RNXHostConfig>)config launchOptions:(NSDictionary *)launchOptions
50
50
  {
51
51
  if (self = [super init]) {
52
+ _config = config;
53
+ _launchOptions = launchOptions;
54
+ [self enableTurboModule];
55
+ _isShuttingDown = [[NSLock alloc] init];
56
+
57
+ if ([config respondsToSelector:@selector(shouldReleaseBridgeWhenBackgrounded)] &&
58
+ [config shouldReleaseBridgeWhenBackgrounded]) {
59
+ _hostReleaser = [[RNXHostReleaser alloc] initWithHost:self];
60
+ }
61
+
62
+ #ifdef USE_FEATURE_FLAGS
63
+ if (self.isBridgelessEnabled) {
64
+ facebook::react::ReactNativeFeatureFlags::override(
65
+ std::make_unique<RNXBridgelessFeatureFlags>());
66
+ }
67
+ #endif // USE_FEATURE_FLAGS
68
+
52
69
  if ([config respondsToSelector:@selector(isDevLoadingViewEnabled)]) {
53
70
  RCTDevLoadingViewSetEnabled([config isDevLoadingViewEnabled]);
54
71
  }
@@ -69,16 +86,6 @@ using ReactNativeConfig = facebook::react::EmptyReactNativeConfig const;
69
86
  });
70
87
  }
71
88
 
72
- _config = config;
73
- _launchOptions = launchOptions;
74
- [self enableTurboModule];
75
- _isShuttingDown = [[NSLock alloc] init];
76
-
77
- if ([config respondsToSelector:@selector(shouldReleaseBridgeWhenBackgrounded)] &&
78
- [config shouldReleaseBridgeWhenBackgrounded]) {
79
- _hostReleaser = [[RNXHostReleaser alloc] initWithHost:self];
80
- }
81
-
82
89
  [self initializeReactHost];
83
90
  }
84
91
  return self;
@@ -108,6 +115,11 @@ using ReactNativeConfig = facebook::react::EmptyReactNativeConfig const;
108
115
  }
109
116
  }
110
117
 
118
+ - (RCTHost *)reactHost
119
+ {
120
+ return _reactHost;
121
+ }
122
+
111
123
  - (RCTSurfacePresenter *)surfacePresenter
112
124
  {
113
125
  #if USE_BRIDGELESS
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rnx-kit/react-native-host",
3
- "version": "0.4.8",
3
+ "version": "0.4.10",
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",