diff --git a/packages/react-native/React/Base/RCTBridge.mm b/packages/react-native/React/Base/RCTBridge.mm index d163cd49ccb..3f1cbeb7bb2 100644 --- a/packages/react-native/React/Base/RCTBridge.mm +++ b/packages/react-native/React/Base/RCTBridge.mm @@ -141,7 +141,8 @@ NSMutableArray *getModulesLoadedWithOldArch(void) void RCTRegisterModule(Class); void RCTRegisterModule(Class moduleClass) { - if (RCTIsNewArchEnabled() && ![getCoreModuleClasses() containsObject:[moduleClass description]]) { + if (RCTAreLegacyLogsEnabled() && RCTIsNewArchEnabled() && + ![getCoreModuleClasses() containsObject:[moduleClass description]]) { addModuleLoadedWithOldArch([moduleClass description]); } static dispatch_once_t onceToken; diff --git a/packages/react-native/React/Base/RCTUtils.h b/packages/react-native/React/Base/RCTUtils.h index 90939a8ea55..d4459badcea 100644 --- a/packages/react-native/React/Base/RCTUtils.h +++ b/packages/react-native/React/Base/RCTUtils.h @@ -22,6 +22,10 @@ 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"))); ; +// Whether React native should output logs for modules and components used +// through the interop layers +RCT_EXTERN BOOL RCTAreLegacyLogsEnabled(void); + // JSON serialization/deserialization RCT_EXTERN NSString *__nullable RCTJSONStringify(id __nullable jsonObject, NSError **error); RCT_EXTERN id __nullable RCTJSONParse(NSString *__nullable jsonString, NSError **error); diff --git a/packages/react-native/React/Base/RCTUtils.mm b/packages/react-native/React/Base/RCTUtils.mm index 1223a1ef305..d1ac5cefae3 100644 --- a/packages/react-native/React/Base/RCTUtils.mm +++ b/packages/react-native/React/Base/RCTUtils.mm @@ -52,6 +52,18 @@ void RCTSetNewArchEnabled(BOOL enabled) // whether the New Arch is enabled or not. } +static BOOL _legacyWarningEnabled = true; +BOOL RCTAreLegacyLogsEnabled(void) +{ + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + NSNumber *rctNewArchEnabled = + (NSNumber *)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"RCTLegacyWarningsEnabled"]; + _legacyWarningEnabled = rctNewArchEnabled == nil || rctNewArchEnabled.boolValue; + }); + return _legacyWarningEnabled; +} + static NSString *__nullable _RCTJSONStringifyNoRetry(id __nullable jsonObject, NSError **error) { if (!jsonObject) { diff --git a/packages/react-native/React/Fabric/Mounting/RCTComponentViewFactory.mm b/packages/react-native/React/Fabric/Mounting/RCTComponentViewFactory.mm index 6db166015fb..3db0181332b 100644 --- a/packages/react-native/React/Fabric/Mounting/RCTComponentViewFactory.mm +++ b/packages/react-native/React/Fabric/Mounting/RCTComponentViewFactory.mm @@ -141,7 +141,7 @@ static Class RCTComponentViewClassWithName(const char // TODO(T174674274): Implement lazy loading of legacy view managers in the new architecture. if (RCTFabricInteropLayerEnabled() && [RCTLegacyViewManagerInteropComponentView isSupported:componentNameString]) { RCTLogNewArchitectureValidation( - RCTNotAllowedInFabricWithoutLegacy, + RCTAreLegacyLogsEnabled() ? RCTNotAllowedInFabricWithoutLegacy : RCTNotAllowedInBridgeless, self, [NSString stringWithFormat: diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTInteropTurboModule.mm b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTInteropTurboModule.mm index 802e5a09e10..98df9165c41 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTInteropTurboModule.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTInteropTurboModule.mm @@ -336,6 +336,10 @@ jsi::Value ObjCInteropTurboModule::create(jsi::Runtime &runtime, const jsi::Prop void ObjCInteropTurboModule::_logLegacyArchitectureWarning(NSString *moduleName, const std::string &methodName) { + if (!RCTAreLegacyLogsEnabled()) { + return; + } + std::string separator = std::string("."); std::string moduleInvocation = [moduleName cStringUsingEncoding:NSUTF8StringEncoding] + separator + methodName;