Skip to content

Commit

Permalink
fix(react-native-host): override feature flags for bridgeless mode (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 committed Jun 19, 2024
1 parent a4d5c18 commit 99bcb24
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-moose-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rnx-kit/react-native-host": patch
---

Override feature flags for bridgeless mode
28 changes: 28 additions & 0 deletions packages/react-native-host/cocoa/RNXBridgelessHeaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

#import <react/config/ReactNativeConfig.h>

#if __has_include(<react/featureflags/ReactNativeFeatureFlags.h>)
#import <react/featureflags/ReactNativeFeatureFlags.h>
#import <react/featureflags/ReactNativeFeatureFlagsDefaults.h>
#define USE_FEATURE_FLAGS
#endif // __has_include(<react/featureflags/ReactNativeFeatureFlags.h>)

#if __has_include(<react/runtime/JSEngineInstance.h>)
using SharedJSRuntimeFactory = std::shared_ptr<facebook::react::JSEngineInstance>;
#else
Expand Down Expand Up @@ -42,6 +48,28 @@ using SharedJSRuntimeFactory = std::shared_ptr<facebook::react::JSRuntimeFactory
- (RCTSurfacePresenter *)getSurfacePresenter; // Deprecated in 0.74, and removed in 0.75
@end

#ifdef USE_FEATURE_FLAGS
// https://github.com/facebook/react-native/blob/0.74-stable/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm#L272-L286
class RNXBridgelessFeatureFlags : public facebook::react::ReactNativeFeatureFlagsDefaults
{
public:
bool useModernRuntimeScheduler() override
{
return true;
}

bool enableMicrotasks() override
{
return true;
}

bool batchRenderingUpdatesInEventLoop() override
{
return true;
}
};
#endif // USE_FEATURE_FLAGS

#elif USE_FABRIC

#import <React/RCTSurfacePresenterBridgeAdapter.h>
Expand Down
27 changes: 17 additions & 10 deletions packages/react-native-host/cocoa/ReactNativeHost.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ - (instancetype)initWithConfig:(id<RNXHostConfig>)config
- (instancetype)initWithConfig:(id<RNXHostConfig>)config launchOptions:(NSDictionary *)launchOptions
{
if (self = [super init]) {
_config = config;
_launchOptions = launchOptions;
[self enableTurboModule];
_isShuttingDown = [[NSLock alloc] init];

if ([config respondsToSelector:@selector(shouldReleaseBridgeWhenBackgrounded)] &&
[config shouldReleaseBridgeWhenBackgrounded]) {
_hostReleaser = [[RNXHostReleaser alloc] initWithHost:self];
}

#ifdef USE_FEATURE_FLAGS
if (self.isBridgelessEnabled) {
facebook::react::ReactNativeFeatureFlags::override(
std::make_unique<RNXBridgelessFeatureFlags>());
}
#endif // USE_FEATURE_FLAGS

if ([config respondsToSelector:@selector(isDevLoadingViewEnabled)]) {
RCTDevLoadingViewSetEnabled([config isDevLoadingViewEnabled]);
}
Expand All @@ -69,16 +86,6 @@ - (instancetype)initWithConfig:(id<RNXHostConfig>)config launchOptions:(NSDictio
});
}

_config = config;
_launchOptions = launchOptions;
[self enableTurboModule];
_isShuttingDown = [[NSLock alloc] init];

if ([config respondsToSelector:@selector(shouldReleaseBridgeWhenBackgrounded)] &&
[config shouldReleaseBridgeWhenBackgrounded]) {
_hostReleaser = [[RNXHostReleaser alloc] initWithHost:self];
}

[self initializeReactHost];
}
return self;
Expand Down

0 comments on commit 99bcb24

Please sign in to comment.