Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react-native-host): override feature flags for bridgeless mode #3196

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading