Add default prop handling

Summary: Adds handling for default props for java props

Reviewed By: JoshuaGross

Differential Revision: D16417825

fbshipit-source-id: 00ad2ace33409e9c204de16970ff0b7f756fda71
This commit is contained in:
Rick Hanlon
2019-07-24 10:36:24 -07:00
committed by Facebook Github Bot
parent 34505dba05
commit df0d6e28e5
4 changed files with 42 additions and 30 deletions
@@ -40,17 +40,29 @@ function getJavaValueForProp(
switch (typeAnnotation.type) {
case 'BooleanTypeAnnotation':
return '(boolean) value';
return `value == null ? ${typeAnnotation.default.toString()} : (boolean) value`;
case 'StringTypeAnnotation':
return '(String) value';
const defaultValueString =
typeAnnotation.default === null
? 'null'
: `"${typeAnnotation.default}"`;
return `value == null ? ${defaultValueString} : (String) value`;
case 'Int32TypeAnnotation':
return '((Double) value).intValue()';
return `value == null ? ${
typeAnnotation.default
} : ((Double) value).intValue()`;
case 'FloatTypeAnnotation':
return '((Double) value).floatValue()';
if (prop.optional) {
return `value == null ? ${
typeAnnotation.default
}f : ((Double) value).floatValue()`;
} else {
return 'value == null ? Float.NaN : ((Double) value).floatValue()';
}
case 'NativePrimitiveTypeAnnotation':
switch (typeAnnotation.name) {
case 'ColorPrimitive':
return '((Double) value).intValue()';
return 'value == null ? null : ((Double) value).intValue()';
case 'ImageSourcePrimitive':
return '(ReadableMap) value';
case 'PointPrimitive':