-
- All Implemented Interfaces:
-
com.facebook.react.bridge.JSIModule
,com.facebook.react.bridge.LifecycleEventListener
,com.facebook.react.bridge.NativeModule
,com.facebook.react.bridge.OnBatchCompleteListener
,com.facebook.react.bridge.PerformanceCounter
,com.facebook.react.bridge.UIManager
public class UIManagerModule extends ReactContextBaseJavaModule implements OnBatchCompleteListener, LifecycleEventListener, UIManager
Native module to allow JS to create and update native Views.
== Transactional Requirement ==A requirement of this class is to make sure that transactional UI updates occur all at once, meaning that no intermediate state is ever rendered to the screen. For example, if a JS application update changes the background of View A to blue and the width of View B to 100, both need to appear at once. Practically, this means that all UI update code related to a single transaction must be executed as a single code block on the UI thread. Executing as multiple code blocks could allow the platform UI system to interrupt and render a partial UI state.To facilitate this, this module enqueues operations that are then applied to native view hierarchy through NativeViewHierarchyManager at the end of each transaction.
== CSSNodes ==In order to allow layout and measurement to occur on a non-UI thread, this module also operates on intermediate CSSNodeDEPRECATED objects that correspond to a native view. These CSSNodeDEPRECATED are able to calculate layout according to their styling rules, and then the resulting x/y/width/height of that layout is scheduled as an operation that will be applied to native view hierarchy at the end of current batch. TODO(5241856): Investigate memory usage of creating many small objects in UIManageModule and consider implementing a pool TODO(5483063): Don't dispatch the view hierarchy at the end of a batch if no UI changes occurred
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interface
UIManagerModule.CustomEventNamesResolver
Resolves a name coming from native side to a name of the event that is exposed to JS.
-
Constructor Summary
Constructors Constructor Description UIManagerModule(ReactApplicationContext reactContext, ViewManagerResolver viewManagerResolver, int minTimeLeftInFrameForNonBatchedOperationMs)
UIManagerModule(ReactApplicationContext reactContext, List<ViewManager> viewManagersList, int minTimeLeftInFrameForNonBatchedOperationMs)
UIManagerModule(ReactApplicationContext reactContext, ViewManagerResolver viewManagerResolver, UIImplementationProvider uiImplementationProvider, int minTimeLeftInFrameForNonBatchedOperationMs)
UIManagerModule(ReactApplicationContext reactContext, List<ViewManager> viewManagersList, UIImplementationProvider uiImplementationProvider, int minTimeLeftInFrameForNonBatchedOperationMs)
-
Method Summary
Modifier and Type Method Description UIImplementation
getUIImplementation()
This method gives an access to the UIImplementation object that can be used to executeoperations on the view hierarchy. String
getName()
Map<String, Object>
getConstants()
void
initialize()
This is called at the end of createCatalystInstance afterthe CatalystInstance has been created, in order to initialize NativeModules that require theCatalystInstance or JS modules. void
onHostResume()
Called either when the host activity receives a resume event (e.g. void
onHostPause()
Called when host activity receives pause event (e.g. void
onHostDestroy()
Called when host activity receives destroy event (e.g. void
onCatalystInstanceDestroy()
Allow NativeModule to clean up. ViewManagerRegistry
getViewManagerRegistry_DO_NOT_USE()
This method is intended to reuse the ViewManagerRegistry with FabricUIManager. void
preInitializeViewManagers(List<String> viewManagerNames)
Helper method to pre-compute the constants for a view manager. WritableMap
getConstantsForViewManager(@Nullable() String viewManagerName)
WritableMap
getDefaultEventTypes()
UIManagerModule.CustomEventNamesResolver
getDirectEventNamesResolver()
Resolves Direct Event name exposed to JS from the one known to the Native side. String
resolveCustomDirectEventName(@Nullable() String eventName)
Resolves Direct Event name exposed to JS from the one known to the Native side. void
profileNextBatch()
Map<String, Long>
getPerformanceCounters()
<T extends View> int
addRootView(T rootView)
void
synchronouslyUpdateViewOnUIThread(int tag, ReadableMap props)
Used by native animated module to bypass the process of updating the values through the shadowview hierarchy. <T extends View> int
addRootView(T rootView, WritableMap initialProps, @Nullable() String initialUITemplate)
Registers a new root view. <T extends View> int
startSurface(T rootView, String moduleName, WritableMap initialProps, int widthMeasureSpec, int heightMeasureSpec)
Registers a new root view with width and height. void
stopSurface(int surfaceId)
Stop a surface from running in JS and clears up native memory usage. void
removeRootView(int rootViewTag)
Unregisters a new root view. void
updateNodeSize(int nodeViewTag, int newWidth, int newHeight)
void
setViewLocalData(int tag, Object data)
Sets local data for a shadow node corresponded with given tag. void
createView(int tag, String className, int rootViewTag, ReadableMap props)
void
updateView(int tag, String className, ReadableMap props)
void
manageChildren(int viewTag, @Nullable() ReadableArray moveFrom, @Nullable() ReadableArray moveTo, @Nullable() ReadableArray addChildTags, @Nullable() ReadableArray addAtIndices, @Nullable() ReadableArray removeFrom)
Interface for adding/removing/moving views within a parent view from JS. void
setChildren(int viewTag, ReadableArray childrenTags)
Interface for fast tracking the initial adding of views. void
replaceExistingNonRootView(int oldTag, int newTag)
Replaces the View specified by oldTag with the View specified by newTag within oldTag's parent. void
removeSubviewsFromContainerWithID(int containerTag)
Method which takes a container tag and then releases all subviews for that container uponreceipt. void
measure(int reactTag, Callback callback)
Determines the location on screen, width, and height of the given view and returns the valuesvia an async callback. void
measureInWindow(int reactTag, Callback callback)
Determines the location on screen, width, and height of the given view relative to the devicescreen 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 and measureLayout but measures relative to the immediate parent. void
findSubviewIn(int reactTag, ReadableArray point, Callback callback)
Find the touch target child native view in the supplied root view hierarchy, given a reacttarget location. void
viewIsDescendantOf(int reactTag, int ancestorReactTag, Callback callback)
Check if the first shadow node is the descendant of the second shadow node void
setJSResponder(int reactTag, boolean blockNativeResponder)
void
clearJSResponder()
void
dispatchViewManagerCommand(int reactTag, Dynamic commandId, @Nullable() ReadableArray commandArgs)
void
dispatchCommand(int reactTag, int commandId, @Nullable() ReadableArray commandArgs)
Deprecated, use dispatchCommand instead. void
dispatchCommand(int reactTag, String commandId, @Nullable() ReadableArray commandArgs)
Dispatches the commandId received by parameter to the view associated with the reactTag. void
showPopupMenu(int reactTag, ReadableArray items, Callback error, Callback success)
Show a PopupMenu. void
dismissPopupMenu()
void
setLayoutAnimationEnabledExperimental(boolean enabled)
LayoutAnimation API on Android is currently experimental. void
configureNextLayoutAnimation(ReadableMap config, Callback success, Callback error)
Configure an animation to be used for the native layout changes, and native views creation. void
onBatchComplete()
To implement the transactional requirement mentioned in the class javadoc, we only commit UIchanges to the actual view hierarchy once a batch of JS->Java calls have been completed. void
setViewHierarchyUpdateDebugListener(@Nullable() NotThreadSafeViewHierarchyUpdateDebugListener listener)
EventDispatcher
getEventDispatcher()
void
sendAccessibilityEvent(int tag, int eventType)
Dispatch an accessibility event to a view asynchronously. void
addUIBlock(UIBlock block)
Schedule a block to be executed on the UI thread. void
prependUIBlock(UIBlock block)
Schedule a block to be executed on the UI thread. void
addUIManagerListener(UIManagerModuleListener listener)
void
removeUIManagerListener(UIManagerModuleListener listener)
void
addUIManagerEventListener(UIManagerListener listener)
Register a UIManagerListener with this UIManager to receive lifecycle callbacks. void
removeUIManagerEventListener(UIManagerListener listener)
Unregister a UIManagerListener from this UIManager to stop receiving lifecyclecallbacks. int
resolveRootTagFromReactTag(int reactTag)
Given a reactTag from a component, find its root node tag, if possible. void
invalidateNodeLayout(int tag)
Dirties the node associated with the given react tag void
updateRootLayoutSpecs(int rootViewTag, int widthMeasureSpec, int heightMeasureSpec, int offsetX, int offsetY)
Updates the styles of the ReactShadowNode based on the Measure specs received byparameters. View
resolveView(int tag)
Resolves a view based on its reactTag. void
receiveEvent(int reactTag, String eventName, @Nullable() WritableMap event)
This method dispatches events from RN Android code to JS. void
receiveEvent(int surfaceId, int reactTag, String eventName, @Nullable() WritableMap event)
This method dispatches events from RN Android code to JS. -
Methods inherited from class com.facebook.react.bridge.BaseJavaModule
canOverrideExistingModule, hasConstants, invalidate
-
Methods inherited from class com.facebook.react.bridge.UIManager
getEventDispatcher, receiveEvent, resolveView, sendAccessibilityEvent, synchronouslyUpdateViewOnUIThread, updateRootLayoutSpecs
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
UIManagerModule
UIManagerModule(ReactApplicationContext reactContext, ViewManagerResolver viewManagerResolver, int minTimeLeftInFrameForNonBatchedOperationMs)
-
UIManagerModule
UIManagerModule(ReactApplicationContext reactContext, List<ViewManager> viewManagersList, int minTimeLeftInFrameForNonBatchedOperationMs)
-
UIManagerModule
UIManagerModule(ReactApplicationContext reactContext, ViewManagerResolver viewManagerResolver, UIImplementationProvider uiImplementationProvider, int minTimeLeftInFrameForNonBatchedOperationMs)
-
UIManagerModule
UIManagerModule(ReactApplicationContext reactContext, List<ViewManager> viewManagersList, UIImplementationProvider uiImplementationProvider, int minTimeLeftInFrameForNonBatchedOperationMs)
-
-
Method Detail
-
getUIImplementation
@Deprecated() UIImplementation getUIImplementation()
This method gives an access to the UIImplementation object that can be used to executeoperations on the view hierarchy.
-
getConstants
Map<String, Object> getConstants()
-
initialize
void initialize()
This is called at the end of createCatalystInstance afterthe CatalystInstance has been created, in order to initialize NativeModules that require theCatalystInstance or JS modules.
-
onHostResume
void onHostResume()
Called either when the host activity receives a resume event (e.g. onResume orif the native module that implements this is initialized while the host activity is alreadyresumed. Always called for the most current activity.
-
onHostPause
void onHostPause()
Called when host activity receives pause event (e.g. onPause. Always calledfor the most current activity.
-
onHostDestroy
void onHostDestroy()
Called when host activity receives destroy event (e.g. onDestroy. Only calledfor the last React activity to be destroyed.
-
onCatalystInstanceDestroy
void onCatalystInstanceDestroy()
Allow NativeModule to clean up. Called before {CatalystInstance#onHostDestroy}
-
getViewManagerRegistry_DO_NOT_USE
@Deprecated() ViewManagerRegistry getViewManagerRegistry_DO_NOT_USE()
This method is intended to reuse the ViewManagerRegistry with FabricUIManager. Do notuse this method as this will be removed in the near future.
-
preInitializeViewManagers
@Deprecated() void preInitializeViewManagers(List<String> viewManagerNames)
Helper method to pre-compute the constants for a view manager. This method ensures that wedon't block for getting the constants for view managers during TTI
- Parameters:
viewManagerNames
- < names of ViewManagers
-
getConstantsForViewManager
@Nullable() WritableMap getConstantsForViewManager(@Nullable() String viewManagerName)
-
getDefaultEventTypes
WritableMap getDefaultEventTypes()
-
getDirectEventNamesResolver
@Deprecated() UIManagerModule.CustomEventNamesResolver getDirectEventNamesResolver()
Resolves Direct Event name exposed to JS from the one known to the Native side.
-
resolveCustomDirectEventName
@Deprecated()@Nullable() String resolveCustomDirectEventName(@Nullable() String eventName)
Resolves Direct Event name exposed to JS from the one known to the Native side.
-
profileNextBatch
void profileNextBatch()
-
getPerformanceCounters
Map<String, Long> getPerformanceCounters()
-
addRootView
<T extends View> int addRootView(T rootView)
-
synchronouslyUpdateViewOnUIThread
void synchronouslyUpdateViewOnUIThread(int tag, ReadableMap props)
Used by native animated module to bypass the process of updating the values through the shadowview hierarchy. This method will directly update native views, which means that updates forlayout-related propertied won't be handled properly. Make sure you know what you're doingbefore calling this method :)
-
addRootView
<T extends View> int addRootView(T rootView, WritableMap initialProps, @Nullable() String initialUITemplate)
Registers a new root view. JS can use the returned tag with manageChildren to add/removechildren to this view.
Calling addRootView through UIManagerModule calls addRootView in the non-Fabric renderer,always. This is deprecated in favor of calling startSurface in Fabric, which must be donedirectly through the FabricUIManager.
Note that this must be called after getWidth()/getHeight() actually return something. SeeCatalystApplicationFragment as an example.
TODO(6242243): Make addRootView thread safe NB: this method is horribly not-thread-safe.
-
startSurface
<T extends View> int startSurface(T rootView, String moduleName, WritableMap initialProps, int widthMeasureSpec, int heightMeasureSpec)
Registers a new root view with width and height.
-
stopSurface
void stopSurface(int surfaceId)
Stop a surface from running in JS and clears up native memory usage. Assumes that the nativeView hierarchy has already been cleaned up. Fabric-only.
-
removeRootView
void removeRootView(int rootViewTag)
Unregisters a new root view.
-
updateNodeSize
void updateNodeSize(int nodeViewTag, int newWidth, int newHeight)
-
setViewLocalData
void setViewLocalData(int tag, Object data)
Sets local data for a shadow node corresponded with given tag. In some cases we need a way tospecify some environmental data to shadow node to improve layout (or do something similar), so
{@code localData}
serves these needs. For example, any stateful embedded native views maybenefit from this. Have in mind that this data is not supposed to interfere with the state ofthe shadow view. Please respect one-directional data flow of React.
-
createView
void createView(int tag, String className, int rootViewTag, ReadableMap props)
-
updateView
void updateView(int tag, String className, ReadableMap props)
-
manageChildren
void manageChildren(int viewTag, @Nullable() ReadableArray moveFrom, @Nullable() ReadableArray moveTo, @Nullable() ReadableArray addChildTags, @Nullable() ReadableArray addAtIndices, @Nullable() ReadableArray removeFrom)
Interface for adding/removing/moving views within a parent view from JS.
- Parameters:
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.
-
setChildren
void setChildren(int viewTag, ReadableArray childrenTags)
Interface for fast tracking the initial adding of views. Children view tags are assumed to bein order
- Parameters:
viewTag
- the view tag of the parent viewchildrenTags
- An array of tags to add to the parent in order
-
replaceExistingNonRootView
@Deprecated() void replaceExistingNonRootView(int oldTag, int newTag)
Replaces the View specified by oldTag with the View specified by newTag within oldTag's parent.This resolves to a simple manageChildren call, but React doesn't have enough info inJS to formulate it itself.
-
removeSubviewsFromContainerWithID
@Deprecated() void removeSubviewsFromContainerWithID(int containerTag)
Method which takes a container tag and then releases all subviews for that container uponreceipt.
- Parameters:
containerTag
- the tag of the container for which the subviews must be removed
-
measure
void measure(int reactTag, Callback callback)
Determines the location on screen, width, and height of the given view and returns the valuesvia an async callback.
-
measureInWindow
void measureInWindow(int reactTag, Callback callback)
Determines the location on screen, width, and height of the given view relative to the devicescreen and returns the values via an async callback. This is the absolute position includingthings like the status bar
-
measureLayout
void measureLayout(int tag, int ancestorTag, Callback errorCallback, Callback successCallback)
Measures the view specified by tag relative to the given ancestorTag. This means that thereturned x, y are relative to the origin x, y of the ancestor view. Results are stored in thegiven outputBuffer. We allow ancestor view and measured view to be the same, in which case theposition always will be (0, 0) and method will only measure the view dimensions.
NB: Unlike measure, this will measure relative to the view layout, not the visiblewindow which can cause unexpected results when measuring relative to things like ScrollViewsthat can have offset content on the screen.
-
measureLayoutRelativeToParent
@Deprecated() void measureLayoutRelativeToParent(int tag, Callback errorCallback, Callback successCallback)
Like measure and measureLayout but measures relative to the immediate parent.
NB: Unlike measure, this will measure relative to the view layout, not the visiblewindow which can cause unexpected results when measuring relative to things like ScrollViewsthat can have offset content on the screen.
-
findSubviewIn
void findSubviewIn(int reactTag, ReadableArray point, Callback callback)
Find the touch target child native view in the supplied root view hierarchy, given a reacttarget location.
This method is currently used only by Element Inspector DevTool.
- Parameters:
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 measurementinfo.
-
viewIsDescendantOf
@Deprecated() void viewIsDescendantOf(int reactTag, int ancestorReactTag, Callback callback)
Check if the first shadow node is the descendant of the second shadow node
-
setJSResponder
void setJSResponder(int reactTag, boolean blockNativeResponder)
-
clearJSResponder
void clearJSResponder()
-
dispatchViewManagerCommand
void dispatchViewManagerCommand(int reactTag, Dynamic commandId, @Nullable() ReadableArray commandArgs)
-
dispatchCommand
@Deprecated() void dispatchCommand(int reactTag, int commandId, @Nullable() ReadableArray commandArgs)
Deprecated, use dispatchCommand instead.
-
dispatchCommand
void dispatchCommand(int reactTag, String commandId, @Nullable() ReadableArray commandArgs)
Dispatches the commandId received by parameter to the view associated with the reactTag. Thecommand will be processed in the UIThread.
Pre-Fabric, this is only called on the Native Module Thread.
- Parameters:
reactTag
- that identifies the view that will receive this commandcommandId
- String command idcommandArgs
- ReadableArray parameters associated with the command
-
showPopupMenu
void showPopupMenu(int reactTag, ReadableArray items, Callback error, Callback success)
Show a PopupMenu.
- Parameters:
reactTag
- the tag of the anchor view (the PopupMenu is displayed next to this view); thisneeds 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, orno arguments if the menu is dismissed
-
dismissPopupMenu
void dismissPopupMenu()
-
setLayoutAnimationEnabledExperimental
void setLayoutAnimationEnabledExperimental(boolean enabled)
LayoutAnimation API on Android is currently experimental. Therefore, it needs to be enabledexplicitly in order to avoid regression in existing application written for iOS using this API.
Warning : This method will be removed in future version of React Native, and layoutanimation will be enabled by default, so always check for its existence before invoking it.
TODO(9139831) : remove this method once layout animation is fully stable.
- Parameters:
enabled
- whether layout animation is enabled or not
-
configureNextLayoutAnimation
void configureNextLayoutAnimation(ReadableMap config, Callback success, Callback error)
Configure an animation to be used for the native layout changes, and native views creation. Theanimation will only apply during the current batch operations.
TODO(7728153) : animating view deletion is currently not supported.
- Parameters:
config
- the configuration of the animation for view addition/removal/update.success
- will be called when the animation completes, or when the animation getinterrupted.error
- will be called if there was an error processing the animation
-
onBatchComplete
void onBatchComplete()
To implement the transactional requirement mentioned in the class javadoc, we only commit UIchanges to the actual view hierarchy once a batch of JS->Java calls have been completed. Weknow this is safe because all JS->Java calls that are triggered by a Java->JS call (e.g. thedelivery of a touch event or execution of 'renderApplication') end up in a single JS->Javatransaction.
A better way to do this would be to have JS explicitly signal to this module when a UItransaction is done. Right now, though, this is how iOS does it, and we should probably updatethe JS and native code and make this change at the same time.
TODO(5279396): Make JS UI library explicitly notify the native UI module of the end of a UItransaction using a standard native call
-
setViewHierarchyUpdateDebugListener
void setViewHierarchyUpdateDebugListener(@Nullable() NotThreadSafeViewHierarchyUpdateDebugListener listener)
-
getEventDispatcher
EventDispatcher getEventDispatcher()
-
sendAccessibilityEvent
void sendAccessibilityEvent(int tag, int eventType)
Dispatch an accessibility event to a view asynchronously.
Pre-Fabric, this is only called on the Native Module Thread.
-
addUIBlock
void addUIBlock(UIBlock block)
Schedule a block to be executed on the UI thread. Useful if you need to execute view logicafter all currently queued view updates have completed.
- Parameters:
block
- that contains UI logic you want to execute.
-
prependUIBlock
void prependUIBlock(UIBlock block)
Schedule a block to be executed on the UI thread. Useful if you need to execute view logicbefore all currently queued view updates have completed.
- Parameters:
block
- that contains UI logic you want to execute.
-
addUIManagerListener
@Deprecated() void addUIManagerListener(UIManagerModuleListener listener)
-
removeUIManagerListener
@Deprecated() void removeUIManagerListener(UIManagerModuleListener listener)
-
addUIManagerEventListener
void addUIManagerEventListener(UIManagerListener listener)
Register a UIManagerListener with this UIManager to receive lifecycle callbacks.
-
removeUIManagerEventListener
void removeUIManagerEventListener(UIManagerListener listener)
Unregister a UIManagerListener from this UIManager to stop receiving lifecyclecallbacks.
-
resolveRootTagFromReactTag
@Deprecated() int resolveRootTagFromReactTag(int reactTag)
Given a reactTag from a component, find its root node tag, if possible. Otherwise, this willreturn 0. If the reactTag belongs to a root node, this will return the same reactTag.
- Parameters:
reactTag
- the component tag
-
invalidateNodeLayout
void invalidateNodeLayout(int tag)
Dirties the node associated with the given react tag
-
updateRootLayoutSpecs
void updateRootLayoutSpecs(int rootViewTag, int widthMeasureSpec, int heightMeasureSpec, int offsetX, int offsetY)
Updates the styles of the ReactShadowNode based on the Measure specs received byparameters. offsetX and offsetY aren't used in non-Fabric, so they're ignored here.
-
resolveView
View resolveView(int tag)
Resolves a view based on its reactTag. Do not mutate properties on this view that are alreadymanaged by React, as there are no guarantees this changes will be preserved.
-
receiveEvent
void receiveEvent(int reactTag, String eventName, @Nullable() WritableMap event)
This method dispatches events from RN Android code to JS. The delivery of this event will notbe queued in EventDispatcher class.
- Parameters:
reactTag
- tageventName
- name of the eventevent
- parameters
-
receiveEvent
void receiveEvent(int surfaceId, int reactTag, String eventName, @Nullable() WritableMap event)
This method dispatches events from RN Android code to JS. The delivery of this event will notbe queued in EventDispatcher class.
- Parameters:
reactTag
- tageventName
- name of the eventevent
- parameters
-
-
-
-