Skip to content

Commit 83e6eaf

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Prevent users from opting-out of the New Architecture (#53026)
Summary: Pull Request resolved: #53026 This change prevents users from opting out of the New Architecure. The change is non breaking with respect to building an app: all the functions are still there, even if they are unreachable, in case users will still call them explicitly. We hardcoded all the values to enable the New Architecture, so there is no way to disable it. This is a behavioral breaking change, though. ## Changelog: [iOS][Removed] - Removed the opt-out from the New Architecture. Reviewed By: cortinico Differential Revision: D79090048 fbshipit-source-id: 9779bfedf50748d7adbef5f7ef038f469e30efc2
1 parent 01d5eeb commit 83e6eaf

File tree

11 files changed

+62
-118
lines changed

11 files changed

+62
-118
lines changed

packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled)
3333
{
34-
RCTEnableTurboModule(turboModuleEnabled);
34+
RCTEnableTurboModule(YES);
3535

3636
#if DEBUG
3737
// Disable idle timer in dev builds to avoid putting application in background and complicating
@@ -43,15 +43,12 @@ void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled)
4343
UIView *
4444
RCTAppSetupDefaultRootView(RCTBridge *bridge, NSString *moduleName, NSDictionary *initialProperties, BOOL fabricEnabled)
4545
{
46-
if (fabricEnabled) {
47-
id<RCTSurfaceProtocol> surface = [[RCTFabricSurface alloc] initWithBridge:bridge
48-
moduleName:moduleName
49-
initialProperties:initialProperties];
50-
UIView *rootView = [[RCTSurfaceHostingProxyRootView alloc] initWithSurface:surface];
51-
[surface start];
52-
return rootView;
53-
}
54-
return [[RCTRootView alloc] initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
46+
id<RCTSurfaceProtocol> surface = [[RCTFabricSurface alloc] initWithBridge:bridge
47+
moduleName:moduleName
48+
initialProperties:initialProperties];
49+
UIView *rootView = [[RCTSurfaceHostingProxyRootView alloc] initWithSurface:surface];
50+
[surface start];
51+
return rootView;
5552
}
5653

5754
NSArray<NSString *> *RCTAppSetupUnstableModulesRequiringMainQueueSetup(id<RCTDependencyProvider> dependencyProvider)

packages/react-native/Libraries/AppDelegate/RCTDefaultReactNativeFactoryDelegate.mm

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge
5757
moduleName:(NSString *)moduleName
5858
initProps:(NSDictionary *)initProps
5959
{
60-
BOOL enableFabric = self.fabricEnabled;
61-
UIView *rootView = RCTAppSetupDefaultRootView(bridge, moduleName, initProps, enableFabric);
60+
UIView *rootView = RCTAppSetupDefaultRootView(bridge, moduleName, initProps, YES);
6261

6362
rootView.backgroundColor = [UIColor systemBackgroundColor];
6463

@@ -107,22 +106,22 @@ - (void)hostDidStart:(RCTHost *)host
107106

108107
- (BOOL)newArchEnabled
109108
{
110-
return RCTIsNewArchEnabled();
109+
return YES;
111110
}
112111

113112
- (BOOL)bridgelessEnabled
114113
{
115-
return self.newArchEnabled;
114+
return YES;
116115
}
117116

118117
- (BOOL)fabricEnabled
119118
{
120-
return self.newArchEnabled;
119+
return YES;
121120
}
122121

123122
- (BOOL)turboModuleEnabled
124123
{
125-
return self.newArchEnabled;
124+
return YES;
126125
}
127126

128127
- (Class)getModuleClassFromName:(const char *)name

packages/react-native/Libraries/AppDelegate/RCTReactNativeFactory.mm

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,12 @@ - (instancetype)initWithDelegate:(id<RCTReactNativeFactoryDelegate>)delegate rel
5252
self.delegate = delegate;
5353
[self _setUpFeatureFlags:releaseLevel];
5454

55-
auto newArchEnabled = [self newArchEnabled];
56-
auto fabricEnabled = [self fabricEnabled];
57-
5855
[RCTColorSpaceUtils applyDefaultColorSpace:[self defaultColorSpace]];
59-
RCTEnableTurboModule([self turboModuleEnabled]);
56+
RCTEnableTurboModule(YES);
6057

6158
self.rootViewFactory = [self createRCTRootViewFactory];
6259

63-
if (newArchEnabled || fabricEnabled) {
64-
[RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self;
65-
}
60+
[RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self;
6661
}
6762

6863
return self;
@@ -126,37 +121,22 @@ - (JSRuntimeFactoryRef)createJSRuntimeFactory
126121

127122
- (BOOL)newArchEnabled
128123
{
129-
if ([_delegate respondsToSelector:@selector(newArchEnabled)]) {
130-
return _delegate.newArchEnabled;
131-
}
132-
return RCTIsNewArchEnabled();
124+
return YES;
133125
}
134126

135127
- (BOOL)fabricEnabled
136128
{
137-
if ([_delegate respondsToSelector:@selector(fabricEnabled)]) {
138-
return _delegate.fabricEnabled;
139-
}
140-
141-
return [self newArchEnabled];
129+
return YES;
142130
}
143131

144132
- (BOOL)turboModuleEnabled
145133
{
146-
if ([_delegate respondsToSelector:@selector(turboModuleEnabled)]) {
147-
return _delegate.turboModuleEnabled;
148-
}
149-
150-
return [self newArchEnabled];
134+
return YES;
151135
}
152136

153137
- (BOOL)bridgelessEnabled
154138
{
155-
if ([_delegate respondsToSelector:@selector(bridgelessEnabled)]) {
156-
return _delegate.bridgelessEnabled;
157-
}
158-
159-
return [self newArchEnabled];
139+
return YES;
160140
}
161141

162142
#pragma mark - RCTTurboModuleManagerDelegate
@@ -250,9 +230,9 @@ - (RCTRootViewFactory *)createRCTRootViewFactory
250230

251231
RCTRootViewFactoryConfiguration *configuration =
252232
[[RCTRootViewFactoryConfiguration alloc] initWithBundleURLBlock:bundleUrlBlock
253-
newArchEnabled:self.fabricEnabled
254-
turboModuleEnabled:self.turboModuleEnabled
255-
bridgelessEnabled:self.bridgelessEnabled];
233+
newArchEnabled:YES
234+
turboModuleEnabled:YES
235+
bridgelessEnabled:YES];
256236

257237
configuration.createRootViewWithBridge = ^UIView *(RCTBridge *bridge, NSString *moduleName, NSDictionary *initProps) {
258238
return [weakSelf.delegate createRootViewWithBridge:bridge moduleName:moduleName initProps:initProps];
@@ -334,9 +314,7 @@ - (void)_setUpFeatureFlags:(RCTReleaseLevel)releaseLevel
334314
dispatch_once(&setupFeatureFlagsToken, ^{
335315
switch (releaseLevel) {
336316
case Stable:
337-
if ([self bridgelessEnabled]) {
338-
ReactNativeFeatureFlags::override(std::make_unique<ReactNativeFeatureFlagsOverridesOSSStable>());
339-
}
317+
ReactNativeFeatureFlags::override(std::make_unique<ReactNativeFeatureFlagsOverridesOSSStable>());
340318
break;
341319
case Canary:
342320
ReactNativeFeatureFlags::override(std::make_unique<ReactNativeFeatureFlagsOverridesOSSCanary>());

packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm

Lines changed: 26 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ - (instancetype)initWithBundleURLBlock:(RCTBundleURLBlock)bundleURLBlock
7373
{
7474
if (self = [super init]) {
7575
_bundleURLBlock = bundleURLBlock;
76-
_fabricEnabled = newArchEnabled;
77-
_turboModuleEnabled = turboModuleEnabled;
78-
_bridgelessEnabled = bridgelessEnabled;
76+
_fabricEnabled = YES;
77+
_turboModuleEnabled = YES;
78+
_bridgelessEnabled = YES;
7979
}
8080
return self;
8181
}
@@ -135,17 +135,12 @@ - (UIView *)viewWithModuleName:(NSString *)moduleName
135135

136136
- (void)initializeReactHostWithLaunchOptions:(NSDictionary *)launchOptions
137137
{
138-
if (_configuration.bridgelessEnabled) {
139-
// Enable TurboModule interop by default in Bridgeless mode
140-
RCTEnableTurboModuleInterop(YES);
141-
RCTEnableTurboModuleInteropBridgeProxy(YES);
138+
// Enable TurboModule interop by default in Bridgeless mode
139+
RCTEnableTurboModuleInterop(YES);
140+
RCTEnableTurboModuleInteropBridgeProxy(YES);
142141

143-
[self createReactHostIfNeeded:launchOptions];
144-
return;
145-
}
146-
147-
[self createBridgeIfNeeded:launchOptions];
148-
[self createBridgeAdapterIfNeeded];
142+
[self createReactHostIfNeeded:launchOptions];
143+
return;
149144
}
150145

151146
- (UIView *)viewWithModuleName:(NSString *)moduleName
@@ -154,29 +149,17 @@ - (UIView *)viewWithModuleName:(NSString *)moduleName
154149
{
155150
[self initializeReactHostWithLaunchOptions:launchOptions];
156151

157-
if (_configuration.bridgelessEnabled) {
158-
RCTFabricSurface *surface = [self.reactHost createSurfaceWithModuleName:moduleName initialProperties:initProps];
152+
RCTFabricSurface *surface = [self.reactHost createSurfaceWithModuleName:moduleName
153+
initialProperties:initProps ? initProps : @{}];
159154

160-
RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView =
161-
[[RCTSurfaceHostingProxyRootView alloc] initWithSurface:surface];
155+
RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView =
156+
[[RCTSurfaceHostingProxyRootView alloc] initWithSurface:surface];
162157

163-
surfaceHostingProxyRootView.backgroundColor = [UIColor systemBackgroundColor];
164-
if (_configuration.customizeRootView != nil) {
165-
_configuration.customizeRootView(surfaceHostingProxyRootView);
166-
}
167-
return surfaceHostingProxyRootView;
168-
}
169-
170-
UIView *rootView;
171-
if (_configuration.createRootViewWithBridge != nil) {
172-
rootView = _configuration.createRootViewWithBridge(self.bridge, moduleName, initProps);
173-
} else {
174-
rootView = [self createRootViewWithBridge:self.bridge moduleName:moduleName initProps:initProps];
175-
}
158+
surfaceHostingProxyRootView.backgroundColor = [UIColor systemBackgroundColor];
176159
if (_configuration.customizeRootView != nil) {
177-
_configuration.customizeRootView(rootView);
160+
_configuration.customizeRootView(surfaceHostingProxyRootView);
178161
}
179-
return rootView;
162+
return surfaceHostingProxyRootView;
180163
}
181164

182165
- (RCTBridge *)createBridgeWithDelegate:(id<RCTBridgeDelegate>)delegate launchOptions:(NSDictionary *)launchOptions
@@ -188,8 +171,7 @@ - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge
188171
moduleName:(NSString *)moduleName
189172
initProps:(NSDictionary *)initProps
190173
{
191-
BOOL enableFabric = _configuration.fabricEnabled;
192-
UIView *rootView = RCTAppSetupDefaultRootView(bridge, moduleName, initProps, enableFabric);
174+
UIView *rootView = RCTAppSetupDefaultRootView(bridge, moduleName, initProps, YES);
193175
rootView.backgroundColor = [UIColor systemBackgroundColor];
194176
return rootView;
195177
}
@@ -198,19 +180,15 @@ - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge
198180
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
199181
{
200182
_runtimeScheduler = std::make_shared<facebook::react::RuntimeScheduler>(RCTRuntimeExecutorFromBridge(bridge));
201-
if (RCTIsNewArchEnabled()) {
202-
std::shared_ptr<facebook::react::CallInvoker> callInvoker =
203-
std::make_shared<facebook::react::RuntimeSchedulerCallInvoker>(_runtimeScheduler);
204-
RCTTurboModuleManager *turboModuleManager =
205-
[[RCTTurboModuleManager alloc] initWithBridge:bridge
206-
delegate:_turboModuleManagerDelegate
207-
jsInvoker:callInvoker];
208-
_contextContainer->erase("RuntimeScheduler");
209-
_contextContainer->insert("RuntimeScheduler", _runtimeScheduler);
210-
return RCTAppSetupDefaultJsExecutorFactory(bridge, turboModuleManager, _runtimeScheduler);
211-
} else {
212-
return RCTAppSetupJsExecutorFactoryForOldArch(bridge, _runtimeScheduler);
213-
}
183+
184+
std::shared_ptr<facebook::react::CallInvoker> callInvoker =
185+
std::make_shared<facebook::react::RuntimeSchedulerCallInvoker>(_runtimeScheduler);
186+
RCTTurboModuleManager *turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge
187+
delegate:_turboModuleManagerDelegate
188+
jsInvoker:callInvoker];
189+
_contextContainer->erase("RuntimeScheduler");
190+
_contextContainer->insert("RuntimeScheduler", _runtimeScheduler);
191+
return RCTAppSetupDefaultJsExecutorFactory(bridge, turboModuleManager, _runtimeScheduler);
214192
}
215193

216194
- (void)createBridgeIfNeeded:(NSDictionary *)launchOptions
@@ -228,7 +206,7 @@ - (void)createBridgeIfNeeded:(NSDictionary *)launchOptions
228206

229207
- (void)createBridgeAdapterIfNeeded
230208
{
231-
if (!self->_configuration.fabricEnabled || self.bridgeAdapter) {
209+
if (self.bridgeAdapter != nullptr) {
232210
return;
233211
}
234212

packages/react-native/React/Base/RCTBridge.mm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ void addModuleLoadedWithOldArch(NSString *moduleName)
141141
void RCTRegisterModule(Class);
142142
void RCTRegisterModule(Class moduleClass)
143143
{
144-
if (RCTAreLegacyLogsEnabled() && RCTIsNewArchEnabled() &&
145-
![getCoreModuleClasses() containsObject:[moduleClass description]]) {
144+
if (RCTAreLegacyLogsEnabled() && ![getCoreModuleClasses() containsObject:[moduleClass description]]) {
146145
addModuleLoadedWithOldArch([moduleClass description]);
147146
}
148147
static dispatch_once_t onceToken;
@@ -183,7 +182,7 @@ void RCTRegisterModule(Class moduleClass)
183182
return RCTDropReactPrefixes(name);
184183
}
185184

186-
static BOOL turboModuleEnabled = NO;
185+
static const BOOL turboModuleEnabled = YES;
187186
BOOL RCTTurboModuleEnabled(void)
188187
{
189188
#if RCT_DEBUG
@@ -197,7 +196,7 @@ BOOL RCTTurboModuleEnabled(void)
197196

198197
void RCTEnableTurboModule(BOOL enabled)
199198
{
200-
turboModuleEnabled = enabled;
199+
// The new Architecture is enabled by default and we are ignoring changes to the TurboModule system.
201200
}
202201

203202
static BOOL turboModuleInteropEnabled = NO;

packages/react-native/React/Base/RCTUtils.mm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
4343
// Whether the New Architecture is enabled or not
4444
BOOL RCTIsNewArchEnabled(void)
4545
{
46-
NSNumber *rctNewArchEnabled = (NSNumber *)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"RCTNewArchEnabled"];
47-
return rctNewArchEnabled == nil || rctNewArchEnabled.boolValue;
46+
return YES;
4847
}
4948
void RCTSetNewArchEnabled(BOOL enabled)
5049
{

packages/react-native/scripts/cocoapods/__tests__/new_architecture-test.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,6 @@ def test_newArchEnabled_whenRCTNewArchEnabledIsSetTo1_returnTrue
240240
assert_true(is_enabled)
241241
end
242242

243-
def test_newArchEnabled_whenRCTNewArchEnabledIsSetTo0_returnFalse
244-
ENV["RCT_NEW_ARCH_ENABLED"] = "0"
245-
is_enabled = NewArchitectureHelper.new_arch_enabled
246-
assert_false(is_enabled)
247-
end
248-
249243
def test_newArchEnabled_whenRCTNewArchEnabledIsNotSet_returnTrue
250244
ENV["RCT_NEW_ARCH_ENABLED"] = nil
251245
is_enabled = NewArchitectureHelper.new_arch_enabled

packages/react-native/scripts/cocoapods/codegen.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
def run_codegen!(
1010
app_path,
1111
config_file_dir,
12-
new_arch_enabled: false,
12+
new_arch_enabled: true,
1313
disable_codegen: false,
1414
react_native_path: "../node_modules/react-native",
1515
fabric_enabled: false,

packages/react-native/scripts/cocoapods/new_architecture.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def self.folly_compiler_flags
153153
end
154154

155155
def self.new_arch_enabled
156-
return ENV["RCT_NEW_ARCH_ENABLED"] == '0' ? false : true
156+
return true
157157
end
158158

159159
def self.set_RCTNewArchEnabled_in_info_plist(installer, new_arch_enabled)

packages/react-native/scripts/react_native_pods.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def prepare_react_native_project!
5656
# Parameters
5757
# - path: path to react_native installation.
5858
# - fabric_enabled: whether fabric should be enabled or not.
59-
# - new_arch_enabled: whether the new architecture should be enabled or not.
59+
# - new_arch_enabled: [DEPRECATED] whether the new architecture should be enabled or not.
6060
# - :production [DEPRECATED] whether the dependencies must be installed to target a Debug or a Release build.
6161
# - hermes_enabled: whether Hermes should be enabled or not.
6262
# - app_path: path to the React Native app. Required by the New Architecture.
@@ -94,11 +94,11 @@ def use_react_native! (
9494
# Better to rely and enable this environment flag if the new architecture is turned on using flags.
9595
relative_path_from_current = Pod::Config.instance.installation_root.relative_path_from(Pathname.pwd)
9696
react_native_version = NewArchitectureHelper.extract_react_native_version(File.join(relative_path_from_current, path))
97-
fabric_enabled = fabric_enabled || NewArchitectureHelper.new_arch_enabled
97+
fabric_enabled = true
9898

99-
ENV['RCT_FABRIC_ENABLED'] = fabric_enabled ? "1" : "0"
99+
ENV['RCT_FABRIC_ENABLED'] = "1"
100100
ENV['RCT_AGGREGATE_PRIVACY_FILES'] = privacy_file_aggregation_enabled ? "1" : "0"
101-
ENV["RCT_NEW_ARCH_ENABLED"] = new_arch_enabled ? "1" : "0"
101+
ENV["RCT_NEW_ARCH_ENABLED"] = "1"
102102

103103
prefix = path
104104

@@ -110,7 +110,7 @@ def use_react_native! (
110110
# Update ReactNativeCoreUtils so that we can easily switch between source and prebuilt
111111
ReactNativeCoreUtils.setup_rncore(prefix, react_native_version)
112112

113-
Pod::UI.puts "Configuring the target with the #{new_arch_enabled ? "New" : "Legacy"} Architecture\n"
113+
Pod::UI.puts "Configuring the target with the New Architecture\n"
114114

115115
# The Pods which should be included in all projects
116116
pod 'FBLazyVector', :path => "#{prefix}/Libraries/FBLazyVector"
@@ -270,10 +270,10 @@ def create_header_search_path_for_frameworks(pod_name, additional_framework_path
270270
#
271271
# Parameters:
272272
# - spec: The spec that has to be configured with the New Architecture code
273-
# - new_arch_enabled: Whether the module should install dependencies for the new architecture
273+
# - new_arch_enabled: [DEPRECATED] Whether the module should install dependencies for the new architecture
274274
def install_modules_dependencies(spec, new_arch_enabled: NewArchitectureHelper.new_arch_enabled)
275275
folly_config = get_folly_config()
276-
NewArchitectureHelper.install_modules_dependencies(spec, new_arch_enabled, folly_config[:version])
276+
NewArchitectureHelper.install_modules_dependencies(spec, true, folly_config[:version])
277277
end
278278

279279
# This function is used by podspecs that needs to use the prebuilt sources for React Native.

0 commit comments

Comments
 (0)