Back out D16434402, D16434634

Summary: build-break

fbshipit-source-id: d0786ba78689113be543535bd117c3d7f1de9996
This commit is contained in:
Jason Carreiro
2019-07-24 13:57:46 -07:00
committed by Facebook Github Bot
parent 17f8e5810f
commit 136dde359c
7 changed files with 19 additions and 145 deletions
@@ -11,7 +11,6 @@
'use strict';
import type {
CommandTypeShape,
ComponentShape,
PropTypeShape,
SchemaType,
@@ -27,20 +26,10 @@ package com.facebook.react.viewmanagers;
::_IMPORTS_::
public class ::_CLASSNAME_::<T extends ::_EXTEND_CLASSES_::> {
::_METHODS_::
}
`;
const propSetterTemplate = `
public void setProperty(::_INTERFACE_CLASSNAME_::<T> viewManager, T view, String propName, Object value) {
::_PROP_CASES_::
}
`;
const commandsTemplate = `
public void receiveCommand(::_INTERFACE_CLASSNAME_::<T> viewManager, T view, String commandName, ReadableArray args) {
::_COMMAND_CASES_::
}
}
`;
function getJavaValueForProp(
@@ -116,51 +105,6 @@ function generatePropCasesString(
}`;
}
function getCommandArgJavaType(param) {
switch (param.typeAnnotation.type) {
case 'BooleanTypeAnnotation':
return 'getBoolean';
case 'Int32TypeAnnotation':
return 'getInt';
default:
(param.typeAnnotation.type: empty);
throw new Error('Receieved invalid typeAnnotation');
}
}
function getCommandArguments(command: CommandTypeShape): string {
return [
'view',
...command.typeAnnotation.params.map((param, index) => {
const commandArgJavaType = getCommandArgJavaType(param);
return `args.${commandArgJavaType}(${index})`;
}),
].join(', ');
}
function generateCommandCasesString(
component: ComponentShape,
componentName: string,
) {
if (component.commands.length === 0) {
return null;
}
const commandMethods = component.commands
.map(command => {
return `case "${command.name}":
viewManager.${toSafeJavaString(
command.name,
false,
)}(${getCommandArguments(command)});
break;`;
})
.join('\n' + ' ');
return commandMethods;
}
function getClassExtendString(component): string {
const extendString = component.extendsProps
.map(extendProps => {
@@ -183,28 +127,6 @@ function getClassExtendString(component): string {
return extendString;
}
function getDelegateImports(component) {
const imports = getImports(component);
// The delegate needs ReadableArray for commands always.
// The interface doesn't always need it
if (component.commands.length > 0) {
imports.add('import com.facebook.react.bridge.ReadableArray;');
}
return imports;
}
function generateMethods(propsString, commandsString): string {
return [
propSetterTemplate.trim().replace('::_PROP_CASES_::', propsString),
commandsString != null
? commandsTemplate.trim().replace('::_COMMAND_CASES_::', commandsString)
: '',
]
.join('\n\n ')
.trimRight();
}
module.exports = {
generate(libraryName: string, schema: SchemaType): FilesOutput {
const files = new Map();
@@ -221,12 +143,8 @@ module.exports = {
const interfaceClassName = `${componentName}ViewManagerInterface`;
const fileName = `${className}.java`;
const imports = getDelegateImports(component);
const imports = getImports(component);
const propsString = generatePropCasesString(component, componentName);
const commandsString = generateCommandCasesString(
component,
componentName,
);
const extendString = getClassExtendString(component);
const replacedTemplate = template
@@ -237,13 +155,9 @@ module.exports = {
.join('\n'),
)
.replace(/::_CLASSNAME_::/g, className)
.replace(/::_INTERFACE_CLASSNAME_::/g, interfaceClassName)
.replace('::_EXTEND_CLASSES_::', extendString)
.replace('::_PROP_CASES_::', propsString)
.replace(
'::_METHODS_::',
generateMethods(propsString, commandsString),
)
.replace(/::_INTERFACE_CLASSNAME_::/g, interfaceClassName);
.replace('::_PROP_CASES_::', propsString);
files.set(fileName, replacedTemplate);
});