Rename java API

Reviewed By: IanChilds

Differential Revision: D4265345

fbshipit-source-id: 69ecfd8fac214f86b8b70647b9b909acd83d78b5
This commit is contained in:
Emil Sjolander
2016-12-03 04:40:23 -08:00
committed by Facebook Github Bot
parent 85ac5fc354
commit b9cedaefa6
16 changed files with 173 additions and 154 deletions

View File

@@ -12,11 +12,11 @@ package com.facebook.csslayout;
import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.proguard.annotations.DoNotStrip;
/** /**
* Inteface for recieving logs from native layer. Use by setting CSSNode.setLogger(myLogger); * Inteface for recieving logs from native layer. Use by setting YogaNode.setLogger(myLogger);
* See YogaLogLevel for the different log levels. * See YogaLogLevel for the different log levels.
*/ */
@DoNotStrip @DoNotStrip
public interface CSSLogger { public interface YogaLogger {
@DoNotStrip @DoNotStrip
void log(YogaLogLevel level, String message); void log(YogaLogLevel level, String message);
} }

View File

@@ -0,0 +1,26 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.csslayout;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public interface YogaMeasureFunction {
/**
* Return a value created by YogaMeasureOutput.make(width, height);
*/
@DoNotStrip
long measure(
YogaNodeAPI node,
float width,
YogaMeasureMode widthMode,
float height,
YogaMeasureMode heightMode);
}

View File

