From c0c8e7cfdf83b3a215f15257892f892604eff431 Mon Sep 17 00:00:00 2001 From: Denis Koroskin Date: Wed, 9 Dec 2015 12:34:24 -0800 Subject: [PATCH] Add support for `double` type in ReactPropGroup Reviewed By: astreet Differential Revision: D2735362 fb-gh-sync-id: a8eab400248fc4c8ad5d43e6a34cfd350dfb1d26 --- .../com/facebook/react/uimanager/ReactPropGroup.java | 10 +++++++++- .../react/uimanager/ViewManagersPropertyCache.java | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactPropGroup.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactPropGroup.java index 13c843314..9e2a17b6e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactPropGroup.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactPropGroup.java @@ -26,7 +26,8 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; * group of the property being updated. Last, third argument represent the value that should be set. * * - * Currently only {@code int}, {@code float} and {@link String} value types are supported. + * Currently only {@code int}, {@code float}, {@code double} and {@link String} value types are + * supported. * * In case when property has been removed from the corresponding react component annotated setter * will be called and default value will be provided as a value parameter. Default value can be @@ -68,6 +69,13 @@ public @interface ReactPropGroup { */ float defaultFloat() default 0.0f; + /** + * Default value for property of type {@code double}. This value will be provided to property + * setter method annotated with {@link ReactPropGroup} if property with a given name gets removed + * from the component description in JS + */ + double defaultDouble() default 0.0; + /** * Default value for property of type {@code int}. This value will be provided to property * setter method annotated with {@link ReactPropGroup} if property with a given name gets removed diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagersPropertyCache.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagersPropertyCache.java index fd0ce6c41..0e2a33148 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagersPropertyCache.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagersPropertyCache.java @@ -141,6 +141,11 @@ import com.facebook.react.bridge.ReadableMap; mDefaultValue = defaultValue; } + public DoublePropSetter(ReactPropGroup prop, Method setter, int index, double defaultValue) { + super(prop, "number", setter, index); + mDefaultValue = defaultValue; + } + @Override protected Object extractProperty(CatalystStylesDiffMap props) { return props.getDouble(mPropName, mDefaultValue); @@ -366,6 +371,12 @@ import com.facebook.react.bridge.ReadableMap; names[i], new FloatPropSetter(annotation, method, i, annotation.defaultFloat())); } + } else if (propTypeClass == double.class) { + for (int i = 0; i < names.length; i++) { + props.put( + names[i], + new DoublePropSetter(annotation, method, i, annotation.defaultDouble())); + } } else if (propTypeClass == Integer.class) { for (int i = 0; i < names.length; i++) { props.put(