@Retention(value=RUNTIME)
@Target(value=METHOD)
public @interface ReactProp
ViewManager
.
Each annotated method should return void
and take exactly two arguments: first being
a view instance to be updated and second a value that should be set.
Allowed types of values are:
- primitives (int, boolean, double, float)
- String
- Boolean
- ReadableArray
- ReadableMap
When property gets removed from the corresponding component in React, annotated setter will be
called with null
in case of non-primitive value type or with a default value in case when
the value type is a primitive (use appropriate default field of this annotation to customize
default value that is going to be used: defaultBoolean()
, defaultDouble()
, etc.)
Since in case of property removal for non-primitive value type setter will be called with value
set to null
it's required that value type is annotated with Nullable
.
Note: Since boolean property type can be represented both as primitive and wrapped default value
set through defaultBoolean()
is only respected for primitive type and for the wrapped type
null
will be used as a default.Modifier and Type | Fields and Description |
---|---|
static java.lang.String |
USE_DEFAULT_TYPE |
Modifier and Type | Required Element and Description |
---|---|
java.lang.String |
name
Name of the property exposed to JS that will be updated using setter method annotated with
the given instance of
ReactProp annotation |
Modifier and Type | Optional Element and Description |
---|---|
java.lang.String |
customType
Type of property that will be send to JS.
|
boolean |
defaultBoolean
Default value for property of type
boolean . |
double |
defaultDouble
Default value for property of type
double . |
float |
defaultFloat
Default value for property of type
float . |
int |
defaultInt
Default value for property of type
int . |
public abstract java.lang.String name
ReactProp
annotation@Nullable public abstract java.lang.String customType
customType
should not be
set in which case default type will be send to JS based on the type of value argument from the
setter method (e.g. for int
, double
default is "number", for
ReadableArray
it's "Array"). Custom type may be used when additional processing of the
value needs to be done in JS before sending it over the bridge. A good example of that would be
backgroundColor property, which is expressed as a String
in JS, but we use
processColor
JS module to convert it to int
before sending over the bridge.public abstract double defaultDouble
double
. This value will be provided to property
setter method annotated with ReactProp
if property with a given name gets removed
from the component description in JSpublic abstract float defaultFloat
float
. This value will be provided to property
setter method annotated with ReactProp
if property with a given name gets removed
from the component description in JSpublic abstract int defaultInt
int
. This value will be provided to property
setter method annotated with ReactProp
if property with a given name gets removed
from the component description in JSpublic abstract boolean defaultBoolean
boolean
. This value will be provided to property
setter method annotated with ReactProp
if property with a given name gets removed
from the component description in JS