Skip to content

Commit

Permalink
Remove some usages of RCT_NEW_ARCH_ENABLED (#41589)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
cipolleschi authored and facebook-github-bot committed Nov 22, 2023
1 parent 6b53205 commit 951efc8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 76 deletions.
3 changes: 0 additions & 3 deletions packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -139,6 +138,4 @@
/// Return the bundle URL for the main bundle.
- (NSURL *)bundleURL;

#endif

@end
87 changes: 36 additions & 51 deletions packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 () <RCTCxxBridgeDelegate> {
Expand All @@ -72,12 +65,9 @@ @interface RCTAppDelegate () <RCTCxxBridgeDelegate> {
@end

@implementation RCTAppDelegate {
#if RCT_NEW_ARCH_ENABLED
RCTHost *_reactHost;
#endif
}

#if RCT_NEW_ARCH_ENABLED
- (instancetype)init
{
if (self = [super init]) {
Expand All @@ -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);

Expand All @@ -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];
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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<NSString *, Class<RCTComponentViewProtocol>> *)thirdPartyFabricComponents
{
return @{};
}

#pragma mark - RCTTurboModuleManagerDelegate

Expand Down Expand Up @@ -254,30 +265,6 @@ - (Class)getModuleClassFromName:(const char *)name
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
Expand Down Expand Up @@ -324,6 +311,4 @@ - (NSURL *)bundleURL
return nullptr;
}

#endif

@end
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 0 additions & 10 deletions packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -114,8 +107,6 @@ void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled)
}));
}

#else // else !RCT_NEW_ARCH_ENABLED

std::unique_ptr<facebook::react::JSExecutorFactory> RCTAppSetupJsExecutorFactoryForOldArch(
RCTBridge *bridge,
const std::shared_ptr<facebook::react::RuntimeScheduler> &runtimeScheduler)
Expand All @@ -134,4 +125,3 @@ void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled)
}
}));
}
#endif // end RCT_NEW_ARCH_ENABLED
6 changes: 0 additions & 6 deletions packages/rn-tester/RNTester/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -88,11 +86,9 @@ - (void)loadSourceForBridge:(RCTBridge *)bridge
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;
}

Expand Down Expand Up @@ -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<NSString *, Class<RCTComponentViewProtocol>> *)thirdPartyFabricComponents
{
Expand All @@ -141,6 +136,5 @@ - (NSURL *)bundleURL
{
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:kBundlePath];
}
#endif

@end

0 comments on commit 951efc8

Please sign in to comment.