diff --git a/packages/react-native/scripts/cocoapods/codegen_utils.rb b/packages/react-native/scripts/cocoapods/codegen_utils.rb index 067184cd61dd43..76a1fc8586a2a9 100644 --- a/packages/react-native/scripts/cocoapods/codegen_utils.rb +++ b/packages/react-native/scripts/cocoapods/codegen_utils.rb @@ -143,6 +143,7 @@ def get_react_codegen_spec(package_json_file, folly_version: get_folly_config()[ 'React-debug': [], 'React-utils': [], 'React-featureflags': [], + 'React-RCTAppDelegate': [], } } diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor.js b/packages/react-native/scripts/codegen/generate-artifacts-executor.js index 3e79c45ad685c2..26d8cabc0683ee 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor.js @@ -102,6 +102,22 @@ const THIRD_PARTY_COMPONENTS_MM_TEMPLATE_PATH = path.join( 'RCTThirdPartyComponentsProviderMM.template', ); +const APP_DEPENDENCY_PROVIDER_H_TEMPLATE_PATH = path.join( + REACT_NATIVE_PACKAGE_ROOT_FOLDER, + 'scripts', + 'codegen', + 'templates', + 'RCTAppDependencyProviderH.template', +); + +const APP_DEPENDENCY_PROVIDER_MM_TEMPLATE_PATH = path.join( + REACT_NATIVE_PACKAGE_ROOT_FOLDER, + 'scripts', + 'codegen', + 'templates', + 'RCTAppDependencyProviderMM.template', +); + const codegenLog = (text, info = false) => { // ANSI escape codes for colors and formatting const reset = '\x1b[0m'; @@ -628,6 +644,27 @@ function generateCustomURLHandlers(libraries, outputDir) { ); } +function generateAppDependencyProvider(outputDir) { + fs.mkdirSync(outputDir, {recursive: true}); + codegenLog('Generating RCTAppDependencyProvider'); + + const templateH = fs.readFileSync( + APP_DEPENDENCY_PROVIDER_H_TEMPLATE_PATH, + 'utf8', + ); + const finalPathH = path.join(outputDir, 'RCTAppDependencyProvider.h'); + fs.writeFileSync(finalPathH, templateH); + codegenLog(`Generated artifact: ${finalPathH}`); + + const templateMM = fs.readFileSync( + APP_DEPENDENCY_PROVIDER_MM_TEMPLATE_PATH, + 'utf8', + ); + const finalPathMM = path.join(outputDir, 'RCTAppDependencyProvider.mm'); + fs.writeFileSync(finalPathMM, templateMM); + codegenLog(`Generated artifact: ${finalPathMM}`); +} + function generateRCTThirdPartyComponents(libraries, outputDir) { fs.mkdirSync(outputDir, {recursive: true}); // Generate Header File @@ -886,6 +923,7 @@ function execute(projectRoot, targetPlatform, baseOutputPath) { generateRCTThirdPartyComponents(libraries, outputPath); generateCustomURLHandlers(libraries, outputPath); + generateAppDependencyProvider(outputPath); cleanupEmptyFilesAndFolders(outputPath); } diff --git a/packages/react-native/scripts/codegen/templates/RCTAppDependencyProviderH.template b/packages/react-native/scripts/codegen/templates/RCTAppDependencyProviderH.template new file mode 100644 index 00000000000000..5a1502d16fa115 --- /dev/null +++ b/packages/react-native/scripts/codegen/templates/RCTAppDependencyProviderH.template @@ -0,0 +1,25 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + + +#import + +#if __has_include() +#import +#elif __has_include() +#import +#else +#import "RCTDependencyProvider.h" +#endif + +NS_ASSUME_NONNULL_BEGIN + +@interface RCTAppDependencyProvider : NSObject + +@end + +NS_ASSUME_NONNULL_END diff --git a/packages/react-native/scripts/codegen/templates/RCTAppDependencyProviderMM.template b/packages/react-native/scripts/codegen/templates/RCTAppDependencyProviderMM.template new file mode 100644 index 00000000000000..532d7b4b4ce527 --- /dev/null +++ b/packages/react-native/scripts/codegen/templates/RCTAppDependencyProviderMM.template @@ -0,0 +1,55 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "RCTAppDependencyProvider.h" +#import "RCTModulesConformingToProtocolsProvider.h" +#import "RCTThirdPartyComponentsProvider.h" + +@implementation RCTAppDependencyProvider { + NSArray * _URLRequestHandlerClassNames; + NSArray * _imageDataDecoderClassNames; + NSArray * _imageURLLoaderClassNames; + NSDictionary> * _thirdPartyFabricComponents; +} + +- (nonnull NSArray *)URLRequestHandlerClassNames { + static dispatch_once_t requestUrlToken; + dispatch_once(&requestUrlToken, ^{ + self->_URLRequestHandlerClassNames = RCTModulesConformingToProtocolsProvider.URLRequestHandlerClassNames; + }); + + return _URLRequestHandlerClassNames; +} + +- (nonnull NSArray *)imageDataDecoderClassNames { + static dispatch_once_t dataDecoderToken; + dispatch_once(&dataDecoderToken, ^{ + _imageDataDecoderClassNames = RCTModulesConformingToProtocolsProvider.imageDataDecoderClassNames; + }); + + return _imageDataDecoderClassNames; +} + +- (nonnull NSArray *)imageURLLoaderClassNames { + static dispatch_once_t urlLoaderToken; + dispatch_once(&urlLoaderToken, ^{ + _imageURLLoaderClassNames = RCTModulesConformingToProtocolsProvider.imageURLLoaderClassNames; + }); + + return _imageURLLoaderClassNames; +} + +- (nonnull NSDictionary> *)thirdPartyFabricComponents { + static dispatch_once_t nativeComponentsToken; + dispatch_once(&nativeComponentsToken, ^{ + _thirdPartyFabricComponents = RCTThirdPartyComponentsProvider.thirdPartyFabricComponents; + }); + + return _thirdPartyFabricComponents; +} + +@end