From 951efc8ce2a6d34aa6df6d1ad205db2661143855 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Wed, 22 Nov 2023 03:50:29 -0800 Subject: [PATCH] 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 --- .../Libraries/AppDelegate/RCTAppDelegate.h | 3 - .../Libraries/AppDelegate/RCTAppDelegate.mm | 87 ++++++++----------- .../Libraries/AppDelegate/RCTAppSetupUtils.h | 7 +- .../Libraries/AppDelegate/RCTAppSetupUtils.mm | 10 --- packages/rn-tester/RNTester/AppDelegate.mm | 6 -- 5 files changed, 37 insertions(+), 76 deletions(-) diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h index 71739d159ff40c..f6a35caf3f0cb3 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h @@ -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 diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm index 3f3bb759ba63e8..414534f9fb4dbe 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm @@ -13,7 +13,6 @@ #import "RCTAppSetupUtils.h" #import "RCTLegacyInteropComponents.h" -#if RCT_NEW_ARCH_ENABLED #if RN_DISABLE_OSS_PLUGIN_HEADER #import #else @@ -51,19 +50,13 @@ @interface RCTAppDelegate () < } @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 () { @@ -72,12 +65,9 @@ @interface RCTAppDelegate () { @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 @@ - (instancetype)init } 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 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( sizeMeasureMode:RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact]; rootView = (RCTRootView *)surfaceHostingProxyRootView; -#endif } else { if (!self.bridge) { self.bridge = [self createBridgeWithDelegate:self launchOptions:launchOptions]; @@ -170,10 +154,7 @@ - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge 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 @@ - (void)windowScene:(UIWindowScene *)windowScene #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> *)thirdPartyFabricComponents +{ + return @{}; +} #pragma mark - RCTTurboModuleManagerDelegate @@ -254,30 +265,6 @@ - (Class)getModuleClassFromName:(const char *)name return RCTAppSetupDefaultModuleFromClass(moduleClass); } -#pragma mark - RCTComponentViewFactoryComponentProvider - -- (NSDictionary> *)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 @@ - (NSURL *)bundleURL return nullptr; } -#endif - @end diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.h b/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.h index e1c69078409caf..d661fb4355c1c1 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.h +++ b/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.h @@ -26,28 +26,23 @@ #endif #endif -#if RCT_NEW_ARCH_ENABLED #import -#endif // Forward declaration to decrease compilation coupling namespace facebook::react { class RuntimeScheduler; } -#if RCT_NEW_ARCH_ENABLED - RCT_EXTERN id RCTAppSetupDefaultModuleFromClass(Class moduleClass); std::unique_ptr RCTAppSetupDefaultJsExecutorFactory( RCTBridge *bridge, RCTTurboModuleManager *turboModuleManager, const std::shared_ptr &runtimeScheduler); -#else + std::unique_ptr RCTAppSetupJsExecutorFactoryForOldArch( RCTBridge *bridge, const std::shared_ptr &runtimeScheduler); -#endif #endif // __cplusplus diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm b/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm index 6241f62831cf40..3127588b7de0a1 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm @@ -11,7 +11,6 @@ #import #import -#if RCT_NEW_ARCH_ENABLED // Turbo Module #import #import @@ -24,13 +23,10 @@ // Fabric #import #import -#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 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 RCTAppSetupDefaultModuleFromClass(Class moduleClass) { // Set up the default RCTImageLoader and RCTNetworking modules. @@ -114,8 +107,6 @@ void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled) })); } -#else // else !RCT_NEW_ARCH_ENABLED - std::unique_ptr RCTAppSetupJsExecutorFactoryForOldArch( RCTBridge *bridge, const std::shared_ptr &runtimeScheduler) @@ -134,4 +125,3 @@ void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled) } })); } -#endif // end RCT_NEW_ARCH_ENABLED diff --git a/packages/rn-tester/RNTester/AppDelegate.mm b/packages/rn-tester/RNTester/AppDelegate.mm index a7fa095e5bc2e6..0692f5b4cb5eea 100644 --- a/packages/rn-tester/RNTester/AppDelegate.mm +++ b/packages/rn-tester/RNTester/AppDelegate.mm @@ -16,12 +16,10 @@ #import #endif -#if RCT_NEW_ARCH_ENABLED #import #ifndef RN_DISABLE_OSS_PLUGIN_HEADER #import #endif -#endif // FB-internal imports #ifdef RN_DISABLE_OSS_PLUGIN_HEADER @@ -88,11 +86,9 @@ - (void)loadSourceForBridge:(RCTBridge *)bridge if (name == std::string([@"SampleTurboCxxModule" UTF8String])) { return std::make_shared(jsInvoker); } -#ifdef RCT_NEW_ARCH_ENABLED if (name == facebook::react::NativeCxxModuleExample::kModuleName) { return std::make_shared(jsInvoker); } -#endif return nullptr; } @@ -129,7 +125,6 @@ - (void)application:(__unused UIApplication *)application #pragma mark - RCTComponentViewFactoryComponentProvider -#if RCT_NEW_ARCH_ENABLED #ifndef RN_DISABLE_OSS_PLUGIN_HEADER - (nonnull NSDictionary> *)thirdPartyFabricComponents { @@ -141,6 +136,5 @@ - (NSURL *)bundleURL { return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:kBundlePath]; } -#endif @end