mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Revert Refactor ViewManagerInterfaces codegen to generate kotlin classes
Summary: reverting Refactor ViewManagerInterfaces codegen to generate kotlin classes because of warning in OSS, we will reland after 0.81 cut Changelog: [Android][Breaking] - Revert of Migrate ViewManagerInterfaces to kotlin. Some types in code generated ViewManagerInterfaces might differ. e.g. this will start enforcing nullability in parameters of viewManagerInterface methods (e.g. String commands parameters are not nullable, view params are not nullable in any method, etc) Reviewed By: lenaic, mlord93 Differential Revision: D77759777 fbshipit-source-id: c24b216b231cdc53296d8c9fca8d789d80daa596
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0e175ce5b6
commit
2d0aa1a747
+49
-32
@@ -48,15 +48,19 @@ const FileTemplate = ({
|
||||
* ${'@'}generated by codegen project: GeneratePropsJavaInterface.js
|
||||
*/
|
||||
|
||||
package ${packageName}
|
||||
package ${packageName};
|
||||
|
||||
${imports}
|
||||
|
||||
public interface ${className}<T: ${extendClasses}>: ViewManagerWithGeneratedInterface {
|
||||
public interface ${className}<T extends ${extendClasses}> extends ViewManagerWithGeneratedInterface {
|
||||
${methods}
|
||||
}
|
||||
`;
|
||||
|
||||
function addNullable(imports: Set<string>) {
|
||||
imports.add('import androidx.annotation.Nullable;');
|
||||
}
|
||||
|
||||
function getJavaValueForProp(
|
||||
prop: NamedShape<PropTypeAnnotation>,
|
||||
imports: Set<string>,
|
||||
@@ -66,52 +70,65 @@ function getJavaValueForProp(
|
||||
switch (typeAnnotation.type) {
|
||||
case 'BooleanTypeAnnotation':
|
||||
if (typeAnnotation.default === null) {
|
||||
return 'value: Boolean?';
|
||||
addNullable(imports);
|
||||
return '@Nullable Boolean value';
|
||||
} else {
|
||||
return 'value: Boolean';
|
||||
return 'boolean value';
|
||||
}
|
||||
case 'StringTypeAnnotation':
|
||||
return 'value: String?';
|
||||
addNullable(imports);
|
||||
return '@Nullable String value';
|
||||
case 'Int32TypeAnnotation':
|
||||
return 'value: Int';
|
||||
return 'int value';
|
||||
case 'DoubleTypeAnnotation':
|
||||
return 'value: Double';
|
||||
return 'double value';
|
||||
case 'FloatTypeAnnotation':
|
||||
if (typeAnnotation.default === null) {
|
||||
return 'value: Float?';
|
||||
addNullable(imports);
|
||||
return '@Nullable Float value';
|
||||
} else {
|
||||
return 'value: Float';
|
||||
return 'float value';
|
||||
}
|
||||
case 'ReservedPropTypeAnnotation':
|
||||
switch (typeAnnotation.name) {
|
||||
case 'ColorPrimitive':
|
||||
return 'value: Int?';
|
||||
addNullable(imports);
|
||||
return '@Nullable Integer value';
|
||||
case 'ImageSourcePrimitive':
|
||||
return 'value: ReadableMap?';
|
||||
addNullable(imports);
|
||||
return '@Nullable ReadableMap value';
|
||||
case 'ImageRequestPrimitive':
|
||||
return 'value: ReadableMap?';
|
||||
addNullable(imports);
|
||||
return '@Nullable ReadableMap value';
|
||||
case 'PointPrimitive':
|
||||
return 'value: ReadableMap?';
|
||||
addNullable(imports);
|
||||
return '@Nullable ReadableMap value';
|
||||
case 'EdgeInsetsPrimitive':
|
||||
return 'value: ReadableMap?';
|
||||
addNullable(imports);
|
||||
return '@Nullable ReadableMap value';
|
||||
case 'DimensionPrimitive':
|
||||
return 'value: YogaValue?';
|
||||
addNullable(imports);
|
||||
return '@Nullable YogaValue value';
|
||||
default:
|
||||
(typeAnnotation.name: empty);
|
||||
throw new Error('Received unknown ReservedPropTypeAnnotation');
|
||||
}
|
||||
case 'ArrayTypeAnnotation': {
|
||||
return 'value: ReadableArray?';
|
||||
addNullable(imports);
|
||||
return '@Nullable ReadableArray value';
|
||||
}
|
||||
case 'ObjectTypeAnnotation': {
|
||||
return 'value: ReadableMap?';
|
||||
addNullable(imports);
|
||||
return '@Nullable ReadableMap value';
|
||||
}
|
||||
case 'StringEnumTypeAnnotation':
|
||||
return 'value: String?';
|
||||
addNullable(imports);
|
||||
return '@Nullable String value';
|
||||
case 'Int32EnumTypeAnnotation':
|
||||
return 'value: Int?';
|
||||
addNullable(imports);
|
||||
return '@Nullable Integer value';
|
||||
case 'MixedTypeAnnotation':
|
||||
return 'value: Dynamic';
|
||||
return 'Dynamic value';
|
||||
default:
|
||||
(typeAnnotation: empty);
|
||||
throw new Error('Received invalid typeAnnotation');
|
||||
@@ -125,9 +142,9 @@ function generatePropsString(component: ComponentShape, imports: Set<string>) {
|
||||
|
||||
return component.props
|
||||
.map(prop => {
|
||||
return `public fun set${toSafeJavaString(
|
||||
return `void set${toSafeJavaString(
|
||||
prop.name,
|
||||
)}(view: T, ${getJavaValueForProp(prop, imports)}): Unit`;
|
||||
)}(T view, ${getJavaValueForProp(prop, imports)});`;
|
||||
})
|
||||
.join('\n' + ' ');
|
||||
}
|
||||
@@ -139,19 +156,19 @@ function getCommandArgJavaType(param: NamedShape<CommandParamTypeAnnotation>) {
|
||||
case 'ReservedTypeAnnotation':
|
||||
switch (typeAnnotation.name) {
|
||||
case 'RootTag':
|
||||
return 'Double';
|
||||
return 'double';
|
||||
default:
|
||||
(typeAnnotation.name: empty);
|
||||
throw new Error(`Receieved invalid type: ${typeAnnotation.name}`);
|
||||
}
|
||||
case 'BooleanTypeAnnotation':
|
||||
return 'Boolean';
|
||||
return 'boolean';
|
||||
case 'DoubleTypeAnnotation':
|
||||
return 'Double';
|
||||
return 'double';
|
||||
case 'FloatTypeAnnotation':
|
||||
return 'Float';
|
||||
return 'float';
|
||||
case 'Int32TypeAnnotation':
|
||||
return 'Int';
|
||||
return 'int';
|
||||
case 'StringTypeAnnotation':
|
||||
return 'String';
|
||||
case 'ArrayTypeAnnotation':
|
||||
@@ -167,11 +184,11 @@ function getCommandArguments(
|
||||
componentName: string,
|
||||
): string {
|
||||
return [
|
||||
'view: T',
|
||||
'T view',
|
||||
...command.typeAnnotation.params.map(param => {
|
||||
const commandArgJavaType = getCommandArgJavaType(param);
|
||||
|
||||
return `${param.name}: ${commandArgJavaType}`;
|
||||
return `${commandArgJavaType} ${param.name}`;
|
||||
}),
|
||||
].join(', ');
|
||||
}
|
||||
@@ -184,10 +201,10 @@ function generateCommandsString(
|
||||
.map(command => {
|
||||
const safeJavaName = toSafeJavaString(command.name, false);
|
||||
|
||||
return `public fun ${safeJavaName}(${getCommandArguments(
|
||||
return `void ${safeJavaName}(${getCommandArguments(
|
||||
command,
|
||||
componentName,
|
||||
)}): Unit`;
|
||||
)});`;
|
||||
})
|
||||
.join('\n' + ' ');
|
||||
}
|
||||
@@ -270,7 +287,7 @@ module.exports = {
|
||||
.trimRight(),
|
||||
});
|
||||
|
||||
files.set(`${outputDir}/${className}.kt`, replacedTemplate);
|
||||
files.set(`${outputDir}/${className}.java`, replacedTemplate);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user