Package 

Class ViewManager

  • All Implemented Interfaces:
    com.facebook.react.bridge.NativeModule

    
    public abstract class ViewManager<T extends View, C extends ReactShadowNode>
    extends BaseJavaModule
                        

    Class responsible for knowing how to create and update catalyst Views of a given type. It is also responsible for creating and updating CSSNodeDEPRECATED subclasses used for calculating position and size for the corresponding native view.

    • Method Detail

      • updateProperties

         void updateProperties(@NonNull() T viewToUpdate, ReactStylesDiffMap props)

        For the vast majority of ViewManagers, you will not need to override this. Only override thisif you really know what you're doing and have a very unique use-case.

      • getShadowNodeClass

         abstract Class<out C> getShadowNodeClass()

        This method should return Class instance that represent type of shadow node that thismanager will return from createShadowNodeInstance.

        This method will be used in the bridge initialization phase to collect properties exposedusing ReactProp (or ReactPropGroup) annotation from the ReactShadowNode subclass specific for native view this manager provides.

      • updateExtraData

         abstract void updateExtraData(@NonNull() T root, Object extraData)

        Subclasses can implement this method to receive an optional extra data enqueued from thecorresponding instance of ReactShadowNode in .

        Since css layout step and ui updates can be executed in separate thread apart of settingx/y/width/height this is the recommended and thread-safe way of passing extra data from cssnode to the native view counterpart.

        TODO T7247021: Replace updateExtraData with generic update props mechanism after D2086999

      • receiveCommand

        @Deprecated() void receiveCommand(@NonNull() T root, int commandId, @Nullable() ReadableArray args)

        Subclasses may use this method to receive events/commands directly from JS through the . Good example of such a command would be {@code scrollTo} request with coordinatesfor a ScrollView instance.

        This method is deprecated use receiveCommand instead.

        Parameters:
        root - View instance that should receive the command
        commandId - code of the command
        args - optional arguments for the command
      • receiveCommand

         void receiveCommand(@NonNull() T root, String commandId, @Nullable() ReadableArray args)

        Subclasses may use this method to receive events/commands directly from JS through the . Good example of such a command would be {@code scrollTo} request with coordinatesfor a ReactScrollView instance.

        Parameters:
        root - View instance that should receive the command
        commandId - code of the command
        args - optional arguments for the command
      • getCommandsMap

        @Nullable() Map<String, Integer> getCommandsMap()

        Subclasses of ViewManager that expect to receive commands through should override this method returning the mapbetween names of the commands and IDs that are then used in receiveCommand methodwhenever the command is dispatched for this particular ViewManager.

      • getExportedCustomBubblingEventTypeConstants

        @Nullable() Map<String, Object> getExportedCustomBubblingEventTypeConstants()

        Returns a map of config data passed to JS that defines eligible events that can be placed onnative views. This should return bubbling directly-dispatched event types and specify whatnames should be used to subscribe to either form (bubbling/capturing).

        Returned map should be of the form:

        {
          "onTwirl": {
            "phasedRegistrationNames": {
              "bubbled": "onTwirl",
              "captured": "onTwirlCaptured"
            }
          }
        }
        
      • getExportedCustomDirectEventTypeConstants

        @Nullable() Map<String, Object> getExportedCustomDirectEventTypeConstants()

        Returns a map of config data passed to JS that defines eligible events that can be placed onnative views. This should return non-bubbling directly-dispatched event types.

        Returned map should be of the form:

        {
          "onTwirl": {
            "registrationName": "onTwirl"
          }
        }
        
      • getNativeProps

         Map<String, String> getNativeProps()

        Returns a , representing the native props of the view manager. TheMap contains the names (key) and types (value) of the ViewManager's props.

      • measure

         long measure(Context context, ReadableMap localData, ReadableMap props, ReadableMap state, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode, @Nullable() Array<float> attachmentsPositions)

        Subclasses can override this method to implement custom measure functions for the ViewManager

        Parameters:
        context - com.facebook.react.bridge.ReactContext used for the view.
        localData - ReadableMap containing "local data" defined in C++
        props - ReadableMap containing JS props
        state - ReadableMap containing state defined in C++
        width - width of the view (usually zero)
        widthMode - widthMode used during calculation of layout
        height - height of the view (usually zero)
        heightMode - widthMode used during calculation of layout
        attachmentsPositions - array containing 2x times the amount of attachmentsof the view.
      • measure

         long measure(Context context, MapBuffer localData, MapBuffer props, @Nullable() MapBuffer state, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode, @Nullable() Array<float> attachmentsPositions)

        THIS MEASURE METHOD IS EXPERIMENTAL, MOST LIKELY YOU ARE LOOKING TO USE THE OTHER OVERLOADINSTEAD: measure

        Subclasses can override this method to implement custom measure functions for theViewManager

        Parameters:
        context - com.facebook.react.bridge.ReactContext used for the view.
        localData - MapBuffer containing "local data" defined in C++
        props - MapBuffer containing JS props
        state - MapBuffer containing state defined in C++
        width - width of the view (usually zero)
        widthMode - widthMode used during calculation of layout
        height - height of the view (usually zero)
        heightMode - widthMode used during calculation of layout
        attachmentsPositions - array containing 2x times the amount of attachmentsof the view.
      • setPadding

         void setPadding(T view, int left, int top, int right, int bottom)

        Subclasses can override this method to set padding for the given View in Fabric. Since not allcomponents support setting padding, the default implementation of this method does nothing.