Skip to content
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
5 changes: 5 additions & 0 deletions packages/react-native/React/Base/RCTBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ RCT_EXTERN_C_BEGIN
*/
NSString *RCTBridgeModuleNameForClass(Class bridgeModuleClass);

/**
* This function returns the list of modules that have been registered using the Old Architecture mechanism.
*/
NSMutableArray<NSString *> *getModulesLoadedWithOldArch(void);

/**
* Experimental.
* Check/set if JSI-bound NativeModule is enabled. By default it's off.
Expand Down
94 changes: 94 additions & 0 deletions packages/react-native/React/Base/RCTBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,97 @@
return result;
}

NSSet<NSString *> *getCoreModuleClasses(void);
NSSet<NSString *> *getCoreModuleClasses(void)
{
static NSSet<NSString *> *coreModuleClasses = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
coreModuleClasses = [NSSet setWithArray:@[
@"RCTViewManager",
@"RCTActivityIndicatorViewManager",
@"RCTDebuggingOverlayManager",
@"RCTModalHostViewManager",
@"RCTModalManager",
@"RCTRefreshControlManager",
@"RCTSafeAreaViewManager",
@"RCTScrollContentViewManager",
@"RCTScrollViewManager",
@"RCTSwitchManager",
@"RCTUIManager",
@"RCTAccessibilityManager",
@"RCTActionSheetManager",
@"RCTAlertManager",
@"RCTAppearance",
@"RCTAppState",
@"RCTClipboard",
@"RCTDeviceInfo",
@"RCTDevLoadingView",
@"RCTDevMenu",
@"RCTDevSettings",
@"RCTDevToolsRuntimeSettingsModule",
@"RCTEventDispatcher",
@"RCTExceptionsManager",
@"RCTI18nManager",
@"RCTKeyboardObserver",
@"RCTLogBox",
@"RCTPerfMonitor",
@"RCTPlatform",
@"RCTRedBox",
@"RCTSourceCode",
@"RCTStatusBarManager",
@"RCTTiming",
@"RCTWebSocketModule",
@"RCTNativeAnimatedModule",
@"RCTNativeAnimatedTurboModule",
@"RCTBlobManager",
@"RCTFileReaderModule",
@"RCTBundleAssetImageLoader",
@"RCTGIFImageDecoder",
@"RCTImageEditingManager",
@"RCTImageLoader",
@"RCTImageStoreManager",
@"RCTImageViewManager",
@"RCTLocalAssetImageLoader",
@"RCTLinkingManager",
@"RCTDataRequestHandler",
@"RCTFileRequestHandler",
@"RCTHTTPRequestHandler",
@"RCTNetworking",
@"RCTPushNotificationManager",
@"RCTSettingsManager",
@"RCTBaseTextViewManager",
@"RCTBaseTextInputViewManager",
@"RCTInputAccessoryViewManager",
@"RCTMultilineTextInputViewManager",
@"RCTRawTextViewManager",
@"RCTSinglelineTextInputViewManager",
@"RCTTextViewManager",
@"RCTVirtualTextViewManager",
@"RCTVibration",
]];
});

return coreModuleClasses;
}

static NSMutableArray<NSString *> *modulesLoadedWithOldArch;
void addModuleLoadedWithOldArch(NSString *);
void addModuleLoadedWithOldArch(NSString *moduleName)
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
modulesLoadedWithOldArch = [NSMutableArray new];
});

[modulesLoadedWithOldArch addObject:moduleName];
}

NSMutableArray<NSString *> *getModulesLoadedWithOldArch(void)
{
return modulesLoadedWithOldArch;
}

/**
* Register the given class as a bridge module. All modules must be registered
* prior to the first bridge initialization.
Expand All @@ -50,6 +141,9 @@
void RCTRegisterModule(Class);
void RCTRegisterModule(Class moduleClass)
{
if (RCTIsNewArchEnabled() && ![getCoreModuleClasses() containsObject:[moduleClass description]]) {
addModuleLoadedWithOldArch([moduleClass description]);
}
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
RCTModuleClasses = [NSMutableArray new];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,26 @@ - (void)_loadJSBundle:(NSURL *)sourceURL
// Set up hot module reloading in Dev only.
[strongSelf->_performanceLogger markStopForTag:RCTPLScriptDownload];
[devSettings setupHMRClientWithBundleURL:sourceURL];

[strongSelf _logOldArchitectureWarnings];
}];
}

- (void)_logOldArchitectureWarnings
{
NSMutableArray<NSString *> *modulesInOldArchMode = getModulesLoadedWithOldArch();
if (modulesInOldArchMode.count > 0) {
NSMutableString *moduleList = [NSMutableString new];
for (NSString *moduleName in modulesInOldArchMode) {
[moduleList appendFormat:@"- %@\n", moduleName];
}
RCTLogWarn(
@"The following modules have been registered using a RCT_EXPORT_MODULE. That's a Legacy Architecture API. Please migrate to the new approach as described in the https://reactnative.dev/docs/next/turbo-native-modules-introduction#register-the-native-module-in-your-app website or open a PR in the library repository:\n%@",
moduleList);
[modulesInOldArchMode removeAllObjects];
}
}

- (void)_loadScriptFromSource:(RCTSource *)source
{
std::lock_guard<std::mutex> lock(_invalidationMutex);
Expand Down