public class UIManagerModule extends ReactContextBaseJavaModule implements OnBatchCompleteListener, LifecycleEventListener, PerformanceCounter, UIManager
Native module to allow JS to create and update native Views.
To facilitate this, this module enqueues operations that are then applied to native view
hierarchy through NativeViewHierarchyManager
at the end of each transaction.
Modifier and Type | Class and Description |
---|---|
static interface |
UIManagerModule.CustomEventNamesResolver
Resolves a name coming from native side to a name of the event that is exposed to JS.
|
static interface |
UIManagerModule.ViewManagerResolver
Enables lazy discovery of a specific
ViewManager by its name. |
NativeModule.NativeMethod
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
NAME |
METHOD_TYPE_ASYNC, METHOD_TYPE_PROMISE, METHOD_TYPE_SYNC
Constructor and Description |
---|
UIManagerModule(ReactApplicationContext reactContext,
java.util.List<ViewManager> viewManagersList,
UIImplementationProvider uiImplementationProvider,
int minTimeLeftInFrameForNonBatchedOperationMs) |
UIManagerModule(ReactApplicationContext reactContext,
UIManagerModule.ViewManagerResolver viewManagerResolver,
UIImplementationProvider uiImplementationProvider,
int minTimeLeftInFrameForNonBatchedOperationMs) |
Modifier and Type | Method and Description |
---|---|
void |
addAnimation(int reactTag,
int animationID,
Callback onSuccess)
Adds an Animation previously registered with
registerAnimation(com.facebook.react.animation.Animation) to a View and starts it |
<T extends SizeMonitoringFrameLayout & MeasureSpecProvider> |
addRootView(T rootView)
Registers a new root view.
|
void |
addUIBlock(UIBlock block)
Schedule a block to be executed on the UI thread.
|
void |
addUIManagerListener(UIManagerModuleListener listener) |
void |
clearJSResponder() |
void |
configureNextLayoutAnimation(ReadableMap config,
Callback success,
Callback error)
Configure an animation to be used for the native layout changes, and native views
creation.
|
void |
createView(int tag,
java.lang.String className,
int rootViewTag,
ReadableMap props) |
void |
dispatchViewManagerCommand(int reactTag,
int commandId,
ReadableArray commandArgs) |
void |
findSubviewIn(int reactTag,
ReadableArray point,
Callback callback)
Find the touch target child native view in the supplied root view hierarchy, given a react
target location.
|
java.util.Map<java.lang.String,java.lang.Object> |
getConstants() |
WritableMap |
getConstantsForViewManager(java.lang.String viewManagerName) |
WritableMap |
getDefaultEventTypes() |
UIManagerModule.CustomEventNamesResolver |
getDirectEventNamesResolver()
Resolves Direct Event name exposed to JS from the one known to the Native side.
|
EventDispatcher |
getEventDispatcher() |
java.lang.String |
getName() |
java.util.Map<java.lang.String,java.lang.Long> |
getPerformanceCounters() |
UIImplementation |
getUIImplementation()
This method gives an access to the
UIImplementation object that can be used to execute
operations on the view hierarchy. |
void |
initialize()
This is called at the end of
CatalystApplicationFragment#createCatalystInstance()
after the CatalystInstance has been created, in order to initialize NativeModules that require
the CatalystInstance or JS modules. |
void |
invalidateNodeLayout(int tag)
Dirties the node associated with the given react tag
|
void |
manageChildren(int viewTag,
ReadableArray moveFrom,
ReadableArray moveTo,
ReadableArray addChildTags,
ReadableArray addAtIndices,
ReadableArray removeFrom)
Interface for adding/removing/moving views within a parent view from JS.
|
void |
measure(int reactTag,
Callback callback)
Determines the location on screen, width, and height of the given view and returns the values
via an async callback.
|
void |
measureInWindow(int reactTag,
Callback callback)
Determines the location on screen, width, and height of the given view relative to the device
screen and returns the values via an async callback.
|
void |
measureLayout(int tag,
int ancestorTag,
Callback errorCallback,
Callback successCallback)
Measures the view specified by tag relative to the given ancestorTag.
|
void |
measureLayoutRelativeToParent(int tag,
Callback errorCallback,
Callback successCallback)
Like
measure(int, com.facebook.react.bridge.Callback) and measureLayout(int, int, com.facebook.react.bridge.Callback, com.facebook.react.bridge.Callback) but measures relative to the immediate parent. |
void |
onBatchComplete()
To implement the transactional requirement mentioned in the class javadoc, we only commit
UI changes to the actual view hierarchy once a batch of JS->Java calls have been completed.
|
void |
onCatalystInstanceDestroy()
Called before {CatalystInstance#onHostDestroy}
|
void |
onHostDestroy()
Called when host activity receives destroy event (e.g.
|
void |
onHostPause()
Called when host activity receives pause event (e.g.
|
void |
onHostResume()
Called either when the host activity receives a resume event (e.g.
|
void |
prependUIBlock(UIBlock block)
Schedule a block to be executed on the UI thread.
|
void |
registerAnimation(Animation animation)
Registers a new Animation that can then be added to a View using
addAnimation(int, int, com.facebook.react.bridge.Callback) . |
void |
removeAnimation(int reactTag,
int animationID)
Removes an existing Animation, canceling it if it was in progress.
|
void |
removeRootView(int rootViewTag) |
void |
removeSubviewsFromContainerWithID(int containerTag)
Method which takes a container tag and then releases all subviews for that container upon
receipt.
|
void |
removeUIManagerListener(UIManagerModuleListener listener) |
void |
replaceExistingNonRootView(int oldTag,
int newTag)
Replaces the View specified by oldTag with the View specified by newTag within oldTag's parent.
|
int |
resolveRootTagFromReactTag(int reactTag)
Given a reactTag from a component, find its root node tag, if possible.
|
void |
sendAccessibilityEvent(int tag,
int eventType) |
void |
setChildren(int viewTag,
ReadableArray childrenTags)
Interface for fast tracking the initial adding of views.
|
void |
setJSResponder(int reactTag,
boolean blockNativeResponder) |
void |
setLayoutAnimationEnabledExperimental(boolean enabled)
LayoutAnimation API on Android is currently experimental.
|
void |
setViewHierarchyUpdateDebugListener(NotThreadSafeViewHierarchyUpdateDebugListener listener) |
void |
setViewLocalData(int tag,
java.lang.Object data)
Sets local data for a shadow node corresponded with given tag.
|
void |
showPopupMenu(int reactTag,
ReadableArray items,
Callback error,
Callback success)
Show a PopupMenu.
|
void |
updateNodeSize(int nodeViewTag,
int newWidth,
int newHeight) |
void |
updateRootLayoutSpecs(int rootViewTag,
int widthMeasureSpec,
int heightMeasureSpec)
Updates the styles of the
ReactShadowNode based on the Measure specs received by
parameters. |
void |
updateView(int tag,
java.lang.String className,
ReadableMap props) |
void |
viewIsDescendantOf(int reactTag,
int ancestorReactTag,
Callback callback)
Check if the first shadow node is the descendant of the second shadow node
|
getCurrentActivity, getReactApplicationContext
canOverrideExistingModule, hasConstants
protected static final java.lang.String NAME
public UIManagerModule(ReactApplicationContext reactContext, UIManagerModule.ViewManagerResolver viewManagerResolver, UIImplementationProvider uiImplementationProvider, int minTimeLeftInFrameForNonBatchedOperationMs)
public UIManagerModule(ReactApplicationContext reactContext, java.util.List<ViewManager> viewManagersList, UIImplementationProvider uiImplementationProvider, int minTimeLeftInFrameForNonBatchedOperationMs)
public UIImplementation getUIImplementation()
UIImplementation
object that can be used to execute
operations on the view hierarchy.public java.lang.String getName()
getName
in interface NativeModule
require()
this module
from javascript.public java.util.Map<java.lang.String,java.lang.Object> getConstants()
getConstants
in class BaseJavaModule
public void initialize()
NativeModule
CatalystApplicationFragment#createCatalystInstance()
after the CatalystInstance has been created, in order to initialize NativeModules that require
the CatalystInstance or JS modules.initialize
in interface NativeModule
initialize
in class BaseJavaModule
public void onHostResume()
LifecycleEventListener
Activity#onResume
or
if the native module that implements this is initialized while the host activity is already
resumed. Always called for the most current activity.onHostResume
in interface LifecycleEventListener
public void onHostPause()
LifecycleEventListener
Activity#onPause
. Always called
for the most current activity.onHostPause
in interface LifecycleEventListener
public void onHostDestroy()
LifecycleEventListener
Activity#onDestroy
. Only called
for the last React activity to be destroyed.onHostDestroy
in interface LifecycleEventListener
public void onCatalystInstanceDestroy()
NativeModule
onCatalystInstanceDestroy
in interface NativeModule
onCatalystInstanceDestroy
in class BaseJavaModule
@Nullable public WritableMap getConstantsForViewManager(java.lang.String viewManagerName)
public WritableMap getDefaultEventTypes()
public UIManagerModule.CustomEventNamesResolver getDirectEventNamesResolver()
public java.util.Map<java.lang.String,java.lang.Long> getPerformanceCounters()
getPerformanceCounters
in interface PerformanceCounter
public <T extends SizeMonitoringFrameLayout & MeasureSpecProvider> int addRootView(T rootView)
Note that this must be called after getWidth()/getHeight() actually return something. See CatalystApplicationFragment as an example.
TODO(6242243): Make addRootView thread safe NB: this method is horribly not-thread-safe.
addRootView
in interface UIManager
public void removeRootView(int rootViewTag)
public void updateNodeSize(int nodeViewTag, int newWidth, int newHeight)
public void setViewLocalData(int tag, java.lang.Object data)
localData
serves these needs.
For example, any stateful embedded native views may benefit from this.
Have in mind that this data is not supposed to interfere with the state of
the shadow view.
Please respect one-directional data flow of React.public void createView(int tag, java.lang.String className, int rootViewTag, ReadableMap props)
public void updateView(int tag, java.lang.String className, ReadableMap props)
public void manageChildren(int viewTag, @Nullable ReadableArray moveFrom, @Nullable ReadableArray moveTo, @Nullable ReadableArray addChildTags, @Nullable ReadableArray addAtIndices, @Nullable ReadableArray removeFrom)
viewTag
- the view tag of the parent viewmoveFrom
- a list of indices in the parent view to move views frommoveTo
- parallel to moveFrom, a list of indices in the parent view to move views toaddChildTags
- a list of tags of views to add to the parentaddAtIndices
- parallel to addChildTags, a list of indices to insert those children atremoveFrom
- a list of indices of views to permanently remove. The memory for the
corresponding views and data structures should be reclaimed.public void setChildren(int viewTag, ReadableArray childrenTags)
viewTag
- the view tag of the parent viewchildrenTags
- An array of tags to add to the parent in orderpublic void replaceExistingNonRootView(int oldTag, int newTag)
manageChildren(int, com.facebook.react.bridge.ReadableArray, com.facebook.react.bridge.ReadableArray, com.facebook.react.bridge.ReadableArray, com.facebook.react.bridge.ReadableArray, com.facebook.react.bridge.ReadableArray)
call, but React doesn't have enough info in
JS to formulate it itself.public void removeSubviewsFromContainerWithID(int containerTag)
containerTag
- the tag of the container for which the subviews must be removedpublic void measure(int reactTag, Callback callback)
public void measureInWindow(int reactTag, Callback callback)
public void measureLayout(int tag, int ancestorTag, Callback errorCallback, Callback successCallback)
measure(int, com.facebook.react.bridge.Callback)
, this will measure relative to the view layout, not the visible
window which can cause unexpected results when measuring relative to things like ScrollViews
that can have offset content on the screen.public void measureLayoutRelativeToParent(int tag, Callback errorCallback, Callback successCallback)
measure(int, com.facebook.react.bridge.Callback)
and measureLayout(int, int, com.facebook.react.bridge.Callback, com.facebook.react.bridge.Callback)
but measures relative to the immediate parent.
NB: Unlike measure(int, com.facebook.react.bridge.Callback)
, this will measure relative to the view layout, not the visible
window which can cause unexpected results when measuring relative to things like ScrollViews
that can have offset content on the screen.public void findSubviewIn(int reactTag, ReadableArray point, Callback callback)
reactTag
- the tag of the root view to traversepoint
- an array containing both X and Y target locationcallback
- will be called if with the identified child view react ID, and measurement
info. If no view was found, callback will be invoked with no data.public void viewIsDescendantOf(int reactTag, int ancestorReactTag, Callback callback)
public void registerAnimation(Animation animation)
addAnimation(int, int, com.facebook.react.bridge.Callback)
.public void addAnimation(int reactTag, int animationID, Callback onSuccess)
registerAnimation(com.facebook.react.animation.Animation)
to a View and starts itpublic void removeAnimation(int reactTag, int animationID)
public void setJSResponder(int reactTag, boolean blockNativeResponder)
public void clearJSResponder()
public void dispatchViewManagerCommand(int reactTag, int commandId, ReadableArray commandArgs)
public void showPopupMenu(int reactTag, ReadableArray items, Callback error, Callback success)
reactTag
- the tag of the anchor view (the PopupMenu is displayed next to this view); this
needs to be the tag of a native view (shadow views can not be anchors)items
- the menu items as an array of stringserror
- will be called if there is an error displaying the menusuccess
- will be called with the position of the selected item as the first argument, or
no arguments if the menu is dismissedpublic void setLayoutAnimationEnabledExperimental(boolean enabled)
enabled
- whether layout animation is enabled or notpublic void configureNextLayoutAnimation(ReadableMap config, Callback success, Callback error)
config
- the configuration of the animation for view addition/removal/update.success
- will be called when the animation completes, or when the animation get
interrupted. In this case, callback parameter will be false.error
- will be called if there was an error processing the animationpublic void onBatchComplete()
onBatchComplete
in interface OnBatchCompleteListener
public void setViewHierarchyUpdateDebugListener(@Nullable NotThreadSafeViewHierarchyUpdateDebugListener listener)
public EventDispatcher getEventDispatcher()
public void sendAccessibilityEvent(int tag, int eventType)
public void addUIBlock(UIBlock block)
block
- that contains UI logic you want to execute.
Usage Example:
UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class);
uiManager.addUIBlock(new UIBlock() {
public void execute (NativeViewHierarchyManager nvhm) {
View view = nvhm.resolveView(tag);
// ...execute your code on View (e.g. snapshot the view)
}
});public void prependUIBlock(UIBlock block)
block
- that contains UI logic you want to execute.public void addUIManagerListener(UIManagerModuleListener listener)
public void removeUIManagerListener(UIManagerModuleListener listener)
public int resolveRootTagFromReactTag(int reactTag)
reactTag
- the component tagpublic void invalidateNodeLayout(int tag)
public void updateRootLayoutSpecs(int rootViewTag, int widthMeasureSpec, int heightMeasureSpec)
ReactShadowNode
based on the Measure specs received by
parameters.