Add support for `double` type in ReactPropGroup
Reviewed By: astreet Differential Revision: D2735362 fb-gh-sync-id: a8eab400248fc4c8ad5d43e6a34cfd350dfb1d26
This commit is contained in:
parent
e8659b3602
commit
c0c8e7cfdf
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue