Skip to content

Commit 51a3c73

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Deprecate RCT_NEW_ARCH_ENABLED (#49924)
Summary: This change deprecates the RCT_NEW_ARCH_ENABLEd flag to toggle the New Architecture. The new approach bring iOS closer to Android: to diasable the New Architecture, user needs to modify the App's Info.plist and add a `RCTNewArchEnabled` boolean entry and set it to `NO`. The absence of the entry implies that the New Arch is enabled. (Defaults to enabled) This also deprecates the `RCTSetNewArchEnabled` function because it makes no sense now ## Context The RCT_NEW_ARCH_ENABLE flag is a compile time flag we used for almost two years to configure the iOS apps and to determine whether the app should build with the New Arch or not. However, given that we are looking into prebuilding React Native, we have to get rid of all the compilation flags, because they would require us to prebuild a combinatorial number of artifacts for react native. For example: - New Arch / Hermes - Old Arch / Hermes - New Arch / JSC - Old Arch / JSC - ... ## Backward compatibility We are going to keep adding the RCT_NEW_ARCH_ENABLED flag in all the dependencies, through the cocoapods inrastructure, so libraries, which are not prebuilt, will be build for the right architecture by the app itself. ## Changelog: [iOS][Deprecated] - deprecate the `RCT_NEW_ARCH_ENABLED` and the `RCTSetNewArchEnabled` Reviewed By: cortinico Differential Revision: D70885454
1 parent d50cb76 commit 51a3c73

File tree

5 files changed

+17
-21
lines changed

5 files changed

+17
-21
lines changed

packages/react-native/Libraries/AppDelegate/RCTArchConfiguratorProtocol.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ NS_ASSUME_NONNULL_BEGIN
1515
///
1616
/// @note: This is required to be rendering on Fabric (i.e. on the New Architecture).
1717
/// @return: `true` if the Turbo Native Module are enabled. Otherwise, it returns `false`.
18-
- (BOOL)turboModuleEnabled __attribute__((deprecated("Use newArchEnabled instead")));
18+
- (BOOL)turboModuleEnabled __attribute__((deprecated("Use RCTIsNewArchEnabled instead")));
1919

2020
/// This method controls whether the App will use the Fabric renderer of the New Architecture or not.
2121
///
2222
/// @return: `true` if the Fabric Renderer is enabled. Otherwise, it returns `false`.
23-
- (BOOL)fabricEnabled __attribute__((deprecated("Use newArchEnabled instead")));
23+
- (BOOL)fabricEnabled __attribute__((deprecated("Use RCTIsNewArchEnabled instead")));
2424

2525
/// This method controls whether React Native's new initialization layer is enabled.
2626
///
2727
/// @return: `true` if the new initialization layer is enabled. Otherwise returns `false`.
28-
- (BOOL)bridgelessEnabled __attribute__((deprecated("Use newArchEnabled instead")));
28+
- (BOOL)bridgelessEnabled __attribute__((deprecated("Use RCTIsNewArchEnabled instead")));
2929

3030
/// This method controls whether React Native uses new Architecture.
3131
///
3232
/// @return: `true` if the new architecture is enabled. Otherwise returns `false`.
33-
- (BOOL)newArchEnabled;
33+
- (BOOL)newArchEnabled __attribute__((deprecated("Use RCTIsNewArchEnabled instead")));
3434
@end
3535

3636
NS_ASSUME_NONNULL_END

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,7 @@ - (void)hostDidStart:(RCTHost *)host
108108

109109
- (BOOL)newArchEnabled
110110
{
111-
#if RCT_NEW_ARCH_ENABLED
112-
return YES;
113-
#else
114-
return NO;
115-
#endif
111+
return RCTIsNewArchEnabled();
116112
}
117113

118114
- (BOOL)bridgelessEnabled

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ - (instancetype)initWithDelegate:(id<RCTReactNativeFactoryDelegate>)delegate rel
5555
auto newArchEnabled = [self newArchEnabled];
5656
auto fabricEnabled = [self fabricEnabled];
5757

58-
RCTSetNewArchEnabled(newArchEnabled);
5958
[RCTColorSpaceUtils applyDefaultColorSpace:[self defaultColorSpace]];
6059
RCTEnableTurboModule([self turboModuleEnabled]);
6160

@@ -130,12 +129,7 @@ - (BOOL)newArchEnabled
130129
if ([_delegate respondsToSelector:@selector(newArchEnabled)]) {
131130
return _delegate.newArchEnabled;
132131
}
133-
134-
#if RCT_NEW_ARCH_ENABLED
135-
return YES;
136-
#else
137-
return NO;
138-
#endif
132+
return RCTIsNewArchEnabled();
139133
}
140134

141135
- (BOOL)fabricEnabled

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ NS_ASSUME_NONNULL_BEGIN
1818

1919
// Whether the New Architecture is enabled or not
2020
RCT_EXTERN BOOL RCTIsNewArchEnabled(void);
21-
RCT_EXTERN void RCTSetNewArchEnabled(BOOL enabled);
21+
RCT_EXTERN void RCTSetNewArchEnabled(BOOL enabled) __attribute__((deprecated(
22+
"This function is now no-op. You need to modify the Info.plist adding a RCTNewArchEnabled bool property to control whether the New Arch is enabled or not")));
23+
;
2224

2325
// JSON serialization/deserialization
2426
RCT_EXTERN NSString *__nullable RCTJSONStringify(id __nullable jsonObject, NSError **error);

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,18 @@
3737
static BOOL _newArchEnabled = false;
3838
BOOL RCTIsNewArchEnabled(void)
3939
{
40+
static dispatch_once_t onceToken;
41+
dispatch_once(&onceToken, ^{
42+
NSNumber *rctNewArchEnabled = (NSNumber *)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"RCTNewArchEnabled"];
43+
_newArchEnabled = rctNewArchEnabled == nil || rctNewArchEnabled.boolValue;
44+
});
4045
return _newArchEnabled;
4146
}
4247
void RCTSetNewArchEnabled(BOOL enabled)
4348
{
44-
static dispatch_once_t onceToken;
45-
dispatch_once(&onceToken, ^{
46-
_newArchEnabled = enabled;
47-
});
49+
// This function is now deprecated and will be removed in the future.
50+
// This function is now no-op. You need to modify the Info.plist adding a `RCTNewArchEnabled` bool property to control
51+
// whether the New Arch is enabled or not.
4852
}
4953

5054
static NSString *__nullable _RCTJSONStringifyNoRetry(id __nullable jsonObject, NSError **error)

0 commit comments

Comments
 (0)