-
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 boolean
isVirtual()
Nodes that return {@code true}
will be treated as "virtual" nodes.abstract boolean
isVirtualAnchor()
Nodes that return {@code true}
will be treated as a root view for the virtual nodes tree.abstract boolean
isYogaLeafNode()
Nodes that return {@code true}
will not manage (and and remove) child Yoga nodes.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.abstract String
getViewClass()
abstract boolean
hasUpdates()
abstract void
markUpdateSeen()
abstract void
markUpdated()
abstract boolean
hasUnseenUpdates()
abstract void
dirty()
abstract boolean
isDirty()
abstract void
addChildAt(T child, int i)
abstract T
removeChildAt(int i)
abstract int
getChildCount()
abstract T
getChildAt(int i)
abstract int
indexOf(T child)
abstract void
removeAndDisposeAllChildren()
abstract void
onBeforeLayout(NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer)
This method will be called by UIManagerModule once per batch, before calculatinglayout. abstract void
updateProperties(ReactStylesDiffMap props)
abstract void
onAfterUpdateTransaction()
abstract void
onCollectExtraUpdates(UIViewOperationQueue uiViewOperationQueue)
Called after layout step at the end of the UI batch from UIManagerModule. abstract boolean
dispatchUpdates(float absoluteX, float absoluteY, UIViewOperationQueue uiViewOperationQueue, NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer)
abstract int
getReactTag()
abstract void
setReactTag(int reactTag)
abstract int
getRootTag()
abstract void
setRootTag(int rootTag)
abstract void
setViewClassName(String viewClassName)
abstract T
getParent()
abstract T
getLayoutParent()
abstract void
setLayoutParent(@Nullable() T layoutParent)
abstract ThemedReactContext
getThemedContext()
Get the ThemedReactContext associated with this ReactShadowNode. abstract void
setThemedContext(ThemedReactContext themedContext)
abstract boolean
shouldNotifyOnLayout()
abstract void
calculateLayout()
abstract void
calculateLayout(float width, float height)
abstract boolean
hasNewLayout()
abstract void
markLayoutSeen()
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. abstract T
removeNativeChildAt(int i)
abstract void
removeAllNativeChildren()
abstract int
getNativeChildCount()
abstract int
indexOfNativeChild(T nativeChild)
abstract T
getNativeParent()
abstract void
setIsLayoutOnly(boolean isLayoutOnly)
Sets whether this node only contributes to the layout of its children without doing any drawingor functionality itself. abstract boolean
isLayoutOnly()
abstract NativeKind
getNativeKind()
abstract int
getTotalNativeChildren()
abstract boolean
isDescendantOf(T ancestorNode)
abstract String
getHierarchyInfo()
abstract void
setLocalData(Object data)
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. abstract float
getLayoutX()
abstract float
getLayoutY()
abstract float
getLayoutWidth()
abstract float
getLayoutHeight()
abstract int
getScreenX()
abstract int
getScreenY()
abstract int
getScreenWidth()
abstract int
getScreenHeight()
abstract YogaDirection
getLayoutDirection()
abstract void
setLayoutDirection(YogaDirection direction)
abstract YogaValue
getStyleWidth()
abstract void
setStyleWidth(float widthPx)
abstract void
setStyleWidthPercent(float percent)
abstract void
setStyleWidthAuto()
abstract void
setStyleMinWidth(float widthPx)
abstract void
setStyleMinWidthPercent(float percent)
abstract void
setStyleMaxWidth(float widthPx)
abstract void
setStyleMaxWidthPercent(float percent)
abstract YogaValue
getStyleHeight()
abstract float
getFlex()
abstract void
setStyleHeight(float heightPx)
abstract void
setStyleHeightPercent(float percent)
abstract void
setStyleHeightAuto()
abstract void
setStyleMinHeight(float widthPx)
abstract void
setStyleMinHeightPercent(float percent)
abstract void
setStyleMaxHeight(float widthPx)
abstract void
setStyleMaxHeightPercent(float percent)
abstract void
setFlex(float flex)
abstract void
setFlexGrow(float flexGrow)
abstract void
setFlexShrink(float flexShrink)
abstract void
setFlexBasis(float flexBasis)
abstract void
setFlexBasisAuto()
abstract void
setFlexBasisPercent(float percent)
abstract void
setStyleAspectRatio(float aspectRatio)
abstract void
setFlexDirection(YogaFlexDirection flexDirection)
abstract void
setFlexWrap(YogaWrap wrap)
abstract void
setAlignSelf(YogaAlign alignSelf)
abstract void
setAlignItems(YogaAlign alignItems)
abstract void
setAlignContent(YogaAlign alignContent)
abstract void
setJustifyContent(YogaJustify justifyContent)
abstract void
setOverflow(YogaOverflow overflow)
abstract void
setDisplay(YogaDisplay display)
abstract void
setMargin(int spacingType, float margin)
abstract void
setMarginPercent(int spacingType, float percent)
abstract void
setMarginAuto(int spacingType)
abstract float
getPadding(int spacingType)
abstract YogaValue
getStylePadding(int spacingType)
abstract void
setDefaultPadding(int spacingType, float padding)
abstract void
setPadding(int spacingType, float padding)
abstract void
setPaddingPercent(int spacingType, float percent)
abstract void
setBorder(int spacingType, float borderWidth)
abstract void
setPosition(int spacingType, float position)
abstract void
setPositionPercent(int spacingType, float percent)
abstract void
setPositionType(YogaPositionType positionType)
abstract void
setShouldNotifyOnLayout(boolean shouldNotifyOnLayout)
abstract void
setBaselineFunction(YogaBaselineFunction baselineFunction)
abstract void
setMeasureFunction(YogaMeasureFunction measureFunction)
abstract boolean
isMeasureDefined()
abstract void
dispose()
abstract void
setMeasureSpecs(int widthMeasureSpec, int heightMeasureSpec)
abstract Integer
getWidthMeasureSpec()
abstract Integer
getHeightMeasureSpec()
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()
-
-
-
-