-
public interface ReactShadowNode<T extends ReactShadowNode>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 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 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.
-
-
Method Summary
Modifier and Type Method Description abstract booleanisVirtual()Nodes that return {@code true}will be treated as "virtual" nodes.abstract booleanisVirtualAnchor()Nodes that return {@code true}will be treated as a root view for the virtual nodes tree.abstract booleanisYogaLeafNode()Nodes that return {@code true}will not manage (and and remove) child Yoga nodes.abstract booleanhoistNativeChildren()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.abstract StringgetViewClass()abstract booleanhasUpdates()abstract voidmarkUpdateSeen()abstract voidmarkUpdated()abstract booleanhasUnseenUpdates()abstract voiddirty()abstract booleanisDirty()abstract voidaddChildAt(T child, int i)abstract TremoveChildAt(int i)abstract intgetChildCount()abstract TgetChildAt(int i)abstract intindexOf(T child)abstract voidremoveAndDisposeAllChildren()abstract voidonBeforeLayout(NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer)This method will be called by UIManagerModule once per batch, before calculatinglayout. abstract voidupdateProperties(ReactStylesDiffMap props)abstract voidonAfterUpdateTransaction()abstract voidonCollectExtraUpdates(UIViewOperationQueue uiViewOperationQueue)Called after layout step at the end of the UI batch from UIManagerModule. abstract booleandispatchUpdates(float absoluteX, float absoluteY, UIViewOperationQueue uiViewOperationQueue, NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer)abstract intgetReactTag()abstract voidsetReactTag(int reactTag)abstract intgetRootTag()abstract voidsetRootTag(int rootTag)abstract voidsetViewClassName(String viewClassName)abstract TgetParent()abstract TgetLayoutParent()abstract voidsetLayoutParent(@Nullable() T layoutParent)abstract ThemedReactContextgetThemedContext()Get the ThemedReactContext associated with this ReactShadowNode. abstract voidsetThemedContext(ThemedReactContext themedContext)abstract booleanshouldNotifyOnLayout()abstract voidcalculateLayout()abstract voidcalculateLayout(float width, float height)abstract booleanhasNewLayout()abstract voidmarkLayoutSeen()abstract voidaddNativeChildAt(T child, int nativeIndex)Adds a child that the native view hierarchy will have at this index in the native viewcorresponding to this node. abstract TremoveNativeChildAt(int i)abstract voidremoveAllNativeChildren()abstract intgetNativeChildCount()abstract intindexOfNativeChild(T nativeChild)abstract TgetNativeParent()abstract voidsetIsLayoutOnly(boolean isLayoutOnly)Sets whether this node only contributes to the layout of its children without doing any drawingor functionality itself. abstract booleanisLayoutOnly()abstract NativeKindgetNativeKind()abstract intgetTotalNativeChildren()abstract booleanisDescendantOf(T ancestorNode)abstract StringgetHierarchyInfo()abstract voidsetLocalData(Object data)abstract intgetNativeOffsetForChild(T child)Returns the offset within the native children owned by all layout-only nodes in the subtreerooted at this node for the given child. abstract floatgetLayoutX()abstract floatgetLayoutY()abstract floatgetLayoutWidth()abstract floatgetLayoutHeight()abstract intgetScreenX()abstract intgetScreenY()abstract intgetScreenWidth()abstract intgetScreenHeight()abstract YogaDirectiongetLayoutDirection()abstract voidsetLayoutDirection(YogaDirection direction)abstract YogaValuegetStyleWidth()abstract voidsetStyleWidth(float widthPx)abstract voidsetStyleWidthPercent(float percent)abstract voidsetStyleWidthAuto()abstract voidsetStyleMinWidth(float widthPx)abstract voidsetStyleMinWidthPercent(float percent)abstract voidsetStyleMaxWidth(float widthPx)abstract voidsetStyleMaxWidthPercent(float percent)abstract YogaValuegetStyleHeight()abstract floatgetFlex()abstract voidsetStyleHeight(float heightPx)abstract voidsetStyleHeightPercent(float percent)abstract voidsetStyleHeightAuto()abstract voidsetStyleMinHeight(float widthPx)abstract voidsetStyleMinHeightPercent(float percent)abstract voidsetStyleMaxHeight(float widthPx)abstract voidsetStyleMaxHeightPercent(float percent)abstract voidsetFlex(float flex)abstract voidsetFlexGrow(float flexGrow)abstract voidsetFlexShrink(float flexShrink)abstract voidsetFlexBasis(float flexBasis)abstract voidsetFlexBasisAuto()abstract voidsetFlexBasisPercent(float percent)abstract voidsetStyleAspectRatio(float aspectRatio)abstract voidsetFlexDirection(YogaFlexDirection flexDirection)abstract voidsetFlexWrap(YogaWrap wrap)abstract voidsetAlignSelf(YogaAlign alignSelf)abstract voidsetAlignItems(YogaAlign alignItems)abstract voidsetAlignContent(YogaAlign alignContent)abstract voidsetJustifyContent(YogaJustify justifyContent)abstract voidsetOverflow(YogaOverflow overflow)abstract voidsetDisplay(YogaDisplay display)abstract voidsetMargin(int spacingType, float margin)abstract voidsetMarginPercent(int spacingType, float percent)abstract voidsetMarginAuto(int spacingType)abstract floatgetPadding(int spacingType)abstract YogaValuegetStylePadding(int spacingType)abstract voidsetDefaultPadding(int spacingType, float padding)abstract voidsetPadding(int spacingType, float padding)abstract voidsetPaddingPercent(int spacingType, float percent)abstract voidsetBorder(int spacingType, float borderWidth)abstract voidsetPosition(int spacingType, float position)abstract voidsetPositionPercent(int spacingType, float percent)abstract voidsetPositionType(YogaPositionType positionType)abstract voidsetShouldNotifyOnLayout(boolean shouldNotifyOnLayout)abstract voidsetBaselineFunction(YogaBaselineFunction baselineFunction)abstract voidsetMeasureFunction(YogaMeasureFunction measureFunction)abstract booleanisMeasureDefined()abstract voiddispose()abstract voidsetMeasureSpecs(int widthMeasureSpec, int heightMeasureSpec)abstract IntegergetWidthMeasureSpec()abstract IntegergetHeightMeasureSpec()abstract Iterable<out ReactShadowNode>calculateLayoutOnChildren()-
-
Method Detail
-
isVirtual
abstract 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
abstract 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
abstract 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
abstract 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
abstract String getViewClass()
-
hasUpdates
abstract boolean hasUpdates()
-
markUpdateSeen
abstract void markUpdateSeen()
-
markUpdated
abstract void markUpdated()
-
hasUnseenUpdates
abstract boolean hasUnseenUpdates()
-
dirty
abstract void dirty()
-
isDirty
abstract boolean isDirty()
-
addChildAt
abstract void addChildAt(T child, int i)
-
removeChildAt
abstract T removeChildAt(int i)
-
getChildCount
abstract int getChildCount()
-
getChildAt
abstract T getChildAt(int i)
-
removeAndDisposeAllChildren
abstract void removeAndDisposeAllChildren()
-
onBeforeLayout
abstract 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
abstract void updateProperties(ReactStylesDiffMap props)
-
onAfterUpdateTransaction
abstract void onAfterUpdateTransaction()
-
onCollectExtraUpdates
abstract 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
abstract boolean dispatchUpdates(float absoluteX, float absoluteY, UIViewOperationQueue uiViewOperationQueue, NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer)
-
getReactTag
abstract int getReactTag()
-
setReactTag
abstract void setReactTag(int reactTag)
-
getRootTag
abstract int getRootTag()
-
setRootTag
abstract void setRootTag(int rootTag)
-
setViewClassName
abstract void setViewClassName(String viewClassName)
-
getLayoutParent
@Nullable() abstract T getLayoutParent()
-
setLayoutParent
abstract void setLayoutParent(@Nullable() T layoutParent)
-
getThemedContext
abstract ThemedReactContext getThemedContext()
Get the ThemedReactContext associated with this ReactShadowNode. This willnever change during the lifetime of a ReactShadowNode instance, but different instancescan have different contexts; don't cache any calculations based on theme values globally.
-
setThemedContext
abstract void setThemedContext(ThemedReactContext themedContext)
-
shouldNotifyOnLayout
abstract boolean shouldNotifyOnLayout()
-
calculateLayout
abstract void calculateLayout()
-
calculateLayout
abstract void calculateLayout(float width, float height)
-
hasNewLayout
abstract boolean hasNewLayout()
-
markLayoutSeen
abstract void markLayoutSeen()
-
addNativeChildAt
abstract void addNativeChildAt(T child, int nativeIndex)
Adds a child that the native view hierarchy will have at this index in the native viewcorresponding to this node.
-
removeNativeChildAt
abstract T removeNativeChildAt(int i)
-
removeAllNativeChildren
abstract void removeAllNativeChildren()
-
getNativeChildCount
abstract int getNativeChildCount()
-
indexOfNativeChild
abstract int indexOfNativeChild(T nativeChild)
-
getNativeParent
@Nullable() abstract T getNativeParent()
-
setIsLayoutOnly
abstract void setIsLayoutOnly(boolean isLayoutOnly)
Sets whether this node only contributes to the layout of its children without doing any drawingor functionality itself.
-
isLayoutOnly
abstract boolean isLayoutOnly()
-
getNativeKind
abstract NativeKind getNativeKind()
-
getTotalNativeChildren
abstract int getTotalNativeChildren()
-
isDescendantOf
abstract boolean isDescendantOf(T ancestorNode)
-
getHierarchyInfo
abstract String getHierarchyInfo()
-
setLocalData
abstract void setLocalData(Object data)
-
getNativeOffsetForChild
abstract int getNativeOffsetForChild(T 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
abstract float getLayoutX()
-
getLayoutY
abstract float getLayoutY()
-
getLayoutWidth
abstract float getLayoutWidth()
-
getLayoutHeight
abstract float getLayoutHeight()
-
getScreenX
abstract int getScreenX()
-
getScreenY
abstract int getScreenY()
-
getScreenWidth
abstract int getScreenWidth()
-
getScreenHeight
abstract int getScreenHeight()
-
getLayoutDirection
abstract YogaDirection getLayoutDirection()
-
setLayoutDirection
abstract void setLayoutDirection(YogaDirection direction)
-
getStyleWidth
abstract YogaValue getStyleWidth()
-
setStyleWidth
abstract void setStyleWidth(float widthPx)
-
setStyleWidthPercent
abstract void setStyleWidthPercent(float percent)
-
setStyleWidthAuto
abstract void setStyleWidthAuto()
-
setStyleMinWidth
abstract void setStyleMinWidth(float widthPx)
-
setStyleMinWidthPercent
abstract void setStyleMinWidthPercent(float percent)
-
setStyleMaxWidth
abstract void setStyleMaxWidth(float widthPx)
-
setStyleMaxWidthPercent
abstract void setStyleMaxWidthPercent(float percent)
-
getStyleHeight
abstract YogaValue getStyleHeight()
-
getFlex
abstract float getFlex()
-
setStyleHeight
abstract void setStyleHeight(float heightPx)
-
setStyleHeightPercent
abstract void setStyleHeightPercent(float percent)
-
setStyleHeightAuto
abstract void setStyleHeightAuto()
-
setStyleMinHeight
abstract void setStyleMinHeight(float widthPx)
-
setStyleMinHeightPercent
abstract void setStyleMinHeightPercent(float percent)
-
setStyleMaxHeight
abstract void setStyleMaxHeight(float widthPx)
-
setStyleMaxHeightPercent
abstract void setStyleMaxHeightPercent(float percent)
-
setFlex
abstract void setFlex(float flex)
-
setFlexGrow
abstract void setFlexGrow(float flexGrow)
-
setFlexShrink
abstract void setFlexShrink(float flexShrink)
-
setFlexBasis
abstract void setFlexBasis(float flexBasis)
-
setFlexBasisAuto
abstract void setFlexBasisAuto()
-
setFlexBasisPercent
abstract void setFlexBasisPercent(float percent)
-
setStyleAspectRatio
abstract void setStyleAspectRatio(float aspectRatio)
-
setFlexDirection
abstract void setFlexDirection(YogaFlexDirection flexDirection)
-
setFlexWrap
abstract void setFlexWrap(YogaWrap wrap)
-
setAlignSelf
abstract void setAlignSelf(YogaAlign alignSelf)
-
setAlignItems
abstract void setAlignItems(YogaAlign alignItems)
-
setAlignContent
abstract void setAlignContent(YogaAlign alignContent)
-
setJustifyContent
abstract void setJustifyContent(YogaJustify justifyContent)
-
setOverflow
abstract void setOverflow(YogaOverflow overflow)
-
setDisplay
abstract void setDisplay(YogaDisplay display)
-
setMargin
abstract void setMargin(int spacingType, float margin)
-
setMarginPercent
abstract void setMarginPercent(int spacingType, float percent)
-
setMarginAuto
abstract void setMarginAuto(int spacingType)
-
getPadding
abstract float getPadding(int spacingType)
-
getStylePadding
abstract YogaValue getStylePadding(int spacingType)
-
setDefaultPadding
abstract void setDefaultPadding(int spacingType, float padding)
-
setPadding
abstract void setPadding(int spacingType, float padding)
-
setPaddingPercent
abstract void setPaddingPercent(int spacingType, float percent)
-
setBorder
abstract void setBorder(int spacingType, float borderWidth)
-
setPosition
abstract void setPosition(int spacingType, float position)
-
setPositionPercent
abstract void setPositionPercent(int spacingType, float percent)
-
setPositionType
abstract void setPositionType(YogaPositionType positionType)
-
setShouldNotifyOnLayout
abstract void setShouldNotifyOnLayout(boolean shouldNotifyOnLayout)
-
setBaselineFunction
abstract void setBaselineFunction(YogaBaselineFunction baselineFunction)
-
setMeasureFunction
abstract void setMeasureFunction(YogaMeasureFunction measureFunction)
-
isMeasureDefined
abstract boolean isMeasureDefined()
-
dispose
abstract void dispose()
-
setMeasureSpecs
abstract void setMeasureSpecs(int widthMeasureSpec, int heightMeasureSpec)
-
getWidthMeasureSpec
abstract Integer getWidthMeasureSpec()
-
getHeightMeasureSpec
abstract Integer getHeightMeasureSpec()
-
calculateLayoutOnChildren
abstract Iterable<out ReactShadowNode> calculateLayoutOnChildren()
-
-
-
-