public class UIManagerModule extends ReactContextBaseJavaModule implements OnBatchCompleteListener, LifecycleEventListener, PerformanceCounter
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.
BaseJavaModule.JavaMethod, BaseJavaModule.SyncJavaHook
NativeModule.NativeMethod, NativeModule.SyncNativeHook
METHOD_TYPE_ASYNC, METHOD_TYPE_PROMISE, METHOD_TYPE_SYNC
Constructor and Description |
---|
UIManagerModule(ReactApplicationContext reactContext,
java.util.List<ViewManager> viewManagerList,
UIImplementation uiImplementation) |
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 |
int |
addMeasuredRootView(SizeMonitoringFrameLayout rootView)
Registers a new root view.
|
void |
addUIBlock(UIBlock block)
Schedule a block to be executed on the UI thread.
|
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() |
EventDispatcher |
getEventDispatcher() |
java.lang.String |
getName() |
java.util.Map<java.lang.String,java.lang.Double> |
getPerformanceCounters() |
UIImplementation |
getUIImplementation()
This method gives an access to the
UIImplementation object that can be used to execute
operations on the view hierarchy. |
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 when host activity receives resume event (e.g.
|
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 |
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 |
showPopupMenu(int reactTag,
ReadableArray items,
Callback error,
Callback success)
Show a PopupMenu.
|
void |
updateView(int tag,
java.lang.String className,
ReadableMap props) |
getCurrentActivity, getReactApplicationContext
canOverrideExistingModule, getMethods, getSyncHooks, initialize, onReactBridgeInitialized, supportsWebWorkers, writeConstantsField
public UIManagerModule(ReactApplicationContext reactContext, java.util.List<ViewManager> viewManagerList, UIImplementation uiImplementation)
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 onHostResume()
LifecycleEventListener
Activity#onResume
. 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
public java.util.Map<java.lang.String,java.lang.Double> getPerformanceCounters()
getPerformanceCounters
in interface PerformanceCounter
public int addMeasuredRootView(SizeMonitoringFrameLayout rootView)
public void removeRootView(int rootViewTag)
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 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 int resolveRootTagFromReactTag(int reactTag)
reactTag
- the component tag