mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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:
committed by
Facebook Github Bot
parent
34505dba05
commit
df0d6e28e5
+17
-5
@@ -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':
|
||||
|
||||
Reference in New Issue
Block a user