Remove some usages of RCT_NEW_ARCH_ENABLED (#41589)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41589

This is a cleanup diffs that removes some of the usages of RCT_NEW_ARCH_ENABLED.
Now that we are shipping all the pods, there is no need to conditionally compile-out part of the codebase depending on whether the new architecture is running or not.

This change will not alter the behavior of the app.

## Changelog:
[iOS][Breaking] - Remove some usages of RCT_NEW_ARCH_ENABLED. The change should be transparent BUT some **Swift** libraries might get broken by this change.

Reviewed By: dmytrorykun

Differential Revision: D51498730

fbshipit-source-id: c83416480eea1f7bbc55f72c31e7b69ad0e9e01a
This commit is contained in:
Riccardo Cipolleschi
2023-11-22 03:50:29 -08:00
committed by Facebook GitHub Bot
parent 6b5320540a
commit 951efc8ce2
5 changed files with 37 additions and 76 deletions
@@ -109,7 +109,6 @@
/// @return: `YES` to use RuntimeScheduler, `NO` to use JavaScript scheduler. The default value is `YES`.
- (BOOL)runtimeSchedulerEnabled;
#if RCT_NEW_ARCH_ENABLED
@property (nonatomic, strong) RCTSurfacePresenterBridgeAdapter *bridgeAdapter;
/// This method returns a map of Component Descriptors and Components classes that needs to be registered in the
@@ -139,6 +138,4 @@
/// Return the bundle URL for the main bundle.
- (NSURL *)bundleURL;
#endif
@end
@@ -13,7 +13,6 @@
#import "RCTAppSetupUtils.h"
#import "RCTLegacyInteropComponents.h"
#if RCT_NEW_ARCH_ENABLED
#if RN_DISABLE_OSS_PLUGIN_HEADER
#import <RCTTurboModulePlugin/RCTTurboModulePlugin.h>
#else
@@ -51,19 +50,13 @@ static NSString *const kRNConcurrentRoot = @"concurrentRoot";
}
@end
#endif
static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabricEnabled)
{
#ifdef RCT_NEW_ARCH_ENABLED
NSMutableDictionary *mutableProps = [initialProps mutableCopy] ?: [NSMutableDictionary new];
// Hardcoding the Concurrent Root as it it not recommended to
// have the concurrentRoot turned off when Fabric is enabled.
mutableProps[kRNConcurrentRoot] = @(isFabricEnabled);
return mutableProps;
#else
return initialProps;
#endif
}
@interface RCTAppDelegate () <RCTCxxBridgeDelegate> {
@@ -72,12 +65,9 @@ static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabri
@end
@implementation RCTAppDelegate {
#if RCT_NEW_ARCH_ENABLED
RCTHost *_reactHost;
#endif
}
#if RCT_NEW_ARCH_ENABLED
- (instancetype)init
{
if (self = [super init]) {
@@ -87,25 +77,20 @@ static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabri
}
return self;
}
#endif
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
BOOL enableTM = NO;
BOOL enableBridgeless = NO;
BOOL fabricEnabled = NO;
#if RCT_NEW_ARCH_ENABLED
enableTM = self.turboModuleEnabled;
enableBridgeless = self.bridgelessEnabled;
fabricEnabled = [self fabricEnabled];
#endif
BOOL enableTM = self.turboModuleEnabled;
;
BOOL enableBridgeless = self.bridgelessEnabled;
BOOL fabricEnabled = self.fabricEnabled;
NSDictionary *initProps = updateInitialProps([self prepareInitialProps], fabricEnabled);
RCTAppSetupPrepareApp(application, enableTM);
UIView *rootView;
if (enableBridgeless) {
#if RCT_NEW_ARCH_ENABLED
// Enable native view config interop only if both bridgeless mode and Fabric is enabled.
RCTSetUseNativeViewConfigsInBridgelessMode(fabricEnabled);
@@ -123,7 +108,6 @@ static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabri
sizeMeasureMode:RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact];
rootView = (RCTRootView *)surfaceHostingProxyRootView;
#endif
} else {
if (!self.bridge) {
self.bridge = [self createBridgeWithDelegate:self launchOptions:launchOptions];
@@ -170,10 +154,7 @@ static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabri
moduleName:(NSString *)moduleName
initProps:(NSDictionary *)initProps
{
BOOL enableFabric = NO;
#if RCT_NEW_ARCH_ENABLED
enableFabric = self.fabricEnabled;
#endif
BOOL enableFabric = self.fabricEnabled;
UIView *rootView = RCTAppSetupDefaultRootView(bridge, moduleName, initProps, enableFabric);
rootView.backgroundColor = [UIColor systemBackgroundColor];
@@ -223,7 +204,37 @@ static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabri
#endif
}
#pragma mark - New Arch Enabled settings
- (BOOL)turboModuleEnabled
{
#if RCT_NEW_ARCH_ENABLED
return YES;
#else
return NO;
#endif
}
- (BOOL)fabricEnabled
{
#if RCT_NEW_ARCH_ENABLED
return YES;
#else
return NO;
#endif
}
- (BOOL)bridgelessEnabled
{
return NO;
}
#pragma mark - RCTComponentViewFactoryComponentProvider
- (NSDictionary<NSString *, Class<RCTComponentViewProtocol>> *)thirdPartyFabricComponents
{
return @{};
}
#pragma mark - RCTTurboModuleManagerDelegate
@@ -254,30 +265,6 @@ static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabri
return RCTAppSetupDefaultModuleFromClass(moduleClass);
}
#pragma mark - RCTComponentViewFactoryComponentProvider
- (NSDictionary<NSString *, Class<RCTComponentViewProtocol>> *)thirdPartyFabricComponents
{
return @{};
}
#pragma mark - New Arch Enabled settings
- (BOOL)turboModuleEnabled
{
return YES;
}
- (BOOL)fabricEnabled
{
return YES;
}
- (BOOL)bridgelessEnabled
{
return NO;
}
#pragma mark - New Arch Utilities
- (void)unstable_registerLegacyComponents
@@ -324,6 +311,4 @@ static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabri
return nullptr;
}
#endif
@end
@@ -26,28 +26,23 @@
#endif
#endif
#if RCT_NEW_ARCH_ENABLED
#import <ReactCommon/RCTTurboModuleManager.h>
#endif
// Forward declaration to decrease compilation coupling
namespace facebook::react {
class RuntimeScheduler;
}
#if RCT_NEW_ARCH_ENABLED
RCT_EXTERN id<RCTTurboModule> RCTAppSetupDefaultModuleFromClass(Class moduleClass);
std::unique_ptr<facebook::react::JSExecutorFactory> RCTAppSetupDefaultJsExecutorFactory(
RCTBridge *bridge,
RCTTurboModuleManager *turboModuleManager,
const std::shared_ptr<facebook::react::RuntimeScheduler> &runtimeScheduler);
#else
std::unique_ptr<facebook::react::JSExecutorFactory> RCTAppSetupJsExecutorFactoryForOldArch(
RCTBridge *bridge,
const std::shared_ptr<facebook::react::RuntimeScheduler> &runtimeScheduler);
#endif
#endif // __cplusplus
@@ -11,7 +11,6 @@
#import <react/renderer/runtimescheduler/RuntimeScheduler.h>
#import <react/renderer/runtimescheduler/RuntimeSchedulerBinding.h>
#if RCT_NEW_ARCH_ENABLED
// Turbo Module
#import <React/RCTBundleAssetImageLoader.h>
#import <React/RCTDataRequestHandler.h>
@@ -24,13 +23,10 @@
// Fabric
#import <React/RCTFabricSurface.h>
#import <React/RCTSurfaceHostingProxyRootView.h>
#endif
void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled)
{
#if RCT_NEW_ARCH_ENABLED
RCTEnableTurboModule(turboModuleEnabled);
#endif
#if DEBUG
// Disable idle timer in dev builds to avoid putting application in background and complicating
@@ -42,18 +38,15 @@ void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled)
UIView *
RCTAppSetupDefaultRootView(RCTBridge *bridge, NSString *moduleName, NSDictionary *initialProperties, BOOL fabricEnabled)
{
#if RCT_NEW_ARCH_ENABLED
if (fabricEnabled) {
id<RCTSurfaceProtocol> surface = [[RCTFabricSurface alloc] initWithBridge:bridge
moduleName:moduleName
initialProperties:initialProperties];
return [[RCTSurfaceHostingProxyRootView alloc] initWithSurface:surface];
}
#endif
return [[RCTRootView alloc] initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
}
#if RCT_NEW_ARCH_ENABLED
id<RCTTurboModule> RCTAppSetupDefaultModuleFromClass(Class moduleClass)
{
// Set up the default RCTImageLoader and RCTNetworking modules.
@@ -114,8 +107,6 @@ std::unique_ptr<facebook::react::JSExecutorFactory> RCTAppSetupDefaultJsExecutor
}));
}
#else // else !RCT_NEW_ARCH_ENABLED
std::unique_ptr<facebook::react::JSExecutorFactory> RCTAppSetupJsExecutorFactoryForOldArch(
RCTBridge *bridge,
const std::shared_ptr<facebook::react::RuntimeScheduler> &runtimeScheduler)
@@ -134,4 +125,3 @@ std::unique_ptr<facebook::react::JSExecutorFactory> RCTAppSetupJsExecutorFactory
}
}));
}
#endif // end RCT_NEW_ARCH_ENABLED
@@ -16,12 +16,10 @@
#import <React/RCTPushNotificationManager.h>
#endif
#if RCT_NEW_ARCH_ENABLED
#import <NativeCxxModuleExample/NativeCxxModuleExample.h>
#ifndef RN_DISABLE_OSS_PLUGIN_HEADER
#import <RNTMyNativeViewComponentView.h>
#endif
#endif
// FB-internal imports
#ifdef RN_DISABLE_OSS_PLUGIN_HEADER
@@ -88,11 +86,9 @@ NSString *kBundlePath = @"js/RNTesterApp.ios";
if (name == std::string([@"SampleTurboCxxModule" UTF8String])) {
return std::make_shared<facebook::react::SampleTurboCxxModule>(jsInvoker);
}
#ifdef RCT_NEW_ARCH_ENABLED
if (name == facebook::react::NativeCxxModuleExample::kModuleName) {
return std::make_shared<facebook::react::NativeCxxModuleExample>(jsInvoker);
}
#endif
return nullptr;
}
@@ -129,7 +125,6 @@ NSString *kBundlePath = @"js/RNTesterApp.ios";
#pragma mark - RCTComponentViewFactoryComponentProvider
#if RCT_NEW_ARCH_ENABLED
#ifndef RN_DISABLE_OSS_PLUGIN_HEADER
- (nonnull NSDictionary<NSString *, Class<RCTComponentViewProtocol>> *)thirdPartyFabricComponents
{
@@ -141,6 +136,5 @@ NSString *kBundlePath = @"js/RNTesterApp.ios";
{
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:kBundlePath];
}
#endif
@end