public abstract class ViewManager<T extends android.view.View,C extends ReactShadowNode> extends BaseJavaModule
NativeModule.NativeMethod
METHOD_TYPE_ASYNC, METHOD_TYPE_PROMISE, METHOD_TYPE_SYNC
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.
|
C |
createShadowNodeInstance()
This method should return a subclass of
ReactShadowNode which will be then used for
measuring position and size of the view. |
C |
createShadowNodeInstance(ReactApplicationContext context) |
T |
createView(ThemedReactContext reactContext,
ReactStylesDiffMap props,
StateWrapper stateWrapper,
JSResponderHandler jsResponderHandler)
Creates a view with knowledge of props and state.
|
protected abstract T |
createViewInstance(ThemedReactContext reactContext)
Subclasses should return a new View instance of the proper type.
|
protected T |
createViewInstance(ThemedReactContext reactContext,
ReactStylesDiffMap initialProps,
StateWrapper stateWrapper)
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, com.facebook.react.bridge.Dynamic, 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 . |
protected ViewManagerDelegate<T> |
getDelegate()
Override this method and return an instance of
ViewManagerDelegate if the props of the
view managed by this view manager should be set via this delegate. |
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() . |
long |
measure(android.content.Context context,
ReadableMap localData,
ReadableMap props,
ReadableMap state,
float width,
YogaMeasureMode widthMode,
float height,
YogaMeasureMode heightMode,
int[] attachmentsPositions)
Subclasses can override this method to implement custom measure functions for the ViewManager
|
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)
Deprecated.
|
void |
receiveCommand(T root,
java.lang.String commandId,
ReadableArray args)
Subclasses may use this method to receive events/commands directly from JS through the
UIManager . |
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.
|
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) . |
java.lang.Object |
updateLocalData(T view,
ReactStylesDiffMap props,
ReactStylesDiffMap localData) |
void |
updateProperties(T viewToUpdate,
ReactStylesDiffMap props)
For the vast majority of ViewManagers, you will not need to override this.
|
java.lang.Object |
updateState(T view,
ReactStylesDiffMap props,
StateWrapper stateWrapper)
Subclasses can implement this method to receive state updates shared between all instances of
this component type.
|
canOverrideExistingModule, getConstants, hasConstants, initialize, invalidate, onCatalystInstanceDestroy
public void updateProperties(T viewToUpdate, ReactStylesDiffMap props)
viewToUpdate
- props
- stateWrapper
- protected ViewManagerDelegate<T> getDelegate()
ViewManagerDelegate
if the props of the
view managed by this view manager should be set via this delegate. The provided instance will
then get calls to ViewManagerDelegate.setProperty(View, String, Object)
for every prop
that must be updated and it's the delegate's responsibility to apply these values to the view.
By default this method returns null
, which means that the view manager doesn't have
a delegate and the view props should be set internally by the view manager itself.
ViewManagerDelegate
if the props of the view managed by this
view manager should be set via this delegatepublic T createView(ThemedReactContext reactContext, ReactStylesDiffMap props, StateWrapper stateWrapper, JSResponderHandler jsResponderHandler)
public abstract java.lang.String getName()
public C createShadowNodeInstance()
ReactShadowNode
which will be then used for
measuring position and size of the view. In most of the cases this should just return an
instance of ReactShadowNode
public C createShadowNodeInstance(ReactApplicationContext context)
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
- protected T createViewInstance(ThemedReactContext reactContext, ReactStylesDiffMap initialProps, StateWrapper stateWrapper)
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 T7247021: Replace updateExtraData with generic update props mechanism after D2086999
@Deprecated public void receiveCommand(T root, int commandId, ReadableArray args)
UIManager
. Good example of such a command would be scrollTo
request with coordinates
for a ScrollView
instance.
This method is deprecated use receiveCommand(View, String, ReadableArray)
instead.
root
- View instance that should receive the commandcommandId
- code of the commandargs
- optional arguments for the commandpublic void receiveCommand(T root, java.lang.String commandId, ReadableArray args)
UIManager
. Good example of such a command would be scrollTo
request with coordinates
for a ReactScrollView
instance.root
- View instance that should receive the commandcommandId
- code of the commandargs
- optional arguments for the commandpublic java.util.Map<java.lang.String,java.lang.Integer> getCommandsMap()
ViewManager
that expect to receive commands through UIManagerModule.dispatchViewManagerCommand(int, com.facebook.react.bridge.Dynamic, 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
.public java.util.Map<java.lang.String,java.lang.Object> getExportedCustomBubblingEventTypeConstants()
Returned map should be of the form:
{ "onTwirl": { "phasedRegistrationNames": { "bubbled": "onTwirl", "captured": "onTwirlCaptured" } } }
public java.util.Map<java.lang.String,java.lang.Object> getExportedCustomDirectEventTypeConstants()
Returned map should be of the form:
{ "onTwirl": { "registrationName": "onTwirl" } }
public java.util.Map<java.lang.String,java.lang.Object> getExportedViewConstants()
public java.util.Map<java.lang.String,java.lang.String> getNativeProps()
public java.lang.Object updateLocalData(T view, ReactStylesDiffMap props, ReactStylesDiffMap localData)
public java.lang.Object updateState(T view, ReactStylesDiffMap props, StateWrapper stateWrapper)
public long measure(android.content.Context context, ReadableMap localData, ReadableMap props, ReadableMap state, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode, int[] attachmentsPositions)
context
- 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
- int[]
array containing 2x times the amount of attachments
of the view. An attachment represents the position of an inline view that needs to be
rendered inside a component and it requires the content of the parent view in order to be
positioned. This array is meant to be used by the platform to RETURN the position of each
attachment, as a result of the calculation of layout. (e.g. this array is used to measure
inlineViews that are rendered inside Text components). On most of the components this array
will be contain a null value.
Even values will represent the TOP of each attachment, Odd values represent the LEFT of each attachment.
public void setPadding(T view, int left, int top, int right, int bottom)