mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Update Module Generators to follow new NativeModuleSchema
Summary: NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack). ## Changes 1. NativeModule generators now use the new RN Codegen NativeModule schema. 2. Tangential: We're no longer removing the `Native` prefix from the NativeModule filename, assuming that that's the module name (problem: wrong), and prefixing again with Native (problem: redundant), when we're generating code. Instead, like the internal codegen, we simply pass the filename to the Codegen output. Our linters enforce that all NativeModule specs are contained with files that start off with `Native`. 3. `GenerateModuleCpp` was fixed to use the actual module name as opposed to the spec name. I added a comment inline. Changelog: [Internal] (Note: this ignores all push blocking failures!) Reviewed By: PeteTheHeat Differential Revision: D24236405 fbshipit-source-id: ccd6b5674d252c350be0ec8a86e7ca5f2f614778
This commit is contained in:
committed by
Facebook GitHub Bot
parent
ee177f6cba
commit
c4f23354fd
Vendored
+20
-20
@@ -17,16 +17,16 @@ import type {
|
||||
} from '../serializeMethod';
|
||||
|
||||
const ModuleTemplate = ({
|
||||
moduleName,
|
||||
codegenModuleName,
|
||||
structs,
|
||||
methodSerializationOutputs,
|
||||
}: $ReadOnly<{|
|
||||
moduleName: string,
|
||||
codegenModuleName: string,
|
||||
structs: $ReadOnlyArray<Struct>,
|
||||
methodSerializationOutputs: $ReadOnlyArray<MethodSerializationOutput>,
|
||||
|}>) => `${structs
|
||||
.map(struct =>
|
||||
RCTCxxConvertCategoryTemplate({moduleName, structName: struct.name}),
|
||||
RCTCxxConvertCategoryTemplate({codegenModuleName, structName: struct.name}),
|
||||
)
|
||||
.join('\n')}
|
||||
namespace facebook {
|
||||
@@ -34,7 +34,7 @@ namespace facebook {
|
||||
${methodSerializationOutputs
|
||||
.map(serializedMethodParts =>
|
||||
InlineHostFunctionTemplate({
|
||||
moduleName,
|
||||
codegenModuleName,
|
||||
methodName: serializedMethodParts.methodName,
|
||||
returnJSType: serializedMethodParts.returnJSType,
|
||||
selector: serializedMethodParts.selector,
|
||||
@@ -42,12 +42,12 @@ namespace facebook {
|
||||
)
|
||||
.join('\n')}
|
||||
|
||||
Native${moduleName}SpecJSI::Native${moduleName}SpecJSI(const ObjCTurboModule::InitParams ¶ms)
|
||||
${codegenModuleName}SpecJSI::${codegenModuleName}SpecJSI(const ObjCTurboModule::InitParams ¶ms)
|
||||
: ObjCTurboModule(params) {
|
||||
${methodSerializationOutputs
|
||||
.map(({methodName, structParamRecords, argCount}) =>
|
||||
MethodMapEntryTemplate({
|
||||
moduleName,
|
||||
codegenModuleName,
|
||||
methodName,
|
||||
structParamRecords,
|
||||
argCount,
|
||||
@@ -59,58 +59,58 @@ namespace facebook {
|
||||
} // namespace facebook`;
|
||||
|
||||
const RCTCxxConvertCategoryTemplate = ({
|
||||
moduleName,
|
||||
codegenModuleName,
|
||||
structName,
|
||||
}: $ReadOnly<{|
|
||||
moduleName: string,
|
||||
codegenModuleName: string,
|
||||
structName: string,
|
||||
|}>) => `@implementation RCTCxxConvert (Native${moduleName}_${structName})
|
||||
+ (RCTManagedPointer *)JS_Native${moduleName}_${structName}:(id)json
|
||||
|}>) => `@implementation RCTCxxConvert (${codegenModuleName}_${structName})
|
||||
+ (RCTManagedPointer *)JS_${codegenModuleName}_${structName}:(id)json
|
||||
{
|
||||
return facebook::react::managedPointer<JS::Native${moduleName}::${structName}>(json);
|
||||
return facebook::react::managedPointer<JS::${codegenModuleName}::${structName}>(json);
|
||||
}
|
||||
@end`;
|
||||
|
||||
const InlineHostFunctionTemplate = ({
|
||||
moduleName,
|
||||
codegenModuleName,
|
||||
methodName,
|
||||
returnJSType,
|
||||
selector,
|
||||
}: $ReadOnly<{|
|
||||
moduleName: string,
|
||||
codegenModuleName: string,
|
||||
methodName: string,
|
||||
returnJSType: string,
|
||||
selector: string,
|
||||
|}>) => `
|
||||
static facebook::jsi::Value __hostFunction_Native${moduleName}SpecJSI_${methodName}(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
||||
static facebook::jsi::Value __hostFunction_${codegenModuleName}SpecJSI_${methodName}(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
||||
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, ${returnJSType}, "${methodName}", ${selector}, args, count);
|
||||
}`;
|
||||
|
||||
const MethodMapEntryTemplate = ({
|
||||
moduleName,
|
||||
codegenModuleName,
|
||||
methodName,
|
||||
structParamRecords,
|
||||
argCount,
|
||||
}: $ReadOnly<{|
|
||||
moduleName: string,
|
||||
codegenModuleName: string,
|
||||
methodName: string,
|
||||
structParamRecords: $ReadOnlyArray<StructParameterRecord>,
|
||||
argCount: number,
|
||||
|}>) => `
|
||||
methodMap_["${methodName}"] = MethodMetadata {${argCount}, __hostFunction_Native${moduleName}SpecJSI_${methodName}};
|
||||
methodMap_["${methodName}"] = MethodMetadata {${argCount}, __hostFunction_${codegenModuleName}SpecJSI_${methodName}};
|
||||
${structParamRecords
|
||||
.map(({paramIndex, structName}) => {
|
||||
return `setMethodArgConversionSelector(@"${methodName}", ${paramIndex}, @"JS_Native${moduleName}_${structName}:");`;
|
||||
return `setMethodArgConversionSelector(@"${methodName}", ${paramIndex}, @"JS_${codegenModuleName}_${structName}:");`;
|
||||
})
|
||||
.join('\n' + ' '.repeat(8))}`;
|
||||
|
||||
function serializeModuleSource(
|
||||
moduleName: string,
|
||||
codegenModuleName: string,
|
||||
structs: $ReadOnlyArray<Struct>,
|
||||
methodSerializationOutputs: $ReadOnlyArray<MethodSerializationOutput>,
|
||||
): string {
|
||||
return ModuleTemplate({
|
||||
moduleName,
|
||||
codegenModuleName,
|
||||
structs: structs.filter(({context}) => context !== 'CONSTANTS'),
|
||||
methodSerializationOutputs,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user