Skip to content

Commit a21d63f

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Generate RCTAppDependencyProvider for apps
Summary: ## This Change: This change generates the `RCTAppDependencyProvider` for the apps, so that the amount of changes required by the users is minimal. ## Context React Native has a last temporal dependency on Codegen in the React-RCTAppDelegate pod. The RCTAppDelegate has the responsibility to provide various dependencies to react native, like third party components and various modules. ReactCodegen is generated when the user create the project, while React-RCTAppDelegate eists in React Native itself. This dependency means that we cannot prepare prebuilt for iOS for React Native because when we would have to create prebuilds, we would need the React Codegen, but we can't create a React codegen package that will fit all the apps, because React Codegen can contains App Specific modules and components and apps might have different dependencies. ## Changelog: [iOS][Added] - Introduce the RCTAppDependencyProvider to minimize the changes required y the users Differential Revision: D66074456
1 parent 26c71d8 commit a21d63f

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-0
lines changed

packages/react-native/scripts/cocoapods/codegen_utils.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def get_react_codegen_spec(package_json_file, folly_version: get_folly_config()[
143143
'React-debug': [],
144144
'React-utils': [],
145145
'React-featureflags': [],
146+
'React-RCTAppDelegate': [],
146147
}
147148
}
148149

packages/react-native/scripts/codegen/generate-artifacts-executor.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,22 @@ const THIRD_PARTY_COMPONENTS_MM_TEMPLATE_PATH = path.join(
102102
'RCTThirdPartyComponentsProviderMM.template',
103103
);
104104

105+
const APP_DEPENDENCY_PROVIDER_H_TEMPLATE_PATH = path.join(
106+
REACT_NATIVE_PACKAGE_ROOT_FOLDER,
107+
'scripts',
108+
'codegen',
109+
'templates',
110+
'RCTAppDependencyProviderH.template',
111+
);
112+
113+
const APP_DEPENDENCY_PROVIDER_MM_TEMPLATE_PATH = path.join(
114+
REACT_NATIVE_PACKAGE_ROOT_FOLDER,
115+
'scripts',
116+
'codegen',
117+
'templates',
118+
'RCTAppDependencyProviderMM.template',
119+
);
120+
105121
const codegenLog = (text, info = false) => {
106122
// ANSI escape codes for colors and formatting
107123
const reset = '\x1b[0m';
@@ -628,6 +644,27 @@ function generateCustomURLHandlers(libraries, outputDir) {
628644
);
629645
}
630646

647+
function generateAppDependencyProvider(outputDir) {
648+
fs.mkdirSync(outputDir, {recursive: true});
649+
codegenLog('Generating RCTAppDependencyProvider');
650+
651+
const templateH = fs.readFileSync(
652+
APP_DEPENDENCY_PROVIDER_H_TEMPLATE_PATH,
653+
'utf8',
654+
);
655+
const finalPathH = path.join(outputDir, 'RCTAppDependencyProvider.h');
656+
fs.writeFileSync(finalPathH, templateH);
657+
codegenLog(`Generated artifact: ${finalPathH}`);
658+
659+
const templateMM = fs.readFileSync(
660+
APP_DEPENDENCY_PROVIDER_MM_TEMPLATE_PATH,
661+
'utf8',
662+
);
663+
const finalPathMM = path.join(outputDir, 'RCTAppDependencyProvider.mm');
664+
fs.writeFileSync(finalPathMM, templateMM);
665+
codegenLog(`Generated artifact: ${finalPathMM}`);
666+
}
667+
631668
function generateRCTThirdPartyComponents(libraries, outputDir) {
632669
fs.mkdirSync(outputDir, {recursive: true});
633670
// Generate Header File
@@ -886,6 +923,7 @@ function execute(projectRoot, targetPlatform, baseOutputPath) {
886923

887924
generateRCTThirdPartyComponents(libraries, outputPath);
888925
generateCustomURLHandlers(libraries, outputPath);
926+
generateAppDependencyProvider(outputPath);
889927

890928
cleanupEmptyFilesAndFolders(outputPath);
891929
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
9+
#import <Foundation/Foundation.h>
10+
11+
#if __has_include(<React-RCTAppDelegate/RCTDependencyProvider.h>)
12+
#import <React-RCTAppDelegate/RCTDependencyProvider.h>
13+
#elif __has_include(<React_RCTAppDelegate/RCTDependencyProvider.h>)
14+
#import <React_RCTAppDelegate/RCTDependencyProvider.h>
15+
#else
16+
#import "RCTDependencyProvider.h"
17+
#endif
18+
19+
NS_ASSUME_NONNULL_BEGIN
20+
21+
@interface RCTAppDependencyProvider : NSObject <RCTDependencyProvider>
22+
23+
@end
24+
25+
NS_ASSUME_NONNULL_END
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import "RCTAppDependencyProvider.h"
9+
#import "RCTModulesConformingToProtocolsProvider.h"
10+
#import "RCTThirdPartyComponentsProvider.h"
11+
12+
@implementation RCTAppDependencyProvider {
13+
NSArray<NSString *> * _URLRequestHandlerClassNames;
14+
NSArray<NSString *> * _imageDataDecoderClassNames;
15+
NSArray<NSString *> * _imageURLLoaderClassNames;
16+
NSDictionary<NSString *,Class<RCTComponentViewProtocol>> * _thirdPartyFabricComponents;
17+
}
18+
19+
- (nonnull NSArray<NSString *> *)URLRequestHandlerClassNames {
20+
static dispatch_once_t requestUrlToken;
21+
dispatch_once(&requestUrlToken, ^{
22+
self->_URLRequestHandlerClassNames = RCTModulesConformingToProtocolsProvider.URLRequestHandlerClassNames;
23+
});
24+
25+
return _URLRequestHandlerClassNames;
26+
}
27+
28+
- (nonnull NSArray<NSString *> *)imageDataDecoderClassNames {
29+
static dispatch_once_t dataDecoderToken;
30+
dispatch_once(&dataDecoderToken, ^{
31+
_imageDataDecoderClassNames = RCTModulesConformingToProtocolsProvider.imageDataDecoderClassNames;
32+
});
33+
34+
return _imageDataDecoderClassNames;
35+
}
36+
37+
- (nonnull NSArray<NSString *> *)imageURLLoaderClassNames {
38+
static dispatch_once_t urlLoaderToken;
39+
dispatch_once(&urlLoaderToken, ^{
40+
_imageURLLoaderClassNames = RCTModulesConformingToProtocolsProvider.imageURLLoaderClassNames;
41+
});
42+
43+
return _imageURLLoaderClassNames;
44+
}
45+
46+
- (nonnull NSDictionary<NSString *,Class<RCTComponentViewProtocol>> *)thirdPartyFabricComponents {
47+
static dispatch_once_t nativeComponentsToken;
48+
dispatch_once(&nativeComponentsToken, ^{
49+
_thirdPartyFabricComponents = RCTThirdPartyComponentsProvider.thirdPartyFabricComponents;
50+
});
51+
52+
return _thirdPartyFabricComponents;
53+
}
54+
55+
@end

0 commit comments

Comments
 (0)