-
- 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 Summary
Modifier and Type Method Description void
updateProperties(@NonNull() T viewToUpdate, ReactStylesDiffMap props)
For the vast majority of ViewManagers, you will not need to override this. T
createView(int reactTag, @NonNull() ThemedReactContext reactContext, @Nullable() ReactStylesDiffMap props, @Nullable() StateWrapper stateWrapper, JSResponderHandler jsResponderHandler)
Creates a view with knowledge of props and state. abstract String
getName()
C
createShadowNodeInstance()
This method should return a subclass of ReactShadowNode which will be then used formeasuring position and size of the view. C
createShadowNodeInstance(@NonNull() ReactApplicationContext context)
abstract Class<out C>
getShadowNodeClass()
This method should return Class instance that represent type of shadow node that thismanager will return from createShadowNodeInstance. void
onDropViewInstance(@NonNull() T view)
Called when view is detached from view hierarchy and allows for some additional cleanup by the ViewManager subclass. 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 . void
receiveCommand(@NonNull() T root, int commandId, @Nullable() ReadableArray args)
Subclasses may use this method to receive events/commands directly from JS through the . void
receiveCommand(@NonNull() T root, String commandId, @Nullable() ReadableArray args)
Subclasses may use this method to receive events/commands directly from JS through the . 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. Map<String, Object>
getExportedCustomBubblingEventTypeConstants()
Returns a map of config data passed to JS that defines eligible events that can be placed onnative views. Map<String, Object>
getExportedCustomDirectEventTypeConstants()
Returns a map of config data passed to JS that defines eligible events that can be placed onnative views. Map<String, Object>
getExportedViewConstants()
Returns a map of view-specific constants that are injected to JavaScript. Map<String, String>
getNativeProps()
Returns a , representing the native props of the view manager. Object
updateState(@NonNull() T view, ReactStylesDiffMap props, @Nullable() StateWrapper stateWrapper)
Subclasses can implement this method to receive state updates shared between all instances ofthis component type. 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 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: measureSubclasses can override this method to implement custom measure functions for theViewManager 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. -
Methods inherited from class com.facebook.react.bridge.BaseJavaModule
canOverrideExistingModule, getConstants, hasConstants, initialize, invalidate, onCatalystInstanceDestroy
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
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.
-
createView
@NonNull() T createView(int reactTag, @NonNull() ThemedReactContext reactContext, @Nullable() ReactStylesDiffMap props, @Nullable() StateWrapper stateWrapper, JSResponderHandler jsResponderHandler)
Creates a view with knowledge of props and state.
-
createShadowNodeInstance
C createShadowNodeInstance()
This method should return a subclass of ReactShadowNode which will be then used formeasuring position and size of the view. In most of the cases this should just return aninstance of ReactShadowNode
-
createShadowNodeInstance
@NonNull() C createShadowNodeInstance(@NonNull() ReactApplicationContext context)
-
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.
-
onDropViewInstance
void onDropViewInstance(@NonNull() T view)
Called when view is detached from view hierarchy and allows for some additional cleanup by the ViewManager subclass.
-
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 commandcommandId
- code of the commandargs
- 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 commandcommandId
- code of the commandargs
- 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" } }
-
getExportedViewConstants
@Nullable() Map<String, Object> getExportedViewConstants()
Returns a map of view-specific constants that are injected to JavaScript. These constants aremade accessible via UIManager..Constants.
-
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.
-
updateState
@Nullable() Object updateState(@NonNull() T view, ReactStylesDiffMap props, @Nullable() StateWrapper stateWrapper)
Subclasses can implement this method to receive state updates shared between all instances ofthis component type.
-
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 propsstate
- ReadableMap containing state defined in C++width
- width of the view (usually zero)widthMode
- widthMode used during calculation of layoutheight
- height of the view (usually zero)heightMode
- widthMode used during calculation of layoutattachmentsPositions
- 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 propsstate
- MapBuffer containing state defined in C++width
- width of the view (usually zero)widthMode
- widthMode used during calculation of layoutheight
- height of the view (usually zero)heightMode
- widthMode used during calculation of layoutattachmentsPositions
- 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.
-
-
-
-