/** * Copyright (c) 2015-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ package com.facebook.react.uimanager; import com.facebook.yoga.YogaAlign; import com.facebook.yoga.YogaBaselineFunction; import com.facebook.yoga.YogaDirection; import com.facebook.yoga.YogaDisplay; import com.facebook.yoga.YogaFlexDirection; import com.facebook.yoga.YogaJustify; import com.facebook.yoga.YogaMeasureFunction; import com.facebook.yoga.YogaNode; import com.facebook.yoga.YogaOverflow; import com.facebook.yoga.YogaPositionType; import com.facebook.yoga.YogaValue; import com.facebook.yoga.YogaWrap; import javax.annotation.Nullable; /** * Base node class for representing virtual tree of React nodes. Shadow nodes are used primarily for * layouting therefore it extends {@link YogaNode} to allow that. They also help with handling * Common base subclass of {@link YogaNode} for all layout nodes for react-based view. It extends * {@link YogaNode} by adding additional capabilities. * *
Instances of this class receive property updates from JS via @{link UIManagerModule}. * Subclasses may use {@link #updateShadowNode} to persist some of the updated fields in the node * instance that corresponds to a particular view type. * *
Subclasses of {@link ReactShadowNode} should be created only from {@link ViewManager} that * corresponds to a certain type of native view. They will be updated and accessed only from JS * thread. Subclasses of {@link ViewManager} may choose to use base class {@link ReactShadowNode} or * custom subclass of it if necessary. * *
The primary use-case for {@link 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. {@link #getChildCount()} and
* separately native children (e.g. {@link #getNativeChildCount()}). See {@link
* NativeViewHierarchyOptimizer} for more information.
*/
public interface ReactShadowNode Basically, a view might have children that have been optimized away by {@link
* 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) => 6
*/
int getNativeOffsetForChild(T child);
float getLayoutX();
float getLayoutY();
float getLayoutWidth();
float getLayoutHeight();
/** @return the x position of the corresponding view on the screen, rounded to pixels */
int getScreenX();
/** @return the y position of the corresponding view on the screen, rounded to pixels */
int getScreenY();
/** @return width corrected for rounding to pixels. */
int getScreenWidth();
/** @return height corrected for rounding to pixels. */
int getScreenHeight();
YogaDirection getLayoutDirection();
void setLayoutDirection(YogaDirection direction);
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);
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);
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);
float getPadding(int spacingType);
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();
void dispose();
}