mirror of
https://github.com/facebook/react-native.git
synced 2024-11-21 22:10:14 +00:00
Generate RCTAppDependencyProvider
for apps (#47650)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47650 ## 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 Reviewed By: dmytrorykun Differential Revision: D66074456 fbshipit-source-id: 073022e66da53eca6bf948aeda01f17ad85793ff
This commit is contained in:
parent
b91626af26
commit
41c2502b36
@ -143,6 +143,7 @@ class CodegenUtils
|
||||
'React-debug': [],
|
||||
'React-utils': [],
|
||||
'React-featureflags': [],
|
||||
'React-RCTAppDelegate': [],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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 <Foundation/Foundation.h>
|
||||
|
||||
#if __has_include(<React-RCTAppDelegate/RCTDependencyProvider.h>)
|
||||
#import <React-RCTAppDelegate/RCTDependencyProvider.h>
|
||||
#elif __has_include(<React_RCTAppDelegate/RCTDependencyProvider.h>)
|
||||
#import <React_RCTAppDelegate/RCTDependencyProvider.h>
|
||||
#else
|
||||
#import "RCTDependencyProvider.h"
|
||||
#endif
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface RCTAppDependencyProvider : NSObject <RCTDependencyProvider>
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -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<NSString *> * _URLRequestHandlerClassNames;
|
||||
NSArray<NSString *> * _imageDataDecoderClassNames;
|
||||
NSArray<NSString *> * _imageURLLoaderClassNames;
|
||||
NSDictionary<NSString *,Class<RCTComponentViewProtocol>> * _thirdPartyFabricComponents;
|
||||
}
|
||||
|
||||
- (nonnull NSArray<NSString *> *)URLRequestHandlerClassNames {
|
||||
static dispatch_once_t requestUrlToken;
|
||||
dispatch_once(&requestUrlToken, ^{
|
||||
self->_URLRequestHandlerClassNames = RCTModulesConformingToProtocolsProvider.URLRequestHandlerClassNames;
|
||||
});
|
||||
|
||||
return _URLRequestHandlerClassNames;
|
||||
}
|
||||
|
||||
- (nonnull NSArray<NSString *> *)imageDataDecoderClassNames {
|
||||
static dispatch_once_t dataDecoderToken;
|
||||
dispatch_once(&dataDecoderToken, ^{
|
||||
_imageDataDecoderClassNames = RCTModulesConformingToProtocolsProvider.imageDataDecoderClassNames;
|
||||
});
|
||||
|
||||
return _imageDataDecoderClassNames;
|
||||
}
|
||||
|
||||
- (nonnull NSArray<NSString *> *)imageURLLoaderClassNames {
|
||||
static dispatch_once_t urlLoaderToken;
|
||||
dispatch_once(&urlLoaderToken, ^{
|
||||
_imageURLLoaderClassNames = RCTModulesConformingToProtocolsProvider.imageURLLoaderClassNames;
|
||||
});
|
||||
|
||||
return _imageURLLoaderClassNames;
|
||||
}
|
||||
|
||||
- (nonnull NSDictionary<NSString *,Class<RCTComponentViewProtocol>> *)thirdPartyFabricComponents {
|
||||
static dispatch_once_t nativeComponentsToken;
|
||||
dispatch_once(&nativeComponentsToken, ^{
|
||||
_thirdPartyFabricComponents = RCTThirdPartyComponentsProvider.thirdPartyFabricComponents;
|
||||
});
|
||||
|
||||
return _thirdPartyFabricComponents;
|
||||
}
|
||||
|
||||
@end
|
Loading…
Reference in New Issue
Block a user