Rename java API

Reviewed By: IanChilds

Differential Revision: D4265345

fbshipit-source-id: 69ecfd8fac214f86b8b70647b9b909acd83d78b5
This commit is contained in:
Emil Sjolander
2016-12-12 11:36:38 +00:00
committed by Martin Konicek
parent 99f972f33f
commit 2c26dffa79
16 changed files with 173 additions and 154 deletions
@@ -19,8 +19,8 @@ import com.facebook.csslayout.YogaConstants;
import com.facebook.csslayout.YogaDirection;
import com.facebook.csslayout.YogaFlexDirection;
import com.facebook.csslayout.YogaJustify;
import com.facebook.csslayout.CSSNode;
import com.facebook.csslayout.CSSNodeAPI;
import com.facebook.csslayout.YogaMeasureFunction;
import com.facebook.csslayout.YogaNode;
import com.facebook.csslayout.YogaOverflow;
import com.facebook.csslayout.YogaPositionType;
import com.facebook.csslayout.YogaWrap;
@@ -29,9 +29,9 @@ import com.facebook.react.uimanager.annotations.ReactPropertyHolder;
/**
* Base node class for representing virtual tree of React nodes. Shadow nodes are used primarily
* for layouting therefore it extends {@link CSSNode} to allow that. They also help with handling
* Common base subclass of {@link CSSNode} for all layout nodes for react-based view. It extends
* {@link CSSNode} by adding additional capabilities.
* 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
@@ -43,7 +43,7 @@ import com.facebook.react.uimanager.annotations.ReactPropertyHolder;
* 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 ARTGroupCSSNode or ReactTextCSSNode.
* 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
@@ -73,17 +73,17 @@ public class ReactShadowNode {
private float mAbsoluteBottom;
private final Spacing mDefaultPadding = new Spacing(0);
private final Spacing mPadding = new Spacing(YogaConstants.UNDEFINED);
private final CSSNode mCSSNode;
private final YogaNode mYogaNode;
public ReactShadowNode() {
if (!isVirtual()) {
CSSNode node = CSSNodePool.get().acquire();
YogaNode node = YogaNodePool.get().acquire();
if (node == null) {
node = new CSSNode();
node = new YogaNode();
}
mCSSNode = node;
mYogaNode = node;
} else {
mCSSNode = null;
mYogaNode = null;
}
}
@@ -138,12 +138,12 @@ public class ReactShadowNode {
public void dirty() {
if (!isVirtual()) {
mCSSNode.dirty();
mYogaNode.dirty();
}
}
public final boolean isDirty() {
return mCSSNode != null && mCSSNode.isDirty();
return mYogaNode != null && mYogaNode.isDirty();
}
public void addChildAt(ReactShadowNode child, int i) {
@@ -159,13 +159,13 @@ public class ReactShadowNode {
// If a CSS node has measure defined, the layout algorithm will not visit its children. Even
// more, it asserts that you don't add children to nodes with measure functions.
if (mCSSNode != null && !mCSSNode.isMeasureDefined()) {
CSSNode childCSSNode = child.mCSSNode;
if (childCSSNode == null) {
if (mYogaNode != null && !mYogaNode.isMeasureDefined()) {
YogaNode childYogaNode = child.mYogaNode;
if (childYogaNode == null) {
throw new RuntimeException(
"Cannot add a child that doesn't have a CSS node to a node without a measure function!");
}
mCSSNode.addChildAt(childCSSNode, i);
mYogaNode.addChildAt(childYogaNode, i);
}
markUpdated();
@@ -183,8 +183,8 @@ public class ReactShadowNode {
ReactShadowNode removed = mChildren.remove(i);
removed.mParent = null;
if (mCSSNode != null && !mCSSNode.isMeasureDefined()) {
mCSSNode.removeChildAt(i);
if (mYogaNode != null && !mYogaNode.isMeasureDefined()) {
mYogaNode.removeChildAt(i);
}
markUpdated();
@@ -217,8 +217,8 @@ public class ReactShadowNode {
int decrease = 0;
for (int i = getChildCount() - 1; i >= 0; i--) {
if (mCSSNode != null && !mCSSNode.isMeasureDefined()) {
mCSSNode.removeChildAt(i);
if (mYogaNode != null && !mYogaNode.isMeasureDefined()) {
mYogaNode.removeChildAt(i);
}
ReactShadowNode toRemove = getChildAt(i);
toRemove.mParent = null;
@@ -339,16 +339,16 @@ public class ReactShadowNode {
}
public void calculateLayout() {
mCSSNode.calculateLayout();
mYogaNode.calculateLayout();
}
public final boolean hasNewLayout() {
return mCSSNode == null ? false : mCSSNode.hasNewLayout();
return mYogaNode == null ? false : mYogaNode.hasNewLayout();
}
public final void markLayoutSeen() {
if (mCSSNode != null) {
mCSSNode.markLayoutSeen();
if (mYogaNode != null) {
mYogaNode.markLayoutSeen();
}
}
@@ -463,19 +463,19 @@ public class ReactShadowNode {
}
public final float getLayoutX() {
return mCSSNode.getLayoutX();
return mYogaNode.getLayoutX();
}
public final float getLayoutY() {
return mCSSNode.getLayoutY();
return mYogaNode.getLayoutY();
}
public final float getLayoutWidth() {
return mCSSNode.getLayoutWidth();
return mYogaNode.getLayoutWidth();
}
public final float getLayoutHeight() {
return mCSSNode.getLayoutHeight();
return mYogaNode.getLayoutHeight();
}
/**
@@ -507,95 +507,95 @@ public class ReactShadowNode {
}
public final YogaDirection getLayoutDirection() {
return mCSSNode.getLayoutDirection();
return mYogaNode.getLayoutDirection();
}
public void setLayoutDirection(YogaDirection direction) {
mCSSNode.setDirection(direction);
mYogaNode.setDirection(direction);
}
public final float getStyleWidth() {
return mCSSNode.getWidth();
return mYogaNode.getWidth();
}
public void setStyleWidth(float widthPx) {
mCSSNode.setWidth(widthPx);
mYogaNode.setWidth(widthPx);
}
public void setStyleMinWidth(float widthPx) {
mCSSNode.setMinWidth(widthPx);
mYogaNode.setMinWidth(widthPx);
}
public void setStyleMaxWidth(float widthPx) {
mCSSNode.setMaxWidth(widthPx);
mYogaNode.setMaxWidth(widthPx);
}
public final float getStyleHeight() {
return mCSSNode.getHeight();
return mYogaNode.getHeight();
}
public void setStyleHeight(float heightPx) {
mCSSNode.setHeight(heightPx);
mYogaNode.setHeight(heightPx);
}
public void setStyleMinHeight(float widthPx) {
mCSSNode.setMinHeight(widthPx);
mYogaNode.setMinHeight(widthPx);
}
public void setStyleMaxHeight(float widthPx) {
mCSSNode.setMaxHeight(widthPx);
mYogaNode.setMaxHeight(widthPx);
}
public void setFlex(float flex) {
mCSSNode.setFlex(flex);
mYogaNode.setFlex(flex);
}
public void setFlexGrow(float flexGrow) {
mCSSNode.setFlexGrow(flexGrow);
mYogaNode.setFlexGrow(flexGrow);
}
public void setFlexShrink(float flexShrink) {
mCSSNode.setFlexShrink(flexShrink);
mYogaNode.setFlexShrink(flexShrink);
}
public void setFlexBasis(float flexBasis) {
mCSSNode.setFlexBasis(flexBasis);
mYogaNode.setFlexBasis(flexBasis);
}
public void setStyleAspectRatio(float aspectRatio) {
mCSSNode.setAspectRatio(aspectRatio);
mYogaNode.setAspectRatio(aspectRatio);
}
public void setFlexDirection(YogaFlexDirection flexDirection) {
mCSSNode.setFlexDirection(flexDirection);
mYogaNode.setFlexDirection(flexDirection);
}
public void setFlexWrap(YogaWrap wrap) {
mCSSNode.setWrap(wrap);
mYogaNode.setWrap(wrap);
}
public void setAlignSelf(YogaAlign alignSelf) {
mCSSNode.setAlignSelf(alignSelf);
mYogaNode.setAlignSelf(alignSelf);
}
public void setAlignItems(YogaAlign alignItems) {
mCSSNode.setAlignItems(alignItems);
mYogaNode.setAlignItems(alignItems);
}
public void setJustifyContent(YogaJustify justifyContent) {
mCSSNode.setJustifyContent(justifyContent);
mYogaNode.setJustifyContent(justifyContent);
}
public void setOverflow(YogaOverflow overflow) {
mCSSNode.setOverflow(overflow);
mYogaNode.setOverflow(overflow);
}
public void setMargin(int spacingType, float margin) {
mCSSNode.setMargin(YogaEdge.fromInt(spacingType), margin);
mYogaNode.setMargin(YogaEdge.fromInt(spacingType), margin);
}
public final float getPadding(int spacingType) {
return mCSSNode.getPadding(YogaEdge.fromInt(spacingType));
return mYogaNode.getPadding(YogaEdge.fromInt(spacingType));
}
public void setDefaultPadding(int spacingType, float padding) {
@@ -617,63 +617,63 @@ public class ReactShadowNode {
if (YogaConstants.isUndefined(mPadding.getRaw(spacingType)) &&
YogaConstants.isUndefined(mPadding.getRaw(Spacing.HORIZONTAL)) &&
YogaConstants.isUndefined(mPadding.getRaw(Spacing.ALL))) {
mCSSNode.setPadding(YogaEdge.fromInt(spacingType), mDefaultPadding.getRaw(spacingType));
mYogaNode.setPadding(YogaEdge.fromInt(spacingType), mDefaultPadding.getRaw(spacingType));
} else {
mCSSNode.setPadding(YogaEdge.fromInt(spacingType), mPadding.getRaw(spacingType));
mYogaNode.setPadding(YogaEdge.fromInt(spacingType), mPadding.getRaw(spacingType));
}
} else if (spacingType == Spacing.TOP || spacingType == Spacing.BOTTOM) {
if (YogaConstants.isUndefined(mPadding.getRaw(spacingType)) &&
YogaConstants.isUndefined(mPadding.getRaw(Spacing.VERTICAL)) &&
YogaConstants.isUndefined(mPadding.getRaw(Spacing.ALL))) {
mCSSNode.setPadding(YogaEdge.fromInt(spacingType), mDefaultPadding.getRaw(spacingType));
mYogaNode.setPadding(YogaEdge.fromInt(spacingType), mDefaultPadding.getRaw(spacingType));
} else {
mCSSNode.setPadding(YogaEdge.fromInt(spacingType), mPadding.getRaw(spacingType));
mYogaNode.setPadding(YogaEdge.fromInt(spacingType), mPadding.getRaw(spacingType));
}
} else {
if (YogaConstants.isUndefined(mPadding.getRaw(spacingType))) {
mCSSNode.setPadding(YogaEdge.fromInt(spacingType), mDefaultPadding.getRaw(spacingType));
mYogaNode.setPadding(YogaEdge.fromInt(spacingType), mDefaultPadding.getRaw(spacingType));
} else {
mCSSNode.setPadding(YogaEdge.fromInt(spacingType), mPadding.getRaw(spacingType));
mYogaNode.setPadding(YogaEdge.fromInt(spacingType), mPadding.getRaw(spacingType));
}
}
}
}
public void setBorder(int spacingType, float borderWidth) {
mCSSNode.setBorder(YogaEdge.fromInt(spacingType), borderWidth);
mYogaNode.setBorder(YogaEdge.fromInt(spacingType), borderWidth);
}
public void setPosition(int spacingType, float position) {
mCSSNode.setPosition(YogaEdge.fromInt(spacingType), position);
mYogaNode.setPosition(YogaEdge.fromInt(spacingType), position);
}
public void setPositionType(YogaPositionType positionType) {
mCSSNode.setPositionType(positionType);
mYogaNode.setPositionType(positionType);
}
public void setShouldNotifyOnLayout(boolean shouldNotifyOnLayout) {
mShouldNotifyOnLayout = shouldNotifyOnLayout;
}
public void setMeasureFunction(CSSNodeAPI.MeasureFunction measureFunction) {
if ((measureFunction == null ^ mCSSNode.isMeasureDefined()) &&
public void setMeasureFunction(YogaMeasureFunction measureFunction) {
if ((measureFunction == null ^ mYogaNode.isMeasureDefined()) &&
getChildCount() != 0) {
throw new RuntimeException(
"Since a node with a measure function does not add any native CSSLayout children, it's " +
"not safe to transition to/from having a measure function unless a node has no children");
}
mCSSNode.setMeasureFunction(measureFunction);
mYogaNode.setMeasureFunction(measureFunction);
}
@Override
public String toString() {
return mCSSNode.toString();
return mYogaNode.toString();
}
public void dispose() {
if (mCSSNode != null) {
mCSSNode.reset();
CSSNodePool.get().release(mCSSNode);
if (mYogaNode != null) {
mYogaNode.reset();
YogaNodePool.get().release(mYogaNode);
}
}
}