Skip to content

Automate setting the RCTNewArchEnabled flag #49927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ NS_ASSUME_NONNULL_BEGIN
///
/// @note: This is required to be rendering on Fabric (i.e. on the New Architecture).
/// @return: `true` if the Turbo Native Module are enabled. Otherwise, it returns `false`.
- (BOOL)turboModuleEnabled __attribute__((deprecated("Use newArchEnabled instead")));
- (BOOL)turboModuleEnabled __attribute__((deprecated("Use RCTIsNewArchEnabled instead")));

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

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

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

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,7 @@ - (void)hostDidStart:(RCTHost *)host

- (BOOL)newArchEnabled
{
#if RCT_NEW_ARCH_ENABLED
return YES;
#else
return NO;
#endif
return RCTIsNewArchEnabled();
}

- (BOOL)bridgelessEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ - (instancetype)initWithDelegate:(id<RCTReactNativeFactoryDelegate>)delegate rel
auto newArchEnabled = [self newArchEnabled];
auto fabricEnabled = [self fabricEnabled];

RCTSetNewArchEnabled(newArchEnabled);
[RCTColorSpaceUtils applyDefaultColorSpace:[self defaultColorSpace]];
RCTEnableTurboModule([self turboModuleEnabled]);

Expand Down Expand Up @@ -130,12 +129,7 @@ - (BOOL)newArchEnabled
if ([_delegate respondsToSelector:@selector(newArchEnabled)]) {
return _delegate.newArchEnabled;
}

#if RCT_NEW_ARCH_ENABLED
return YES;
#else
return NO;
#endif
return RCTIsNewArchEnabled();
}

- (BOOL)fabricEnabled
Expand Down
4 changes: 3 additions & 1 deletion packages/react-native/React/Base/RCTUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ NS_ASSUME_NONNULL_BEGIN

// Whether the New Architecture is enabled or not
RCT_EXTERN BOOL RCTIsNewArchEnabled(void);
RCT_EXTERN void RCTSetNewArchEnabled(BOOL enabled);
RCT_EXTERN void RCTSetNewArchEnabled(BOOL enabled) __attribute__((deprecated(
"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")));
;

// JSON serialization/deserialization
RCT_EXTERN NSString *__nullable RCTJSONStringify(id __nullable jsonObject, NSError **error);
Expand Down
12 changes: 8 additions & 4 deletions packages/react-native/React/Base/RCTUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@
static BOOL _newArchEnabled = false;
BOOL RCTIsNewArchEnabled(void)
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSNumber *rctNewArchEnabled = (NSNumber *)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"RCTNewArchEnabled"];
_newArchEnabled = rctNewArchEnabled == nil || rctNewArchEnabled.boolValue;
});
return _newArchEnabled;
}
void RCTSetNewArchEnabled(BOOL enabled)
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_newArchEnabled = enabled;
});
// This function is now deprecated and will be removed in the future.
// 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.
}

static NSString *__nullable _RCTJSONStringifyNoRetry(id __nullable jsonObject, NSError **error)
Expand Down
37 changes: 37 additions & 0 deletions packages/react-native/scripts/cocoapods/new_architecture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require_relative "./helpers.rb"
require_relative "./jsengine.rb"


class NewArchitectureHelper
@@NewArchWarningEmitted = false # Used not to spam warnings to the user.

Expand Down Expand Up @@ -159,4 +160,40 @@ def self.extract_react_native_version(react_native_path, file_manager: File, jso
def self.new_arch_enabled
return ENV["RCT_NEW_ARCH_ENABLED"] == '0' ? false : true
end

def self.set_RCTNewArchEnabled_in_info_plist(installer, new_arch_enabled)
projectPaths = installer.aggregate_targets
.map{ |t| t.user_project }
.uniq{ |p| p.path }
.map{ |p| p.path }

excluded_info_plist = ["/Pods", "Tests", "metainternal", ".bundle"]
projectPaths.each do |projectPath|
projectFolderPath = File.dirname(projectPath)
infoPlistFiles = `find #{projectFolderPath} -name "Info.plist"`
infoPlistFiles = infoPlistFiles.split("\n").map { |f| f.strip }

infoPlistFiles.each do |infoPlistFile|
# If infoPlistFile contains Pods or tests, skip it
should_skip = false
excluded_info_plist.each do |excluded|
if infoPlistFile.include? excluded
should_skip = true
end
end
next if should_skip

# Read the file as a plist
info_plist = Xcodeproj::Plist.read_from_path(infoPlistFile)
# Check if it contains the RCTNewArchEnabled key
if info_plist["RCTNewArchEnabled"] and info_plist["RCTNewArchEnabled"] == new_arch_enabled
next
end

# Add the key and value to the plist
info_plist["RCTNewArchEnabled"] = new_arch_enabled ? true : false
Xcodeproj::Plist.write_to_path(info_plist, infoPlistFile)
end
end
end
end
1 change: 1 addition & 0 deletions packages/react-native/scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ def react_native_post_install(

NewArchitectureHelper.set_clang_cxx_language_standard_if_needed(installer)
NewArchitectureHelper.modify_flags_for_new_architecture(installer, NewArchitectureHelper.new_arch_enabled)
NewArchitectureHelper.set_RCTNewArchEnabled_in_info_plist(installer, NewArchitectureHelper.new_arch_enabled)

if ENV['USE_HERMES'] == '0' && ENV['USE_THIRD_PARTY_JSC'] != '1'
print_jsc_removal_message()
Expand Down
Loading