@@ -12,7 +12,7 @@ package com.facebook.csslayout;
/** /**
* Helpers for building measure output value. * Helpers for building measure output value.
*/ */
public class MeasureOutput { public class YogaMeasureOutput {
public static long make(float width, float height) { public static long make(float width, float height) {
return make((int) width, (int) height); return make((int) width, (int) height);

View File

@@ -18,10 +18,10 @@ import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.soloader.SoLoader; import com.facebook.soloader.SoLoader;
@DoNotStrip @DoNotStrip
public class CSSNode implements CSSNodeAPI<CSSNode> { public class YogaNode implements YogaNodeAPI<YogaNode> {
static { static {
SoLoader.loadLibrary("csslayout"); SoLoader.loadLibrary("yoga");
} }
/** /**
@@ -31,7 +31,7 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
static native void jni_YGLog(int level, String message); static native void jni_YGLog(int level, String message);
private static native void jni_YGSetLogger(Object logger); private static native void jni_YGSetLogger(Object logger);
public static void setLogger(CSSLogger logger) { public static void setLogger(YogaLogger logger) {
jni_YGSetLogger(logger); jni_YGSetLogger(logger);
} }
@@ -49,9 +49,9 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
return jni_YGIsExperimentalFeatureEnabled(feature.intValue()); return jni_YGIsExperimentalFeatureEnabled(feature.intValue());
} }
private CSSNode mParent; private YogaNode mParent;
private List<CSSNode> mChildren; private List<YogaNode> mChildren;
private MeasureFunction mMeasureFunction; private YogaMeasureFunction mMeasureFunction;
private long mNativePointer; private long mNativePointer;
private Object mData; private Object mData;
@@ -72,7 +72,7 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
private int mLayoutDirection = 0; private int mLayoutDirection = 0;
private native long jni_YGNodeNew(); private native long jni_YGNodeNew();
public CSSNode() { public YogaNode() {
mNativePointer = jni_YGNodeNew(); mNativePointer = jni_YGNodeNew();
if (mNativePointer == 0) { if (mNativePointer == 0) {
throw new IllegalStateException("Failed to allocate native memory"); throw new IllegalStateException("Failed to allocate native memory");
@@ -115,13 +115,13 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
} }
@Override @Override
public CSSNode getChildAt(int i) { public YogaNode getChildAt(int i) {
return mChildren.get(i); return mChildren.get(i);
} }
private native void jni_YGNodeInsertChild(long nativePointer, long childPointer, int index); private native void jni_YGNodeInsertChild(long nativePointer, long childPointer, int index);
@Override @Override
public void addChildAt(CSSNode child, int i) { public void addChildAt(YogaNode child, int i) {
if (child.mParent != null) { if (child.mParent != null) {
throw new IllegalStateException("Child already has a parent, it must be removed first."); throw new IllegalStateException("Child already has a parent, it must be removed first.");
} }
@@ -136,9 +136,9 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
private native void jni_YGNodeRemoveChild(long nativePointer, long childPointer); private native void jni_YGNodeRemoveChild(long nativePointer, long childPointer);
@Override @Override
public CSSNode removeChildAt(int i) { public YogaNode removeChildAt(int i) {
final CSSNode child = mChildren.remove(i); final YogaNode child = mChildren.remove(i);
child.mParent = null; child.mParent = null;
jni_YGNodeRemoveChild(mNativePointer, child.mNativePointer); jni_YGNodeRemoveChild(mNativePointer, child.mNativePointer);
return child; return child;
@@ -146,12 +146,12 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
@Override @Override
public @Nullable public @Nullable
CSSNode getParent() { YogaNode getParent() {
return mParent; return mParent;
} }
@Override @Override
public int indexOf(CSSNode child) { public int indexOf(YogaNode child) {
return mChildren == null ? -1 : mChildren.indexOf(child); return mChildren == null ? -1 : mChildren.indexOf(child);
} }
@@ -187,7 +187,7 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
private native void jni_YGNodeCopyStyle(long dstNativePointer, long srcNativePointer); private native void jni_YGNodeCopyStyle(long dstNativePointer, long srcNativePointer);
@Override @Override
public void copyStyle(CSSNode srcNode) { public void copyStyle(YogaNode srcNode) {
jni_YGNodeCopyStyle(mNativePointer, srcNode.mNativePointer); jni_YGNodeCopyStyle(mNativePointer, srcNode.mNativePointer);
} }
@@ -508,14 +508,14 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
private native void jni_YGNodeSetHasMeasureFunc(long nativePointer, boolean hasMeasureFunc); private native void jni_YGNodeSetHasMeasureFunc(long nativePointer, boolean hasMeasureFunc);
@Override @Override
public void setMeasureFunction(MeasureFunction measureFunction) { public void setMeasureFunction(YogaMeasureFunction measureFunction) {
mMeasureFunction = measureFunction; mMeasureFunction = measureFunction;
jni_YGNodeSetHasMeasureFunc(mNativePointer, measureFunction != null); jni_YGNodeSetHasMeasureFunc(mNativePointer, measureFunction != null);
} }
// Implementation Note: Why this method needs to stay final // Implementation Note: Why this method needs to stay final
// //
// We cache the jmethodid for this method in CSSLayout code. This means that even if a subclass // We cache the jmethodid for this method in Yoga code. This means that even if a subclass
// were to override measure, we'd still call this implementation from layout code since the // were to override measure, we'd still call this implementation from layout code since the
// overriding method will have a different jmethodid. This is final to prevent that mistake. // overriding method will have a different jmethodid. This is final to prevent that mistake.
@DoNotStrip @DoNotStrip

View File

@@ -9,34 +9,22 @@
package com.facebook.csslayout; package com.facebook.csslayout;
public interface CSSNodeAPI<CSSNodeType extends CSSNodeAPI> { // This only exists for legacy reasons. It will be removed sometime in the near future.
public interface YogaNodeAPI<YogaNodeType extends YogaNodeAPI> {
interface MeasureFunction {
/**
* Return a value created by MeasureOutput.make(width, height);
*/
long measure(
CSSNodeAPI node,
float width,
YogaMeasureMode widthMode,
float height,
YogaMeasureMode heightMode);
}
int getChildCount(); int getChildCount();
CSSNodeType getChildAt(int i); YogaNodeType getChildAt(int i);
void addChildAt(CSSNodeType child, int i); void addChildAt(YogaNodeType child, int i);
CSSNodeType removeChildAt(int i); YogaNodeType removeChildAt(int i);
CSSNodeType getParent(); YogaNodeType getParent();
int indexOf(CSSNodeType child); int indexOf(YogaNodeType child);
void setMeasureFunction(MeasureFunction measureFunction); void setMeasureFunction(YogaMeasureFunction measureFunction);
boolean isMeasureDefined(); boolean isMeasureDefined();
void calculateLayout(); void calculateLayout();
boolean isDirty(); boolean isDirty();
boolean hasNewLayout(); boolean hasNewLayout();
void dirty(); void dirty();
void markLayoutSeen(); void markLayoutSeen();
void copyStyle(CSSNodeType srcNode); void copyStyle(YogaNodeType srcNode);
YogaDirection getStyleDirection(); YogaDirection getStyleDirection();
void setDirection(YogaDirection direction); void setDirection(YogaDirection direction);
YogaFlexDirection getFlexDirection(); YogaFlexDirection getFlexDirection();

View File

@@ -19,8 +19,8 @@ import com.facebook.csslayout.YogaConstants;
import com.facebook.csslayout.YogaDirection; import com.facebook.csslayout.YogaDirection;
import com.facebook.csslayout.YogaFlexDirection; import com.facebook.csslayout.YogaFlexDirection;
import com.facebook.csslayout.YogaJustify; import com.facebook.csslayout.YogaJustify;
import com.facebook.csslayout.CSSNode; import com.facebook.csslayout.YogaMeasureFunction;
import com.facebook.csslayout.CSSNodeAPI; import com.facebook.csslayout.YogaNode;
import com.facebook.csslayout.YogaOverflow; import com.facebook.csslayout.YogaOverflow;
import com.facebook.csslayout.YogaPositionType; import com.facebook.csslayout.YogaPositionType;
import com.facebook.csslayout.YogaWrap; 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 * 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 * for layouting therefore it extends {@link YogaNode} to allow that. They also help with handling
* Common base subclass of {@link CSSNode} for all layout nodes for react-based view. It extends * Common base subclass of {@link YogaNode} for all layout nodes for react-based view. It extends
* {@link CSSNode} by adding additional capabilities. * {@link YogaNode} by adding additional capabilities.
* *
* Instances of this class receive property updates from JS via @{link UIManagerModule}. Subclasses * 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 * 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. * custom subclass of it if necessary.
* *
* The primary use-case for {@link ReactShadowNode} nodes is to calculate layouting. Although this * 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 * 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 * 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 float mAbsoluteBottom;
private final Spacing mDefaultPadding = new Spacing(0); private final Spacing mDefaultPadding = new Spacing(0);
private final Spacing mPadding = new Spacing(YogaConstants.UNDEFINED); private final Spacing mPadding = new Spacing(YogaConstants.UNDEFINED);
private final CSSNode mCSSNode; private final YogaNode mYogaNode;
public ReactShadowNode() { public ReactShadowNode() {
if (!isVirtual()) { if (!isVirtual()) {
CSSNode node = CSSNodePool.get().acquire(); YogaNode node = YogaNodePool.get().acquire();
if (node == null) { if (node == null) {
node = new CSSNode(); node = new YogaNode();
} }
mCSSNode = node; mYogaNode = node;
} else { } else {
mCSSNode = null; mYogaNode = null;
} }
} }
@@ -138,12 +138,12 @@ public class ReactShadowNode {
public void dirty() { public void dirty() {
if (!isVirtual()) { if (!isVirtual()) {
mCSSNode.dirty(); mYogaNode.dirty();
} }
} }
public final boolean isDirty() { public final boolean isDirty() {
return mCSSNode != null && mCSSNode.isDirty(); return mYogaNode != null && mYogaNode.isDirty();
} }
public void addChildAt(ReactShadowNode child, int i) { 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 // 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. // more, it asserts that you don't add children to nodes with measure functions.
if (mCSSNode != null && !mCSSNode.isMeasureDefined()) { if (mYogaNode != null && !mYogaNode.isMeasureDefined()) {
CSSNode childCSSNode = child.mCSSNode; YogaNode childYogaNode = child.mYogaNode;
if (childCSSNode == null) { if (childYogaNode == null) {
throw new RuntimeException( throw new RuntimeException(
"Cannot add a child that doesn't have a CSS node to a node without a measure function!"); "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(); markUpdated();
@@ -183,8 +183,8 @@ public class ReactShadowNode {
ReactShadowNode removed = mChildren.remove(i); ReactShadowNode removed = mChildren.remove(i);
removed.mParent = null; removed.mParent = null;
if (mCSSNode != null && !mCSSNode.isMeasureDefined()) { if (mYogaNode != null && !mYogaNode.isMeasureDefined()) {
mCSSNode.removeChildAt(i); mYogaNode.removeChildAt(i);
} }
markUpdated(); markUpdated();
@@ -217,8 +217,8 @@ public class ReactShadowNode {
int decrease = 0; int decrease = 0;
for (int i = getChildCount() - 1; i >= 0; i--) { for (int i = getChildCount() - 1; i >= 0; i--) {
if (mCSSNode != null && !mCSSNode.isMeasureDefined()) { if (mYogaNode != null && !mYogaNode.isMeasureDefined()) {
mCSSNode.removeChildAt(i); mYogaNode.removeChildAt(i);
} }
ReactShadowNode toRemove = getChildAt(i); ReactShadowNode toRemove = getChildAt(i);
toRemove.mParent = null; toRemove.mParent = null;
@@ -339,16 +339,16 @@ public class ReactShadowNode {
} }
public void calculateLayout() { public void calculateLayout() {
mCSSNode.calculateLayout(); mYogaNode.calculateLayout();
} }
public final boolean hasNewLayout() { public final boolean hasNewLayout() {
return mCSSNode == null ? false : mCSSNode.hasNewLayout(); return mYogaNode == null ? false : mYogaNode.hasNewLayout();
} }
public final void markLayoutSeen() { public final void markLayoutSeen() {
if (mCSSNode != null) { if (mYogaNode != null) {
mCSSNode.markLayoutSeen(); mYogaNode.markLayoutSeen();
} }
} }
@@ -463,19 +463,19 @@ public class ReactShadowNode {
} }
public final float getLayoutX() { public final float getLayoutX() {
return mCSSNode.getLayoutX(); return mYogaNode.getLayoutX();
} }
public final float getLayoutY() { public final float getLayoutY() {
return mCSSNode.getLayoutY(); return mYogaNode.getLayoutY();
} }
public final float getLayoutWidth() { public final float getLayoutWidth() {
return mCSSNode.getLayoutWidth(); return mYogaNode.getLayoutWidth();
} }
public final float getLayoutHeight() { public final float getLayoutHeight() {
return mCSSNode.getLayoutHeight(); return mYogaNode.getLayoutHeight();
} }
/** /**
@@ -507,95 +507,95 @@ public class ReactShadowNode {
} }
public final YogaDirection getLayoutDirection() { public final YogaDirection getLayoutDirection() {
return mCSSNode.getLayoutDirection(); return mYogaNode.getLayoutDirection();
} }
public void setLayoutDirection(YogaDirection direction) { public void setLayoutDirection(YogaDirection direction) {
mCSSNode.setDirection(direction); mYogaNode.setDirection(direction);
} }
public final float getStyleWidth() { public final float getStyleWidth() {
return mCSSNode.getWidth(); return mYogaNode.getWidth();
} }
public void setStyleWidth(float widthPx) { public void setStyleWidth(float widthPx) {
mCSSNode.setWidth(widthPx); mYogaNode.setWidth(widthPx);
} }
public void setStyleMinWidth(float widthPx) { public void setStyleMinWidth(float widthPx) {
mCSSNode.setMinWidth(widthPx); mYogaNode.setMinWidth(widthPx);
} }
public void setStyleMaxWidth(float widthPx) { public void setStyleMaxWidth(float widthPx) {
mCSSNode.setMaxWidth(widthPx); mYogaNode.setMaxWidth(widthPx);
} }
public final float getStyleHeight() { public final float getStyleHeight() {
return mCSSNode.getHeight(); return mYogaNode.getHeight();
} }
public void setStyleHeight(float heightPx) { public void setStyleHeight(float heightPx) {
mCSSNode.setHeight(heightPx); mYogaNode.setHeight(heightPx);
} }
public void setStyleMinHeight(float widthPx) { public void setStyleMinHeight(float widthPx) {
mCSSNode.setMinHeight(widthPx); mYogaNode.setMinHeight(widthPx);
} }
public void setStyleMaxHeight(float widthPx) { public void setStyleMaxHeight(float widthPx) {
mCSSNode.setMaxHeight(widthPx); mYogaNode.setMaxHeight(widthPx);
} }
public void setFlex(float flex) { public void setFlex(float flex) {
mCSSNode.setFlex(flex); mYogaNode.setFlex(flex);
} }
public void setFlexGrow(float flexGrow) { public void setFlexGrow(float flexGrow) {
mCSSNode.setFlexGrow(flexGrow); mYogaNode.setFlexGrow(flexGrow);
} }
public void setFlexShrink(float flexShrink) { public void setFlexShrink(float flexShrink) {
mCSSNode.setFlexShrink(flexShrink); mYogaNode.setFlexShrink(flexShrink);
} }
public void setFlexBasis(float flexBasis) { public void setFlexBasis(float flexBasis) {
mCSSNode.setFlexBasis(flexBasis); mYogaNode.setFlexBasis(flexBasis);
} }
public void setStyleAspectRatio(float aspectRatio) { public void setStyleAspectRatio(float aspectRatio) {
mCSSNode.setAspectRatio(aspectRatio); mYogaNode.setAspectRatio(aspectRatio);
} }
public void setFlexDirection(YogaFlexDirection flexDirection) { public void setFlexDirection(YogaFlexDirection flexDirection) {
mCSSNode.setFlexDirection(flexDirection); mYogaNode.setFlexDirection(flexDirection);
} }
public void setFlexWrap(YogaWrap wrap) { public void setFlexWrap(YogaWrap wrap) {
mCSSNode.setWrap(wrap); mYogaNode.setWrap(wrap);
} }
public void setAlignSelf(YogaAlign alignSelf) { public void setAlignSelf(YogaAlign alignSelf) {
mCSSNode.setAlignSelf(alignSelf); mYogaNode.setAlignSelf(alignSelf);
} }
public void setAlignItems(YogaAlign alignItems) { public void setAlignItems(YogaAlign alignItems) {
mCSSNode.setAlignItems(alignItems); mYogaNode.setAlignItems(alignItems);
} }
public void setJustifyContent(YogaJustify justifyContent) { public void setJustifyContent(YogaJustify justifyContent) {
mCSSNode.setJustifyContent(justifyContent); mYogaNode.setJustifyContent(justifyContent);
} }
public void setOverflow(YogaOverflow overflow) { public void setOverflow(YogaOverflow overflow) {
mCSSNode.setOverflow(overflow); mYogaNode.setOverflow(overflow);
} }
public void setMargin(int spacingType, float margin) { 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) { 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) { public void setDefaultPadding(int spacingType, float padding) {
@@ -617,63 +617,63 @@ public class ReactShadowNode {
if (YogaConstants.isUndefined(mPadding.getRaw(spacingType)) && if (YogaConstants.isUndefined(mPadding.getRaw(spacingType)) &&
YogaConstants.isUndefined(mPadding.getRaw(Spacing.HORIZONTAL)) && YogaConstants.isUndefined(mPadding.getRaw(Spacing.HORIZONTAL)) &&
YogaConstants.isUndefined(mPadding.getRaw(Spacing.ALL))) { YogaConstants.isUndefined(mPadding.getRaw(Spacing.ALL))) {
mCSSNode.setPadding(YogaEdge.fromInt(spacingType), mDefaultPadding.getRaw(spacingType)); mYogaNode.setPadding(YogaEdge.fromInt(spacingType), mDefaultPadding.getRaw(spacingType));
} else { } 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) { } else if (spacingType == Spacing.TOP || spacingType == Spacing.BOTTOM) {
if (YogaConstants.isUndefined(mPadding.getRaw(spacingType)) && if (YogaConstants.isUndefined(mPadding.getRaw(spacingType)) &&
YogaConstants.isUndefined(mPadding.getRaw(Spacing.VERTICAL)) && YogaConstants.isUndefined(mPadding.getRaw(Spacing.VERTICAL)) &&
YogaConstants.isUndefined(mPadding.getRaw(Spacing.ALL))) { YogaConstants.isUndefined(mPadding.getRaw(Spacing.ALL))) {
mCSSNode.setPadding(YogaEdge.fromInt(spacingType), mDefaultPadding.getRaw(spacingType)); mYogaNode.setPadding(YogaEdge.fromInt(spacingType), mDefaultPadding.getRaw(spacingType));
} else { } else {
mCSSNode.setPadding(YogaEdge.fromInt(spacingType), mPadding.getRaw(spacingType)); mYogaNode.setPadding(YogaEdge.fromInt(spacingType), mPadding.getRaw(spacingType));
} }
} else { } else {
if (YogaConstants.isUndefined(mPadding.getRaw(spacingType))) { if (YogaConstants.isUndefined(mPadding.getRaw(spacingType))) {
mCSSNode.setPadding(YogaEdge.fromInt(spacingType), mDefaultPadding.getRaw(spacingType)); mYogaNode.setPadding(YogaEdge.fromInt(spacingType), mDefaultPadding.getRaw(spacingType));
} else { } else {
mCSSNode.setPadding(YogaEdge.fromInt(spacingType), mPadding.getRaw(spacingType)); mYogaNode.setPadding(YogaEdge.fromInt(spacingType), mPadding.getRaw(spacingType));
} }
} }
} }
} }
public void setBorder(int spacingType, float borderWidth) { 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) { public void setPosition(int spacingType, float position) {
mCSSNode.setPosition(YogaEdge.fromInt(spacingType), position); mYogaNode.setPosition(YogaEdge.fromInt(spacingType), position);
} }
public void setPositionType(YogaPositionType positionType) { public void setPositionType(YogaPositionType positionType) {
mCSSNode.setPositionType(positionType); mYogaNode.setPositionType(positionType);
} }
public void setShouldNotifyOnLayout(boolean shouldNotifyOnLayout) { public void setShouldNotifyOnLayout(boolean shouldNotifyOnLayout) {
mShouldNotifyOnLayout = shouldNotifyOnLayout; mShouldNotifyOnLayout = shouldNotifyOnLayout;
} }
public void setMeasureFunction(CSSNodeAPI.MeasureFunction measureFunction) { public void setMeasureFunction(YogaMeasureFunction measureFunction) {
if ((measureFunction == null ^ mCSSNode.isMeasureDefined()) && if ((measureFunction == null ^ mYogaNode.isMeasureDefined()) &&
getChildCount() != 0) { getChildCount() != 0) {
throw new RuntimeException( throw new RuntimeException(
"Since a node with a measure function does not add any native CSSLayout children, it's " + "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"); "not safe to transition to/from having a measure function unless a node has no children");
} }
mCSSNode.setMeasureFunction(measureFunction); mYogaNode.setMeasureFunction(measureFunction);
} }
@Override @Override
public String toString() { public String toString() {
return mCSSNode.toString(); return mYogaNode.toString();
} }
public void dispose() { public void dispose() {
if (mCSSNode != null) { if (mYogaNode != null) {
mCSSNode.reset(); mYogaNode.reset();
CSSNodePool.get().release(mCSSNode); YogaNodePool.get().release(mYogaNode);
} }
} }
} }

View File

@@ -144,7 +144,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
mEventDispatcher.onCatalystInstanceDestroyed(); mEventDispatcher.onCatalystInstanceDestroyed();
getReactApplicationContext().unregisterComponentCallbacks(mMemoryTrimCallback); getReactApplicationContext().unregisterComponentCallbacks(mMemoryTrimCallback);
CSSNodePool.get().clear(); YogaNodePool.get().clear();
} }
private static Map<String, Object> createConstants(List<ViewManager> viewManagerList) { private static Map<String, Object> createConstants(List<ViewManager> viewManagerList) {
@@ -570,7 +570,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
@Override @Override
public void onTrimMemory(int level) { public void onTrimMemory(int level) {
if (level >= TRIM_MEMORY_MODERATE) { if (level >= TRIM_MEMORY_MODERATE) {
CSSNodePool.get().clear(); YogaNodePool.get().clear();
} }
} }

View File

@@ -2,25 +2,25 @@
package com.facebook.react.uimanager; package com.facebook.react.uimanager;
import com.facebook.csslayout.CSSNode; import com.facebook.csslayout.YogaNode;
import com.facebook.react.common.ClearableSynchronizedPool; import com.facebook.react.common.ClearableSynchronizedPool;
/** /**
* Static holder for a recycling pool of CSSNodes. * Static holder for a recycling pool of YogaNodes.
*/ */
public class CSSNodePool { public class YogaNodePool {
private static final Object sInitLock = new Object(); private static final Object sInitLock = new Object();
private static ClearableSynchronizedPool<CSSNode> sPool; private static ClearableSynchronizedPool<YogaNode> sPool;
public static ClearableSynchronizedPool<CSSNode> get() { public static ClearableSynchronizedPool<YogaNode> get() {
if (sPool != null) { if (sPool != null) {
return sPool; return sPool;
} }
synchronized (sInitLock) { synchronized (sInitLock) {
if (sPool == null) { if (sPool == null) {
sPool = new ClearableSynchronizedPool<CSSNode>(1024); sPool = new ClearableSynchronizedPool<YogaNode>(1024);
} }
return sPool; return sPool;
} }

View File

@@ -10,8 +10,8 @@
package com.facebook.react.views.art; package com.facebook.react.views.art;
import com.facebook.csslayout.YogaMeasureMode; import com.facebook.csslayout.YogaMeasureMode;
import com.facebook.csslayout.CSSNodeAPI; import com.facebook.csslayout.YogaMeasureFunction;
import com.facebook.csslayout.MeasureOutput; import com.facebook.csslayout.YogaNodeAPI;
import com.facebook.react.module.annotations.ReactModule; import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.BaseViewManager; import com.facebook.react.uimanager.BaseViewManager;
import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.ThemedReactContext;
@@ -26,10 +26,10 @@ public class ARTSurfaceViewManager extends
protected static final String REACT_CLASS = "ARTSurfaceView"; protected static final String REACT_CLASS = "ARTSurfaceView";
private static final CSSNodeAPI.MeasureFunction MEASURE_FUNCTION = new CSSNodeAPI.MeasureFunction() { private static final YogaMeasureFunction MEASURE_FUNCTION = new YogaMeasureFunction() {
@Override @Override
public long measure( public long measure(
CSSNodeAPI node, YogaNodeAPI node,
float width, float width,
YogaMeasureMode widthMode, YogaMeasureMode widthMode,
float height, float height,

View File

@@ -20,8 +20,9 @@ import android.view.ViewGroup;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import com.facebook.csslayout.YogaMeasureMode; import com.facebook.csslayout.YogaMeasureMode;
import com.facebook.csslayout.CSSNodeAPI; import com.facebook.csslayout.YogaMeasureFunction;
import com.facebook.csslayout.MeasureOutput; import com.facebook.csslayout.YogaNodeAPI;
import com.facebook.csslayout.YogaMeasureOutput;
import com.facebook.react.uimanager.LayoutShadowNode; import com.facebook.react.uimanager.LayoutShadowNode;
import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.uimanager.annotations.ReactProp;
@@ -30,7 +31,7 @@ import com.facebook.react.uimanager.annotations.ReactProp;
* {@link android.R.attr.progressBarStyle} for possible styles. ReactProgressBarViewManager * {@link android.R.attr.progressBarStyle} for possible styles. ReactProgressBarViewManager
* manages how this style is applied to the ProgressBar. * manages how this style is applied to the ProgressBar.
*/ */
public class ProgressBarShadowNode extends LayoutShadowNode implements CSSNodeAPI.MeasureFunction { public class ProgressBarShadowNode extends LayoutShadowNode implements YogaMeasureFunction {
private String mStyle = ReactProgressBarViewManager.DEFAULT_STYLE; private String mStyle = ReactProgressBarViewManager.DEFAULT_STYLE;
@@ -53,7 +54,7 @@ public class ProgressBarShadowNode extends LayoutShadowNode implements CSSNodeAP
@Override @Override
public long measure( public long measure(
CSSNodeAPI node, YogaNodeAPI node,
float width, float width,
YogaMeasureMode widthMode, YogaMeasureMode widthMode,
float height, float height,
@@ -70,6 +71,6 @@ public class ProgressBarShadowNode extends LayoutShadowNode implements CSSNodeAP
mMeasured.add(style); mMeasured.add(style);
} }
return MeasureOutput.make(mWidth.get(style), mHeight.get(style)); return YogaMeasureOutput.make(mWidth.get(style), mHeight.get(style));
} }
} }

View File

@@ -16,8 +16,9 @@ import android.view.ViewGroup;
import android.widget.SeekBar; import android.widget.SeekBar;
import com.facebook.csslayout.YogaMeasureMode; import com.facebook.csslayout.YogaMeasureMode;
import com.facebook.csslayout.CSSNodeAPI; import com.facebook.csslayout.YogaMeasureFunction;
import com.facebook.csslayout.MeasureOutput; import com.facebook.csslayout.YogaNodeAPI;
import com.facebook.csslayout.YogaMeasureOutput;
import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReactContext;
import com.facebook.react.common.MapBuilder; import com.facebook.react.common.MapBuilder;
import com.facebook.react.uimanager.LayoutShadowNode; import com.facebook.react.uimanager.LayoutShadowNode;
@@ -39,7 +40,7 @@ public class ReactSliderManager extends SimpleViewManager<ReactSlider> {
private static final String REACT_CLASS = "RCTSlider"; private static final String REACT_CLASS = "RCTSlider";
static class ReactSliderShadowNode extends LayoutShadowNode implements static class ReactSliderShadowNode extends LayoutShadowNode implements
CSSNodeAPI.MeasureFunction { YogaMeasureFunction {
private int mWidth; private int mWidth;
private int mHeight; private int mHeight;
@@ -51,7 +52,7 @@ public class ReactSliderManager extends SimpleViewManager<ReactSlider> {
@Override @Override
public long measure( public long measure(
CSSNodeAPI node, YogaNodeAPI node,
float width, float width,
YogaMeasureMode widthMode, YogaMeasureMode widthMode,
float height, float height,
@@ -67,7 +68,7 @@ public class ReactSliderManager extends SimpleViewManager<ReactSlider> {
mMeasured = true; mMeasured = true;
} }
return MeasureOutput.make(mWidth, mHeight); return YogaMeasureOutput.make(mWidth, mHeight);
} }
} }
@@ -79,7 +80,7 @@ public class ReactSliderManager extends SimpleViewManager<ReactSlider> {
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent( reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
new ReactSliderEvent( new ReactSliderEvent(
seekbar.getId(), seekbar.getId(),
((ReactSlider)seekbar).toRealProgress(progress), ((ReactSlider) seekbar).toRealProgress(progress),
fromUser)); fromUser));
} }
@@ -93,7 +94,7 @@ public class ReactSliderManager extends SimpleViewManager<ReactSlider> {
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent( reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
new ReactSlidingCompleteEvent( new ReactSlidingCompleteEvent(
seekbar.getId(), seekbar.getId(),
((ReactSlider)seekbar).toRealProgress(seekbar.getProgress()))); ((ReactSlider) seekbar).toRealProgress(seekbar.getProgress())));
} }
}; };

View File

@@ -15,8 +15,9 @@ import android.view.ViewGroup;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import com.facebook.csslayout.YogaMeasureMode; import com.facebook.csslayout.YogaMeasureMode;
import com.facebook.csslayout.CSSNodeAPI; import com.facebook.csslayout.YogaMeasureFunction;
import com.facebook.csslayout.MeasureOutput; import com.facebook.csslayout.YogaNodeAPI;
import com.facebook.csslayout.YogaMeasureOutput;
import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReactContext;
import com.facebook.react.uimanager.LayoutShadowNode; import com.facebook.react.uimanager.LayoutShadowNode;
import com.facebook.react.uimanager.SimpleViewManager; import com.facebook.react.uimanager.SimpleViewManager;
@@ -33,7 +34,7 @@ public class ReactSwitchManager extends SimpleViewManager<ReactSwitch> {
private static final String REACT_CLASS = "AndroidSwitch"; private static final String REACT_CLASS = "AndroidSwitch";
static class ReactSwitchShadowNode extends LayoutShadowNode implements static class ReactSwitchShadowNode extends LayoutShadowNode implements
CSSNodeAPI.MeasureFunction { YogaMeasureFunction {
private int mWidth; private int mWidth;
private int mHeight; private int mHeight;
@@ -45,7 +46,7 @@ public class ReactSwitchManager extends SimpleViewManager<ReactSwitch> {
@Override @Override
public long measure( public long measure(
CSSNodeAPI node, YogaNodeAPI node,
float width, float width,
YogaMeasureMode widthMode, YogaMeasureMode widthMode,
float height, float height,
@@ -64,7 +65,7 @@ public class ReactSwitchManager extends SimpleViewManager<ReactSwitch> {
mMeasured = true; mMeasured = true;
} }
return MeasureOutput.make(mWidth, mHeight); return YogaMeasureOutput.make(mWidth, mHeight);
} }
} }

View File

@@ -9,11 +9,11 @@
package com.facebook.react.views.text; package com.facebook.react.views.text;
import com.facebook.csslayout.CSSNode; import com.facebook.csslayout.YogaNode;
import com.facebook.react.uimanager.LayoutShadowNode; import com.facebook.react.uimanager.LayoutShadowNode;
/** /**
* Base class for {@link CSSNode}s that represent inline images. * Base class for {@link YogaNode}s that represent inline images.
*/ */
public abstract class ReactTextInlineImageShadowNode extends LayoutShadowNode { public abstract class ReactTextInlineImageShadowNode extends LayoutShadowNode {

View File

@@ -33,8 +33,9 @@ import android.widget.TextView;
import com.facebook.csslayout.YogaDirection; import com.facebook.csslayout.YogaDirection;
import com.facebook.csslayout.YogaConstants; import com.facebook.csslayout.YogaConstants;
import com.facebook.csslayout.YogaMeasureMode; import com.facebook.csslayout.YogaMeasureMode;
import com.facebook.csslayout.CSSNodeAPI; import com.facebook.csslayout.YogaMeasureFunction;
import com.facebook.csslayout.MeasureOutput; import com.facebook.csslayout.YogaNodeAPI;
import com.facebook.csslayout.YogaMeasureOutput;
import com.facebook.infer.annotation.Assertions; import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException; import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableMap;
@@ -218,11 +219,11 @@ public class ReactTextShadowNode extends LayoutShadowNode {
return sb; return sb;
} }
private final CSSNodeAPI.MeasureFunction mTextMeasureFunction = private final YogaMeasureFunction mTextMeasureFunction =
new CSSNodeAPI.MeasureFunction() { new YogaMeasureFunction() {
@Override @Override
public long measure( public long measure(
CSSNodeAPI node, YogaNodeAPI node,
float width, float width,
YogaMeasureMode widthMode, YogaMeasureMode widthMode,
float height, float height,
@@ -279,11 +280,11 @@ public class ReactTextShadowNode extends LayoutShadowNode {
if (mNumberOfLines != UNSET && if (mNumberOfLines != UNSET &&
mNumberOfLines < layout.getLineCount()) { mNumberOfLines < layout.getLineCount()) {
return MeasureOutput.make( return YogaMeasureOutput.make(
layout.getWidth(), layout.getWidth(),
layout.getLineBottom(mNumberOfLines - 1)); layout.getLineBottom(mNumberOfLines - 1));
} else { } else {
return MeasureOutput.make(layout.getWidth(), layout.getHeight()); return YogaMeasureOutput.make(layout.getWidth(), layout.getHeight());
} }
} }
}; };

View File

@@ -18,8 +18,9 @@ import android.widget.EditText;
import com.facebook.csslayout.YogaDirection; import com.facebook.csslayout.YogaDirection;
import com.facebook.csslayout.YogaMeasureMode; import com.facebook.csslayout.YogaMeasureMode;
import com.facebook.csslayout.CSSNodeAPI; import com.facebook.csslayout.YogaMeasureFunction;
import com.facebook.csslayout.MeasureOutput; import com.facebook.csslayout.YogaNodeAPI;
import com.facebook.csslayout.YogaMeasureOutput;
import com.facebook.infer.annotation.Assertions; import com.facebook.infer.annotation.Assertions;
import com.facebook.react.common.annotations.VisibleForTesting; import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.PixelUtil;
@@ -34,7 +35,7 @@ import com.facebook.react.views.text.ReactTextUpdate;
@VisibleForTesting @VisibleForTesting
public class ReactTextInputShadowNode extends ReactTextShadowNode implements public class ReactTextInputShadowNode extends ReactTextShadowNode implements
CSSNodeAPI.MeasureFunction { YogaMeasureFunction {
private @Nullable EditText mEditText; private @Nullable EditText mEditText;
private @Nullable float[] mComputedPadding; private @Nullable float[] mComputedPadding;
@@ -71,7 +72,7 @@ public class ReactTextInputShadowNode extends ReactTextShadowNode implements
@Override @Override
public long measure( public long measure(
CSSNodeAPI node, YogaNodeAPI node,
float width, float width,
YogaMeasureMode widthMode, YogaMeasureMode widthMode,
float height, float height,
@@ -103,7 +104,7 @@ public class ReactTextInputShadowNode extends ReactTextShadowNode implements
MeasureUtil.getMeasureSpec(width, widthMode), MeasureUtil.getMeasureSpec(width, widthMode),
MeasureUtil.getMeasureSpec(height, heightMode)); MeasureUtil.getMeasureSpec(height, heightMode));
return MeasureOutput.make(editText.getMeasuredWidth(), editText.getMeasuredHeight()); return YogaMeasureOutput.make(editText.getMeasuredWidth(), editText.getMeasuredHeight());
} }
@Override @Override

View File

@@ -58,7 +58,7 @@ static YGSize YGJNIMeasureFunc(YGNodeRef node,
float height, float height,
YGMeasureMode heightMode) { YGMeasureMode heightMode) {
if (auto obj = YGNodeJobject(node)->lockLocal()) { if (auto obj = YGNodeJobject(node)->lockLocal()) {
static auto measureFunc = findClassLocal("com/facebook/csslayout/CSSNode") static auto measureFunc = findClassLocal("com/facebook/csslayout/YogaNode")
->getMethod<jlong(jfloat, jint, jfloat, jint)>("measure"); ->getMethod<jlong(jfloat, jint, jfloat, jint)>("measure");
YGTransferLayoutDirection(node, obj); YGTransferLayoutDirection(node, obj);
@@ -89,7 +89,7 @@ static int YGLog(YGLogLevel level, const char *format, va_list args) {
char buffer[256]; char buffer[256];
int result = vsnprintf(buffer, sizeof(buffer), format, args); int result = vsnprintf(buffer, sizeof(buffer), format, args);
static auto logFunc = findClassLocal("com/facebook/csslayout/CSSLogger") static auto logFunc = findClassLocal("com/facebook/csslayout/YogaLogger")
->getMethod<void(local_ref<JYogaLogLevel>, jstring)>("log"); ->getMethod<void(local_ref<JYogaLogLevel>, jstring)>("log");
static auto logLevelFromInt = static auto logLevelFromInt =
@@ -261,7 +261,7 @@ YG_NODE_JNI_STYLE_PROP(jfloat, float, AspectRatio);
jint JNI_OnLoad(JavaVM *vm, void *) { jint JNI_OnLoad(JavaVM *vm, void *) {
return initialize(vm, [] { return initialize(vm, [] {
registerNatives("com/facebook/csslayout/CSSNode", registerNatives("com/facebook/csslayout/YogaNode",
{ {
YGMakeNativeMethod(jni_YGNodeNew), YGMakeNativeMethod(jni_YGNodeNew),
YGMakeNativeMethod(jni_YGNodeFree), YGMakeNativeMethod(jni_YGNodeFree),