public abstract class ViewManager<T extends android.view.View,C extends ReactShadowNode>
extends java.lang.Object
Constructor and Description |
---|
ViewManager() |
Modifier and Type | Method and Description |
---|---|
protected void |
addEventEmitters(ThemedReactContext reactContext,
T view)
Subclasses can override this method to install custom event emitters on the given View.
|
abstract C |
createShadowNodeInstance()
This method should return a subclass of
ReactShadowNode which will be then used for
measuring position and size of the view. |
T |
createView(ThemedReactContext reactContext,
JSResponderHandler jsResponderHandler)
Creates a view and installs event emitters on it.
|
protected abstract T |
createViewInstance(ThemedReactContext reactContext)
Subclasses should return a new View instance of the proper type.
|
java.util.Map<java.lang.String,java.lang.Integer> |
getCommandsMap()
Subclasses of
ViewManager that expect to receive commands through
UIManagerModule.dispatchViewManagerCommand(int, int, com.facebook.react.bridge.ReadableArray) should override this method returning the
map between names of the commands and IDs that are then used in receiveCommand(T, int, com.facebook.react.bridge.ReadableArray) method
whenever the command is dispatched for this particular ViewManager . |
java.util.Map<java.lang.String,java.lang.Object> |
getExportedCustomBubblingEventTypeConstants()
Returns a map of config data passed to JS that defines eligible events that can be placed on
native views.
|
java.util.Map<java.lang.String,java.lang.Object> |
getExportedCustomDirectEventTypeConstants()
Returns a map of config data passed to JS that defines eligible events that can be placed on
native views.
|
java.util.Map<java.lang.String,java.lang.Object> |
getExportedViewConstants()
Returns a map of view-specific constants that are injected to JavaScript.
|
abstract java.lang.String |
getName() |
java.util.Map<java.lang.String,java.lang.String> |
getNativeProps() |
abstract java.lang.Class<? extends C> |
getShadowNodeClass()
This method should return
Class instance that represent type of shadow node that this
manager will return from createShadowNodeInstance() . |
protected void |
onAfterUpdateTransaction(T view)
Callback that will be triggered after all properties are updated in current update transaction
(all @ReactProp handlers for properties updated in current transaction have been called).
|
void |
onDropViewInstance(T view)
Called when view is detached from view hierarchy and allows for some additional cleanup by
the
ViewManager subclass. |
void |
receiveCommand(T root,
int commandId,
ReadableArray args)
Subclasses may use this method to receive events/commands directly from JS through the
UIManager . |
abstract void |
updateExtraData(T root,
java.lang.Object extraData)
Subclasses can implement this method to receive an optional extra data enqueued from the
corresponding instance of
ReactShadowNode in
ReactShadowNode.onCollectExtraUpdates(com.facebook.react.uimanager.UIViewOperationQueue) . |
void |
updateProperties(T viewToUpdate,
ReactStylesDiffMap props) |
public final void updateProperties(T viewToUpdate, ReactStylesDiffMap props)
public final T createView(ThemedReactContext reactContext, JSResponderHandler jsResponderHandler)
public abstract java.lang.String getName()
public abstract C createShadowNodeInstance()
ReactShadowNode
which will be then used for
measuring position and size of the view. In mose of the cases this should just return an
instance of ReactShadowNode
public abstract java.lang.Class<? extends C> getShadowNodeClass()
Class
instance that represent type of shadow node that this
manager will return from createShadowNodeInstance()
.
This method will be used in the bridge initialization phase to collect properties exposed using
ReactProp
(or ReactPropGroup
) annotation from the ReactShadowNode
subclass specific for native view this manager provides.Class
object that represents type of shadow node used by this view manager.protected abstract T createViewInstance(ThemedReactContext reactContext)
reactContext
- public void onDropViewInstance(T view)
ViewManager
subclass.protected void addEventEmitters(ThemedReactContext reactContext, T view)
protected void onAfterUpdateTransaction(T view)
public abstract void updateExtraData(T root, java.lang.Object extraData)
ReactShadowNode
in
ReactShadowNode.onCollectExtraUpdates(com.facebook.react.uimanager.UIViewOperationQueue)
.
Since css layout step and ui updates can be executed in separate thread apart of setting
x/y/width/height this is the recommended and thread-safe way of passing extra data from css
node to the native view counterpart.
TODO(7247021): Replace updateExtraData with generic update props mechanism after D2086999public void receiveCommand(T root, int commandId, @Nullable ReadableArray args)
UIManager
. Good example of such a command would be scrollTo
request with
coordinates for a ScrollView
or goBack
request for a WebView
instance.root
- View instance that should receive the commandcommandId
- code of the commandargs
- optional arguments for the command@Nullable public java.util.Map<java.lang.String,java.lang.Integer> getCommandsMap()
ViewManager
that expect to receive commands through
UIManagerModule.dispatchViewManagerCommand(int, int, com.facebook.react.bridge.ReadableArray)
should override this method returning the
map between names of the commands and IDs that are then used in receiveCommand(T, int, com.facebook.react.bridge.ReadableArray)
method
whenever the command is dispatched for this particular ViewManager
.
As an example we may consider ReactWebViewManager
that expose the following commands:
goBack, goForward, reload. In this case the map returned from getCommandsMap()
from
ReactWebViewManager
will look as follows:
{
"goBack": 1,
"goForward": 2,
"reload": 3,
}
Now assuming that "reload" command is dispatched through UIManagerModule
we trigger
ReactWebViewManager#receiveCommand
passing "3" as commandId
argument.@Nullable public java.util.Map<java.lang.String,java.lang.Object> getExportedCustomBubblingEventTypeConstants()
@Nullable public java.util.Map<java.lang.String,java.lang.Object> getExportedCustomDirectEventTypeConstants()
@Nullable public java.util.Map<java.lang.String,java.lang.Object> getExportedViewConstants()
public java.util.Map<java.lang.String,java.lang.String> getNativeProps()