Package 

Annotation ReactProp

  • All Implemented Interfaces:
    java.lang.annotation.Annotation

    @Retention(value = RUNTIME)@Target(value = ElementType.METHOD) 
    public @interface ReactProp
    
                        

    Use this annotation to annotate properties of native views that should be exposed to JS. This annotation should only be used for setter methods of subclasses of .

    Each annotated method should return {@code 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:

    When property gets removed from the corresponding component in React, annotated setter will be called with {@code 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 {@code 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 {@code null} will be used as a default.

    • Method Summary

      Modifier and Type Method Description
      abstract String name() Name of the property exposed to JS that will be updated using setter method annotated with thegiven instance of {@code ReactProp} annotation
      abstract String customType() Type of property that will be send to JS.
      abstract double defaultDouble() Default value for property of type {@code double}.
      abstract float defaultFloat() Default value for property of type {@code float}.
      abstract int defaultInt() Default value for property of type {@code int}.
      abstract boolean defaultBoolean() Default value for property of type {@code boolean}.
      • Methods inherited from class java.lang.annotation.Annotation

        annotationType, equals, hashCode, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • name

         abstract String name()

        Name of the property exposed to JS that will be updated using setter method annotated with thegiven instance of {@code ReactProp} annotation

      • customType

        @Nullable() abstract String customType()

        Type of property that will be send to JS. In most of the cases {@code customType} should not beset in which case default type will be send to JS based on the type of value argument from thesetter method (e.g. for {@code int}, {@code double} default is "number", for {@code * ReadableArray} it's "Array"). Custom type may be used when additional processing of the valueneeds to be done in JS before sending it over the bridge. A good example of that would bebackgroundColor property, which is expressed as a {@code String} in JS, but we use {@code * processColor} JS module to convert it to {@code int} before sending over the bridge.

      • defaultDouble

         abstract double defaultDouble()

        Default value for property of type {@code double}. This value will be provided to propertysetter method annotated with ReactProp if property with a given name gets removed fromthe component description in JS

      • defaultFloat

         abstract float defaultFloat()

        Default value for property of type {@code float}. This value will be provided to propertysetter method annotated with ReactProp if property with a given name gets removed fromthe component description in JS

      • defaultInt

         abstract int defaultInt()

        Default value for property of type {@code int}. This value will be provided to property settermethod annotated with ReactProp if property with a given name gets removed from thecomponent description in JS

      • defaultBoolean

         abstract boolean defaultBoolean()

        Default value for property of type {@code boolean}. This value will be provided to propertysetter method annotated with ReactProp if property with a given name gets removed fromthe component description in JS