public class NativeViewHierarchyOptimizer
extends java.lang.Object
UIManagerModule
, which directly receives view commands from JS, and
UIViewOperationQueue
, which enqueues actual operations on the native view hierarchy. It
is able to take instructions from UIManagerModule and output instructions to the native view
hierarchy that achieve the same displayed UI but with fewer views.
Currently this class is only used to remove layout-only views, that is to say views that only
affect the positions of their children but do not draw anything themselves. These views are
fairly common because 1) containers are used to do layouting via flexbox and 2) the return of
each Component#render() call in JS must be exactly one view, which means views are often wrapped
in a unnecessary layer of hierarchy.
This optimization is implemented by keeping track of both the unoptimized JS hierarchy and the
optimized native hierarchy in ReactShadowNode
.
This optimization is important for view hierarchy depth (which can cause stack overflows during
view traversal for complex apps), memory usage, amount of time spent during GCs,
and time-to-display.
Some examples of the optimizations this class will do based on commands from JS:
- Create a view with only layout props: a description of that view is created as a
ReactShadowNode
in UIManagerModule, but this class will not output any commands to
create the view in the native view hierarchy.
- Update a layout-only view to have non-layout props: before issuing the updateShadowNode call
to the native view hierarchy, issue commands to create the view we optimized away move it into
the view hierarchy
- Manage the children of a view: multiple manageChildren calls for various parent views may be
issued to the native view hierarchy depending on where the views being added/removed are
attached in the optimized hierarchyConstructor and Description |
---|
NativeViewHierarchyOptimizer(UIViewOperationQueue uiViewOperationQueue,
com.facebook.react.uimanager.ShadowNodeRegistry shadowNodeRegistry) |
Modifier and Type | Method and Description |
---|---|
void |
handleCreateView(ReactShadowNode node,
ThemedReactContext themedContext,
ReactStylesDiffMap initialProps)
Handles a createView call.
|
void |
handleManageChildren(ReactShadowNode nodeToManage,
int[] indicesToRemove,
int[] tagsToRemove,
com.facebook.react.uimanager.ViewAtIndex[] viewsToAdd,
int[] tagsToDelete)
Handles a manageChildren call.
|
static void |
handleRemoveNode(ReactShadowNode node)
Handles native children cleanup when css node is removed from hierarchy
|
void |
handleSetChildren(ReactShadowNode nodeToManage,
ReadableArray childrenTags)
Handles a setChildren call.
|
void |
handleUpdateLayout(ReactShadowNode node)
Handles an updateLayout call.
|
void |
handleUpdateView(ReactShadowNode node,
java.lang.String className,
ReactStylesDiffMap props)
Handles an updateView call.
|
void |
onBatchComplete()
Processes the shadow hierarchy to dispatch all necessary updateLayout calls to the native
hierarchy.
|
public NativeViewHierarchyOptimizer(UIViewOperationQueue uiViewOperationQueue, com.facebook.react.uimanager.ShadowNodeRegistry shadowNodeRegistry)
public void handleCreateView(ReactShadowNode node, ThemedReactContext themedContext, @Nullable ReactStylesDiffMap initialProps)
public static void handleRemoveNode(ReactShadowNode node)
public void handleUpdateView(ReactShadowNode node, java.lang.String className, ReactStylesDiffMap props)
public void handleManageChildren(ReactShadowNode nodeToManage, int[] indicesToRemove, int[] tagsToRemove, com.facebook.react.uimanager.ViewAtIndex[] viewsToAdd, int[] tagsToDelete)
public void handleSetChildren(ReactShadowNode nodeToManage, ReadableArray childrenTags)
public void handleUpdateLayout(ReactShadowNode node)
public void onBatchComplete()