mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix ObjC++ structs and method mapping
Summary: Adjust generated ObjC++ code to resolve a few build time and run time errors: * Suppress CONSTANTS struct implementations * Use type alias name as struct name when serializing arguments that involve a type alias * Use actual number of arguments for a method when generating method map. With these changes in place, RNTester can be built and run using the code that is generated by the new codegen. Changelog: [Internal] Reviewed By: hramos Differential Revision: D23926500 fbshipit-source-id: 88fcbb795fd71dc8155eb26348db943975e13e84
This commit is contained in:
1 parent
97d3e85c29
commit
6d6e04619f
4 files changed
+61
-161
No files matched your search
Vendored
+15
-1
@@ -51,6 +51,7 @@ export type MethodSerializationOutput = $ReadOnly<{|
|
||||
selector: string,
|
||||
structParamRecords: $ReadOnlyArray<StructParameterRecord>,
|
||||
returnJSType: ReturnJSType,
|
||||
argCount: number,
|
||||
|}>;
|
||||
|
||||
function serializeMethod(
|
||||
@@ -77,7 +78,7 @@ function serializeMethod(
|
||||
const structParamRecords: Array<StructParameterRecord> = [];
|
||||
|
||||
params.forEach((param, index) => {
|
||||
const structName = `Spec${capitalize(methodName)}${capitalize(param.name)}`;
|
||||
const structName = getParamStructName(methodName, param);
|
||||
const {objCType, isStruct} = getParamObjCType(
|
||||
moduleName,
|
||||
methodName,
|
||||
@@ -145,10 +146,22 @@ function serializeMethod(
|
||||
selector: `@selector(${selector})`,
|
||||
structParamRecords,
|
||||
returnJSType,
|
||||
argCount: params.length,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function getParamStructName(
|
||||
methodName: string,
|
||||
param: NativeModuleMethodParamSchema,
|
||||
): string {
|
||||
if (param.typeAnnotation.type === 'TypeAliasTypeAnnotation') {
|
||||
return param.typeAnnotation.name;
|
||||
}
|
||||
|
||||
return `Spec${capitalize(methodName)}${capitalize(param.name)}`;
|
||||
}
|
||||
|
||||
function getParamObjCType(
|
||||
moduleName: string,
|
||||
methodName: string,
|
||||
@@ -403,6 +416,7 @@ function serializeConstantsProtocolMethods(
|
||||
returnJSType: 'ObjectKind',
|
||||
selector: `@selector(${methodName})`,
|
||||
structParamRecords: [],
|
||||
argCount: 0,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user