diff --git a/packages/react-native-test-library/package.json b/packages/react-native-test-library/package.json index 054eb559809e88..c378871432ff36 100644 --- a/packages/react-native-test-library/package.json +++ b/packages/react-native-test-library/package.json @@ -44,6 +44,11 @@ "includesGeneratedCode": true, "android": { "javaPackageName": "com.reactnative.osslibraryexample" + }, + "ios": { + "componentProvider": { + "SampleNativeComponent": "RCTSampleNativeComponentComponentView" + } } } } diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor.js b/packages/react-native/scripts/codegen/generate-artifacts-executor.js index bd2f24b5c41559..3e79c45ad685c2 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor.js @@ -646,16 +646,37 @@ function generateRCTThirdPartyComponents(libraries, outputDir) { if (isReactNativeCoreLibrary(config.name) || config.type === 'modules') { return; } + const libraryName = JSON.parse( fs.readFileSync(path.join(libraryPath, 'package.json')), ).name; + if (config.ios?.componentProvider) { + componentsInLibraries[libraryName] = Object.keys( + config.ios?.componentProvider, + ).map(componentName => { + return { + componentName, + className: config.ios?.componentProvider[componentName], + }; + }); + return; + } codegenLog(`Crawling ${libraryName} library for components`); // crawl all files and subdirectories for file with the ".mm" extension const files = findFilesWithExtension(libraryPath, '.mm'); - componentsInLibraries[libraryName] = files + const componentsMapping = files .flatMap(file => findRCTComponentViewProtocolClass(file)) .filter(Boolean); + + if (componentsMapping.length !== 0) { + codegenLog( + `[DEPRECATED] ${libraryName} should add the 'ios.componentProvider' property in their codegenConfig`, + true, + ); + } + + componentsInLibraries[libraryName] = componentsMapping; }); const thirdPartyComponentsMapping = Object.keys(componentsInLibraries) diff --git a/packages/rn-tester/package.json b/packages/rn-tester/package.json index 51ff079c14ab0e..48fa5f0de263b9 100644 --- a/packages/rn-tester/package.json +++ b/packages/rn-tester/package.json @@ -43,6 +43,11 @@ "jsSrcsDir": ".", "android": { "javaPackageName": "com.facebook.fbreact.specs" + }, + "ios": { + "componentProvider": { + "RNTMyNativeView": "RNTMyNativeViewComponentView" + } } }, "devDependencies": {