-
- 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 booleanisVirtual()Nodes that return {@code true}will be treated as "virtual" nodes.booleanisVirtualAnchor()Nodes that return {@code true}will be treated as a root view for the virtual nodes tree.booleanisYogaLeafNode()Nodes that return {@code true}will not manage (and and remove) child Yoga nodes.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.final StringgetViewClass()final booleanhasUpdates()final voidmarkUpdateSeen()voidmarkUpdated()final booleanhasUnseenUpdates()voiddirty()final booleanisDirty()voidaddChildAt(ReactShadowNodeImpl child, int i)ReactShadowNodeImplremoveChildAt(int i)final intgetChildCount()final ReactShadowNodeImplgetChildAt(int i)final intindexOf(ReactShadowNodeImpl child)voidremoveAndDisposeAllChildren()voidonBeforeLayout(NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer)This method will be called by UIManagerModule once per batch, before calculatinglayout. final voidupdateProperties(ReactStylesDiffMap props)voidonAfterUpdateTransaction()voidonCollectExtraUpdates(UIViewOperationQueue uiViewOperationQueue)Called after layout step at the end of the UI batch from UIManagerModule. booleandispatchUpdates(float absoluteX, float absoluteY, UIViewOperationQueue uiViewOperationQueue, @Nullable() NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer)final intgetReactTag()voidsetReactTag(int reactTag)final intgetRootTag()final voidsetRootTag(int rootTag)final voidsetViewClassName(String viewClassName)final ReactShadowNodeImplgetParent()final ReactShadowNodeImplgetLayoutParent()final voidsetLayoutParent(@Nullable() ReactShadowNodeImpl layoutParent)final ThemedReactContextgetThemedContext()Get the ThemedReactContext associated with this ReactShadowNodeImpl. voidsetThemedContext(ThemedReactContext themedContext)final booleanshouldNotifyOnLayout()voidcalculateLayout()voidcalculateLayout(float width, float height)final booleanhasNewLayout()final voidmarkLayoutSeen()final voidaddNativeChildAt(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 ReactShadowNodeImplremoveNativeChildAt(int i)final voidremoveAllNativeChildren()final intgetNativeChildCount()final intindexOfNativeChild(ReactShadowNodeImpl nativeChild)final ReactShadowNodeImplgetNativeParent()final voidsetIsLayoutOnly(boolean isLayoutOnly)Sets whether this node only contributes to the layout of its children without doing any drawingor functionality itself. final booleanisLayoutOnly()NativeKindgetNativeKind()final intgetTotalNativeChildren()booleanisDescendantOf(ReactShadowNodeImpl ancestorNode)StringtoString()voidsetLocalData(Object data)final intgetNativeOffsetForChild(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 floatgetLayoutX()final floatgetLayoutY()final floatgetLayoutWidth()final floatgetLayoutHeight()intgetScreenX()intgetScreenY()intgetScreenWidth()intgetScreenHeight()final YogaDirectiongetLayoutDirection()voidsetLayoutDirection(YogaDirection direction)final YogaValuegetStyleWidth()voidsetStyleWidth(float widthPx)voidsetStyleWidthPercent(float percent)voidsetStyleWidthAuto()voidsetStyleMinWidth(float widthPx)voidsetStyleMinWidthPercent(float percent)voidsetStyleMaxWidth(float widthPx)voidsetStyleMaxWidthPercent(float percent)final YogaValuegetStyleHeight()voidsetStyleHeight(float heightPx)voidsetStyleHeightPercent(float percent)voidsetStyleHeightAuto()voidsetStyleMinHeight(float widthPx)voidsetStyleMinHeightPercent(float percent)voidsetStyleMaxHeight(float widthPx)voidsetStyleMaxHeightPercent(float percent)floatgetFlex()voidsetFlex(float flex)voidsetFlexGrow(float flexGrow)voidsetFlexShrink(float flexShrink)voidsetFlexBasis(float flexBasis)voidsetFlexBasisAuto()voidsetFlexBasisPercent(float percent)voidsetStyleAspectRatio(float aspectRatio)voidsetFlexDirection(YogaFlexDirection flexDirection)voidsetFlexWrap(YogaWrap wrap)voidsetAlignSelf(YogaAlign alignSelf)voidsetAlignItems(YogaAlign alignItems)voidsetAlignContent(YogaAlign alignContent)voidsetJustifyContent(YogaJustify justifyContent)voidsetOverflow(YogaOverflow overflow)voidsetDisplay(YogaDisplay display)voidsetMargin(int spacingType, float margin)voidsetMarginPercent(int spacingType, float percent)voidsetMarginAuto(int spacingType)final floatgetPadding(int spacingType)final YogaValuegetStylePadding(int spacingType)voidsetDefaultPadding(int spacingType, float padding)voidsetPadding(int spacingType, float padding)voidsetPaddingPercent(int spacingType, float percent)voidsetBorder(int spacingType, float borderWidth)voidsetPosition(int spacingType, float position)voidsetPositionPercent(int spacingType, float percent)voidsetPositionType(YogaPositionType positionType)voidsetShouldNotifyOnLayout(boolean shouldNotifyOnLayout)voidsetBaselineFunction(YogaBaselineFunction baselineFunction)voidsetMeasureFunction(YogaMeasureFunction measureFunction)booleanisMeasureDefined()StringgetHierarchyInfo()voiddispose()voidsetMeasureSpecs(int widthMeasureSpec, int heightMeasureSpec)IntegergetWidthMeasureSpec()IntegergetHeightMeasureSpec()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()
-
-
-
-