public class ReactShadowNode extends CSSNode
CSSNode to allow that. They also help with handling
Common base subclass of CSSNode for all layout nodes for react-based view. It extends
CSSNode by adding additional capabilities.
Instances of this class receive property updates from JS via @{link UIManagerModule}. Subclasses
may use updateProperties(com.facebook.react.uimanager.CatalystStylesDiffMap) to persist some of the updated fields in the node instance that
corresponds to a particular view type.
Subclasses of ReactShadowNode should be created only from ViewManager that
corresponds to a certain type of native view. They will be updated and accessed only from JS
thread. Subclasses of ViewManager may choose to use base class ReactShadowNode or
custom subclass of it if necessary.
The primary use-case for ReactShadowNode nodes is to calculate layouting. Although this
might be extended. For some examples please refer to ARTGroupCSSNode or ReactTextCSSNode.
This class allows for the native view hierarchy to not be an exact copy of the hierarchy received
from JS by keeping track of both JS children (e.g. CSSNode.getChildCount() and separately native
children (e.g. getNativeChildCount()). See NativeViewHierarchyOptimizer for more
information.CSSNode.MeasureFunction| Constructor and Description |
|---|
ReactShadowNode() |
| Modifier and Type | Method and Description |
|---|---|
void |
addChildAt(CSSNode child,
int i) |
void |
addNativeChildAt(ReactShadowNode child,
int nativeIndex)
Adds a child that the native view hierarchy will have at this index in the native view
corresponding to this node.
|
protected void |
dirty() |
ReactShadowNode |
getChildAt(int i) |
int |
getNativeChildCount() |
int |
getNativeOffsetForChild(ReactShadowNode child)
Returns the offset within the native children owned by all layout-only nodes in the subtree
rooted at this node for the given child.
|
ReactShadowNode |
getNativeParent() |
ReactShadowNode |
getParent() |
int |
getReactTag() |
ReactShadowNode |
getRootNode() |
int |
getScreenHeight() |
int |
getScreenWidth() |
int |
getScreenX() |
int |
getScreenY() |
ThemedReactContext |
getThemedContext()
Get the
ThemedReactContext associated with this ReactShadowNode. |
int |
getTotalNativeChildren() |
java.lang.String |
getViewClass() |
boolean |
hasUpdates() |
int |
indexOfNativeChild(ReactShadowNode nativeChild) |
boolean |
isLayoutOnly() |
boolean |
isVirtual()
Nodes that return
true will be treated as "virtual" nodes. |
boolean |
isVirtualAnchor()
Nodes that return
true will be treated as a root view for the virtual nodes tree. |
protected void |
markUpdated() |
void |
markUpdateSeen() |
void |
onBeforeLayout()
This method will be called by
UIManagerModule once per batch, before calculating
layout. |
void |
onCollectExtraUpdates(UIViewOperationQueue uiViewOperationQueue)
Called after layout step at the end of the UI batch from
UIManagerModule. |
ReactShadowNode |
removeChildAt(int i) |
ReactShadowNode |
removeNativeChildAt(int i) |
void |
setIsLayoutOnly(boolean isLayoutOnly)
Sets whether this node only contributes to the layout of its children without doing any
drawing or functionality itself.
|
protected void |
setThemedContext(ThemedReactContext themedContext) |
void |
updateProperties(CatalystStylesDiffMap styles) |
calculateLayout, getChildCount, getLayoutDirection, getLayoutHeight, getLayoutWidth, getLayoutX, getLayoutY, getStyleDirection, getStyleHeight, getStylePadding, getStyleWidth, hasNewLayout, indexOf, isDirty, isMeasureDefined, markLayoutSeen, setAlignItems, setAlignSelf, setBorder, setDefaultPadding, setDirection, setFlex, setFlexDirection, setJustifyContent, setMargin, setMeasureFunction, setPadding, setPositionBottom, setPositionLeft, setPositionRight, setPositionTop, setPositionType, setStyleHeight, setStyleWidth, setWrap, toString, valuesEqual, valuesEqualpublic boolean isVirtual()
true will be treated as "virtual" nodes. That is, nodes that are not
mapped into native views (e.g. nested text node). By default this method returns false.public boolean isVirtualAnchor()
true will be treated as a root view for the virtual nodes tree. It
means that NativeViewHierarchyManager will not try to perform manageChildren
operation on such views. Good example is InputText view that may have children
Text nodes but this whole hierarchy will be mapped to a single android EditText
view.public final java.lang.String getViewClass()
public final boolean hasUpdates()
public final void markUpdateSeen()
protected void markUpdated()
public void addChildAt(CSSNode child, int i)
addChildAt in class CSSNodepublic ReactShadowNode removeChildAt(int i)
removeChildAt in class CSSNodepublic void onBeforeLayout()
UIManagerModule once per batch, before calculating
layout. Will be only called for nodes that are marked as updated with markUpdated()
or require layouting (marked with dirty()).public void updateProperties(CatalystStylesDiffMap styles)
public void onCollectExtraUpdates(UIViewOperationQueue uiViewOperationQueue)
UIManagerModule. May be used
to enqueue additional ui operations for the native view. Will only be called on nodes marked
as updated either with dirty() or markUpdated().uiViewOperationQueue - interface for enqueueing UI operationspublic final int getReactTag()
public final ReactShadowNode getRootNode()
public final ReactShadowNode getChildAt(int i)
getChildAt in class CSSNode@Nullable public final ReactShadowNode getParent()
public ThemedReactContext getThemedContext()
ThemedReactContext associated with this ReactShadowNode. This will
never change during the lifetime of a ReactShadowNode instance, but different instances
can have different contexts; don't cache any calculations based on theme values globally.protected void setThemedContext(ThemedReactContext themedContext)
public void addNativeChildAt(ReactShadowNode child, int nativeIndex)
public ReactShadowNode removeNativeChildAt(int i)
public int getNativeChildCount()
public int indexOfNativeChild(ReactShadowNode nativeChild)
@Nullable public ReactShadowNode getNativeParent()
public void setIsLayoutOnly(boolean isLayoutOnly)
public boolean isLayoutOnly()
public int getTotalNativeChildren()
public int getNativeOffsetForChild(ReactShadowNode child)
NativeViewHierarchyOptimizer. Since those children will then add their native children
to this view, we now have ranges of native children that correspond to single unoptimized
children. The purpose of this method is to return the index within the native children that
corresponds to the **start** of the native children that belong to the given child. Also, note
that all of the children of a view might be optimized away, so this could return the same value
for multiple different children.
Example. Native children are represented by (N) where N is the no-opt child they came from. If
no children are optimized away it'd look like this: (0) (1) (2) (3) ... (n)
In case some children are optimized away, it might look like this:
(0) (1) (1) (1) (3) (3) (4)
In that case:
getNativeOffsetForChild(Node 0) => 0
getNativeOffsetForChild(Node 1) => 1
getNativeOffsetForChild(Node 2) => 4
getNativeOffsetForChild(Node 3) => 4
getNativeOffsetForChild(Node 4) => 6public int getScreenX()
public int getScreenY()
public int getScreenWidth()
public int getScreenHeight()