-
- All Implemented Interfaces:
-
com.facebook.react.uimanager.ReactShadowNode
public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
Base node class for representing virtual tree of React nodes. Shadow nodes are used primarily for layouting therefore it extends YogaNode to allow that. They also help with handling Common base subclass of YogaNode for all layout nodes for react-based view. It extends YogaNode by adding additional capabilities.
Instances of this class receive property updates from JS via @{link UIManagerModule}. Subclasses may use updateShadowNode to persist some of the updated fields in the node instance that corresponds to a particular view type.
Subclasses of ReactShadowNodeImpl 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 or custom subclass of it if necessary.
The primary use-case for ReactShadowNodeImpl nodes is to calculate layouting. Although this might be extended. For some examples please refer to ARTGroupYogaNode or ReactTextYogaNode.
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. getChildCount and separately native children (e.g. getNativeChildCount). See for more information.
-
-
Constructor Summary
Constructors Constructor Description ReactShadowNodeImpl()
-
Method Summary
Modifier and Type Method Description boolean
isVirtual()
Nodes that return {@code true}
will be treated as "virtual" nodes.boolean
isVirtualAnchor()
Nodes that return {@code true}
will be treated as a root view for the virtual nodes tree.boolean
isYogaLeafNode()
Nodes that return {@code true}
will not manage (and and remove) child Yoga nodes.boolean
hoistNativeChildren()
When constructing the native tree, nodes that return {@code true}
will be treated as leaves.Instead of adding this view's native children as subviews of it, they will be added as subviewsof an ancestor.final String
getViewClass()
final boolean
hasUpdates()
final void
markUpdateSeen()
void
markUpdated()
final boolean
hasUnseenUpdates()
void
dirty()
final boolean
isDirty()
void
addChildAt(ReactShadowNodeImpl child, int i)
ReactShadowNodeImpl
removeChildAt(int i)
final int
getChildCount()
final ReactShadowNodeImpl
getChildAt(int i)
final int
indexOf(ReactShadowNodeImpl child)
void
removeAndDisposeAllChildren()
void
onBeforeLayout(NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer)
This method will be called by UIManagerModule once per batch, before calculatinglayout. final void
updateProperties(ReactStylesDiffMap props)
void
onAfterUpdateTransaction()
void
onCollectExtraUpdates(UIViewOperationQueue uiViewOperationQueue)
Called after layout step at the end of the UI batch from UIManagerModule. boolean
dispatchUpdates(float absoluteX, float absoluteY, UIViewOperationQueue uiViewOperationQueue, @Nullable() NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer)
final int
getReactTag()
void
setReactTag(int reactTag)
final int
getRootTag()
final void
setRootTag(int rootTag)
final void
setViewClassName(String viewClassName)
final ReactShadowNodeImpl
getParent()
final ReactShadowNodeImpl
getLayoutParent()
final void
setLayoutParent(@Nullable() ReactShadowNodeImpl layoutParent)
final ThemedReactContext
getThemedContext()
Get the ThemedReactContext associated with this ReactShadowNodeImpl. void
setThemedContext(ThemedReactContext themedContext)
final boolean
shouldNotifyOnLayout()
void
calculateLayout()
void
calculateLayout(float width, float height)
final boolean
hasNewLayout()
final void
markLayoutSeen()
final void
addNativeChildAt(ReactShadowNodeImpl child, int nativeIndex)
Adds a child that the native view hierarchy will have at this index in the native viewcorresponding to this node. final ReactShadowNodeImpl
removeNativeChildAt(int i)
final void
removeAllNativeChildren()
final int
getNativeChildCount()
final int
indexOfNativeChild(ReactShadowNodeImpl nativeChild)
final ReactShadowNodeImpl
getNativeParent()
final void
setIsLayoutOnly(boolean isLayoutOnly)
Sets whether this node only contributes to the layout of its children without doing any drawingor functionality itself. final boolean
isLayoutOnly()
NativeKind
getNativeKind()
final int
getTotalNativeChildren()
boolean
isDescendantOf(ReactShadowNodeImpl ancestorNode)
String
toString()
void
setLocalData(Object data)
final int
getNativeOffsetForChild(ReactShadowNodeImpl child)
Returns the offset within the native children owned by all layout-only nodes in the subtreerooted at this node for the given child. final float
getLayoutX()
final float
getLayoutY()
final float
getLayoutWidth()
final float
getLayoutHeight()
int
getScreenX()
int
getScreenY()
int
getScreenWidth()
int
getScreenHeight()
final YogaDirection
getLayoutDirection()
void
setLayoutDirection(YogaDirection direction)
final YogaValue
getStyleWidth()
void
setStyleWidth(float widthPx)
void
setStyleWidthPercent(float percent)
void
setStyleWidthAuto()
void
setStyleMinWidth(float widthPx)
void
setStyleMinWidthPercent(float percent)
void
setStyleMaxWidth(float widthPx)
void
setStyleMaxWidthPercent(float percent)
final YogaValue
getStyleHeight()
void
setStyleHeight(float heightPx)
void
setStyleHeightPercent(float percent)
void
setStyleHeightAuto()
void
setStyleMinHeight(float widthPx)
void
setStyleMinHeightPercent(float percent)
void
setStyleMaxHeight(float widthPx)
void
setStyleMaxHeightPercent(float percent)
float
getFlex()
void
setFlex(float flex)
void
setFlexGrow(float flexGrow)
void
setFlexShrink(float flexShrink)
void
setFlexBasis(float flexBasis)
void
setFlexBasisAuto()
void
setFlexBasisPercent(float percent)
void
setStyleAspectRatio(float aspectRatio)
void
setFlexDirection(YogaFlexDirection flexDirection)
void
setFlexWrap(YogaWrap wrap)
void
setAlignSelf(YogaAlign alignSelf)
void
setAlignItems(YogaAlign alignItems)
void
setAlignContent(YogaAlign alignContent)
void
setJustifyContent(YogaJustify justifyContent)
void
setOverflow(YogaOverflow overflow)
void
setDisplay(YogaDisplay display)
void
setMargin(int spacingType, float margin)
void
setMarginPercent(int spacingType, float percent)
void
setMarginAuto(int spacingType)
final float
getPadding(int spacingType)
final YogaValue
getStylePadding(int spacingType)
void
setDefaultPadding(int spacingType, float padding)
void
setPadding(int spacingType, float padding)
void
setPaddingPercent(int spacingType, float percent)
void
setBorder(int spacingType, float borderWidth)
void
setPosition(int spacingType, float position)
void
setPositionPercent(int spacingType, float percent)
void
setPositionType(YogaPositionType positionType)
void
setShouldNotifyOnLayout(boolean shouldNotifyOnLayout)
void
setBaselineFunction(YogaBaselineFunction baselineFunction)
void
setMeasureFunction(YogaMeasureFunction measureFunction)
boolean
isMeasureDefined()
String
getHierarchyInfo()
void
dispose()
void
setMeasureSpecs(int widthMeasureSpec, int heightMeasureSpec)
Integer
getWidthMeasureSpec()
Integer
getHeightMeasureSpec()
Iterable<out ReactShadowNode>
calculateLayoutOnChildren()
-
Methods inherited from class com.facebook.react.uimanager.ReactShadowNode
addChildAt, addNativeChildAt, dispatchUpdates, getChildAt, getLayoutParent, getNativeOffsetForChild, getNativeParent, getParent, indexOf, indexOfNativeChild, isDescendantOf, removeChildAt, removeNativeChildAt, setLayoutParent
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
isVirtual
boolean isVirtual()
Nodes that return
{@code true}
will be treated as "virtual" nodes. That is, nodes that are notmapped into native views or Yoga nodes (e.g. nested text node). By default this method returns{@code false}
.
-
isVirtualAnchor
boolean isVirtualAnchor()
Nodes that return
{@code true}
will be treated as a root view for the virtual nodes tree. Itmeans that all of its descendants will be "virtual" nodes. Good example is{@code InputText}
view that may have children{@code Text}
nodes but this whole hierarchy will be mapped to asingle android EditText view.
-
isYogaLeafNode
boolean isYogaLeafNode()
Nodes that return
{@code true}
will not manage (and and remove) child Yoga nodes. For example ReactTextInputShadowNode or ReactTextShadowNode have child nodes, which do notwant Yoga to lay out, so in the eyes of Yoga it is a leaf node. Override this method insubclass to enforce this requirement.
-
hoistNativeChildren
boolean hoistNativeChildren()
When constructing the native tree, nodes that return
{@code true}
will be treated as leaves.Instead of adding this view's native children as subviews of it, they will be added as subviewsof an ancestor. In other words, this view wants to support native children but it cannot hostthem itself (e.g. it isn't a ViewGroup).
-
getViewClass
final String getViewClass()
-
hasUpdates
final boolean hasUpdates()
-
markUpdateSeen
final void markUpdateSeen()
-
markUpdated
void markUpdated()
-
hasUnseenUpdates
final boolean hasUnseenUpdates()
-
dirty
void dirty()
-
isDirty
final boolean isDirty()
-
addChildAt
void addChildAt(ReactShadowNodeImpl child, int i)
-
removeChildAt
ReactShadowNodeImpl removeChildAt(int i)
-
getChildCount
final int getChildCount()
-
getChildAt
final ReactShadowNodeImpl getChildAt(int i)
-
indexOf
final int indexOf(ReactShadowNodeImpl child)
-
removeAndDisposeAllChildren
void removeAndDisposeAllChildren()
-
onBeforeLayout
void onBeforeLayout(NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer)
This method will be called by UIManagerModule once per batch, before calculatinglayout. Will be only called for nodes that are marked as updated with markUpdated orrequire layouting (marked with dirty).
-
updateProperties
final void updateProperties(ReactStylesDiffMap props)
-
onAfterUpdateTransaction
void onAfterUpdateTransaction()
-
onCollectExtraUpdates
void onCollectExtraUpdates(UIViewOperationQueue uiViewOperationQueue)
Called after layout step at the end of the UI batch from UIManagerModule. May be usedto enqueue additional ui operations for the native view. Will only be called on nodes marked asupdated either with dirty or markUpdated.
- Parameters:
uiViewOperationQueue
- interface for enqueueing UI operations
-
dispatchUpdates
boolean dispatchUpdates(float absoluteX, float absoluteY, UIViewOperationQueue uiViewOperationQueue, @Nullable() NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer)
-
getReactTag
final int getReactTag()
-
setReactTag
void setReactTag(int reactTag)
-
getRootTag
final int getRootTag()
-
setRootTag
final void setRootTag(int rootTag)
-
setViewClassName
final void setViewClassName(String viewClassName)
-
getParent
@Nullable() final ReactShadowNodeImpl getParent()
-
getLayoutParent
@Nullable() final ReactShadowNodeImpl getLayoutParent()
-
setLayoutParent
final void setLayoutParent(@Nullable() ReactShadowNodeImpl layoutParent)
-
getThemedContext
final ThemedReactContext getThemedContext()
Get the ThemedReactContext associated with this ReactShadowNodeImpl. This willnever change during the lifetime of a ReactShadowNodeImpl instance, but differentinstances can have different contexts; don't cache any calculations based on theme valuesglobally.
-
setThemedContext
void setThemedContext(ThemedReactContext themedContext)
-
shouldNotifyOnLayout
final boolean shouldNotifyOnLayout()
-
calculateLayout
void calculateLayout()
-
calculateLayout
void calculateLayout(float width, float height)
-
hasNewLayout
final boolean hasNewLayout()
-
markLayoutSeen
final void markLayoutSeen()
-
addNativeChildAt
final void addNativeChildAt(ReactShadowNodeImpl child, int nativeIndex)
Adds a child that the native view hierarchy will have at this index in the native viewcorresponding to this node.
-
removeNativeChildAt
final ReactShadowNodeImpl removeNativeChildAt(int i)
-
removeAllNativeChildren
final void removeAllNativeChildren()
-
getNativeChildCount
final int getNativeChildCount()
-
indexOfNativeChild
final int indexOfNativeChild(ReactShadowNodeImpl nativeChild)
-
getNativeParent
@Nullable() final ReactShadowNodeImpl getNativeParent()
-
setIsLayoutOnly
final void setIsLayoutOnly(boolean isLayoutOnly)
Sets whether this node only contributes to the layout of its children without doing any drawingor functionality itself.
-
isLayoutOnly
final boolean isLayoutOnly()
-
getNativeKind
NativeKind getNativeKind()
-
getTotalNativeChildren
final int getTotalNativeChildren()
-
isDescendantOf
boolean isDescendantOf(ReactShadowNodeImpl ancestorNode)
-
setLocalData
void setLocalData(Object data)
-
getNativeOffsetForChild
final int getNativeOffsetForChild(ReactShadowNodeImpl child)
Returns the offset within the native children owned by all layout-only nodes in the subtreerooted at this node for the given child. Put another way, this returns the number of nativenodes (nodes not optimized out of the native tree) that are a) to the left (visited before by aDFS) of the given child in the subtree rooted at this node and b) do not have a native parentin this subtree (which means that the given child will be a sibling of theirs in the finalnative hierarchy since they'll get attached to the same native parent).
Basically, a view might have children that have been optimized away by . Since those children will then add their native children to thisview, we now have ranges of native children that correspond to single unoptimized children. Thepurpose of this method is to return the index within the native children that corresponds tothe **start** of the native children that belong to the given child. Also, note that all of thechildren of a view might be optimized away, so this could return the same value for multipledifferent 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) => 1getNativeOffsetForChild(Node 2) => 4 getNativeOffsetForChild(Node 3) => 4
getNativeOffsetForChild(Node 4) => 6
-
getLayoutX
final float getLayoutX()
-
getLayoutY
final float getLayoutY()
-
getLayoutWidth
final float getLayoutWidth()
-
getLayoutHeight
final float getLayoutHeight()
-
getScreenX
int getScreenX()
-
getScreenY
int getScreenY()
-
getScreenWidth
int getScreenWidth()
-
getScreenHeight
int getScreenHeight()
-
getLayoutDirection
final YogaDirection getLayoutDirection()
-
setLayoutDirection
void setLayoutDirection(YogaDirection direction)
-
getStyleWidth
final YogaValue getStyleWidth()
-
setStyleWidth
void setStyleWidth(float widthPx)
-
setStyleWidthPercent
void setStyleWidthPercent(float percent)
-
setStyleWidthAuto
void setStyleWidthAuto()
-
setStyleMinWidth
void setStyleMinWidth(float widthPx)
-
setStyleMinWidthPercent
void setStyleMinWidthPercent(float percent)
-
setStyleMaxWidth
void setStyleMaxWidth(float widthPx)
-
setStyleMaxWidthPercent
void setStyleMaxWidthPercent(float percent)
-
getStyleHeight
final YogaValue getStyleHeight()
-
setStyleHeight
void setStyleHeight(float heightPx)
-
setStyleHeightPercent
void setStyleHeightPercent(float percent)
-
setStyleHeightAuto
void setStyleHeightAuto()
-
setStyleMinHeight
void setStyleMinHeight(float widthPx)
-
setStyleMinHeightPercent
void setStyleMinHeightPercent(float percent)
-
setStyleMaxHeight
void setStyleMaxHeight(float widthPx)
-
setStyleMaxHeightPercent
void setStyleMaxHeightPercent(float percent)
-
getFlex
float getFlex()
-
setFlex
void setFlex(float flex)
-
setFlexGrow
void setFlexGrow(float flexGrow)
-
setFlexShrink
void setFlexShrink(float flexShrink)
-
setFlexBasis
void setFlexBasis(float flexBasis)
-
setFlexBasisAuto
void setFlexBasisAuto()
-
setFlexBasisPercent
void setFlexBasisPercent(float percent)
-
setStyleAspectRatio
void setStyleAspectRatio(float aspectRatio)
-
setFlexDirection
void setFlexDirection(YogaFlexDirection flexDirection)
-
setFlexWrap
void setFlexWrap(YogaWrap wrap)
-
setAlignSelf
void setAlignSelf(YogaAlign alignSelf)
-
setAlignItems
void setAlignItems(YogaAlign alignItems)
-
setAlignContent
void setAlignContent(YogaAlign alignContent)
-
setJustifyContent
void setJustifyContent(YogaJustify justifyContent)
-
setOverflow
void setOverflow(YogaOverflow overflow)
-
setDisplay
void setDisplay(YogaDisplay display)
-
setMargin
void setMargin(int spacingType, float margin)
-
setMarginPercent
void setMarginPercent(int spacingType, float percent)
-
setMarginAuto
void setMarginAuto(int spacingType)
-
getPadding
final float getPadding(int spacingType)
-
getStylePadding
final YogaValue getStylePadding(int spacingType)
-
setDefaultPadding
void setDefaultPadding(int spacingType, float padding)
-
setPadding
void setPadding(int spacingType, float padding)
-
setPaddingPercent
void setPaddingPercent(int spacingType, float percent)
-
setBorder
void setBorder(int spacingType, float borderWidth)
-
setPosition
void setPosition(int spacingType, float position)
-
setPositionPercent
void setPositionPercent(int spacingType, float percent)
-
setPositionType
void setPositionType(YogaPositionType positionType)
-
setShouldNotifyOnLayout
void setShouldNotifyOnLayout(boolean shouldNotifyOnLayout)
-
setBaselineFunction
void setBaselineFunction(YogaBaselineFunction baselineFunction)
-
setMeasureFunction
void setMeasureFunction(YogaMeasureFunction measureFunction)
-
isMeasureDefined
boolean isMeasureDefined()
-
getHierarchyInfo
String getHierarchyInfo()
-
dispose
void dispose()
-
setMeasureSpecs
void setMeasureSpecs(int widthMeasureSpec, int heightMeasureSpec)
-
getWidthMeasureSpec
Integer getWidthMeasureSpec()
-
getHeightMeasureSpec
Integer getHeightMeasureSpec()
-
calculateLayoutOnChildren
Iterable<out ReactShadowNode> calculateLayoutOnChildren()
-
-
-
-