not setting flags when setting margin, padding, border and position on yoga node

Summary: We are now not setting flags when we set style inputs margin, padding, border and position on yoga node.

Reviewed By: davidaurelio

Differential Revision: D14224000

fbshipit-source-id: deef4c1ab1a60fbc4909183bc2aa59fa23939d43
This commit is contained in:
Sidharth Guglani
2019-02-28 12:42:21 -08:00
committed by Facebook Github Bot
parent 15668aceb6
commit 8b8d9a05b7
2 changed files with 19 additions and 63 deletions

View File

@@ -36,10 +36,6 @@ public class YogaNodeJNI extends YogaNode {
private static final int PADDING = 2; private static final int PADDING = 2;
private static final int BORDER = 4; private static final int BORDER = 4;
@DoNotStrip
private int mEdgeSetFlag = 0;
private boolean mHasSetPosition = false;
private final boolean mAvoidGlobalJNIRefs; private final boolean mAvoidGlobalJNIRefs;
@DoNotStrip @DoNotStrip
@@ -120,8 +116,6 @@ public class YogaNodeJNI extends YogaNode {
private static native void jni_YGNodeReset(long nativePointer); private static native void jni_YGNodeReset(long nativePointer);
public void reset() { public void reset() {
mEdgeSetFlag = 0;
mHasSetPosition = false;
mHasNewLayout = true; mHasNewLayout = true;
mWidth = YogaConstants.UNDEFINED; mWidth = YogaConstants.UNDEFINED;
@@ -429,81 +423,61 @@ public class YogaNodeJNI extends YogaNode {
private static native Object jni_YGNodeStyleGetMargin(long nativePointer, int edge); private static native Object jni_YGNodeStyleGetMargin(long nativePointer, int edge);
public YogaValue getMargin(YogaEdge edge) { public YogaValue getMargin(YogaEdge edge) {
if (!((mEdgeSetFlag & MARGIN) == MARGIN)) {
return YogaValue.UNDEFINED;
}
return (YogaValue) jni_YGNodeStyleGetMargin(mNativePointer, edge.intValue()); return (YogaValue) jni_YGNodeStyleGetMargin(mNativePointer, edge.intValue());
} }
private static native void jni_YGNodeStyleSetMargin(long nativePointer, int edge, float margin); private static native void jni_YGNodeStyleSetMargin(long nativePointer, int edge, float margin);
public void setMargin(YogaEdge edge, float margin) { public void setMargin(YogaEdge edge, float margin) {
mEdgeSetFlag |= MARGIN;
jni_YGNodeStyleSetMargin(mNativePointer, edge.intValue(), margin); jni_YGNodeStyleSetMargin(mNativePointer, edge.intValue(), margin);
} }
private static native void jni_YGNodeStyleSetMarginPercent(long nativePointer, int edge, float percent); private static native void jni_YGNodeStyleSetMarginPercent(long nativePointer, int edge, float percent);
public void setMarginPercent(YogaEdge edge, float percent) { public void setMarginPercent(YogaEdge edge, float percent) {
mEdgeSetFlag |= MARGIN;
jni_YGNodeStyleSetMarginPercent(mNativePointer, edge.intValue(), percent); jni_YGNodeStyleSetMarginPercent(mNativePointer, edge.intValue(), percent);
} }
private static native void jni_YGNodeStyleSetMarginAuto(long nativePointer, int edge); private static native void jni_YGNodeStyleSetMarginAuto(long nativePointer, int edge);
public void setMarginAuto(YogaEdge edge) { public void setMarginAuto(YogaEdge edge) {
mEdgeSetFlag |= MARGIN;
jni_YGNodeStyleSetMarginAuto(mNativePointer, edge.intValue()); jni_YGNodeStyleSetMarginAuto(mNativePointer, edge.intValue());
} }
private static native Object jni_YGNodeStyleGetPadding(long nativePointer, int edge); private static native Object jni_YGNodeStyleGetPadding(long nativePointer, int edge);
public YogaValue getPadding(YogaEdge edge) { public YogaValue getPadding(YogaEdge edge) {
if (!((mEdgeSetFlag & PADDING) == PADDING)) {
return YogaValue.UNDEFINED;
}
return (YogaValue) jni_YGNodeStyleGetPadding(mNativePointer, edge.intValue()); return (YogaValue) jni_YGNodeStyleGetPadding(mNativePointer, edge.intValue());
} }
private static native void jni_YGNodeStyleSetPadding(long nativePointer, int edge, float padding); private static native void jni_YGNodeStyleSetPadding(long nativePointer, int edge, float padding);
public void setPadding(YogaEdge edge, float padding) { public void setPadding(YogaEdge edge, float padding) {
mEdgeSetFlag |= PADDING;
jni_YGNodeStyleSetPadding(mNativePointer, edge.intValue(), padding); jni_YGNodeStyleSetPadding(mNativePointer, edge.intValue(), padding);
} }
private static native void jni_YGNodeStyleSetPaddingPercent(long nativePointer, int edge, float percent); private static native void jni_YGNodeStyleSetPaddingPercent(long nativePointer, int edge, float percent);
public void setPaddingPercent(YogaEdge edge, float percent) { public void setPaddingPercent(YogaEdge edge, float percent) {
mEdgeSetFlag |= PADDING;
jni_YGNodeStyleSetPaddingPercent(mNativePointer, edge.intValue(), percent); jni_YGNodeStyleSetPaddingPercent(mNativePointer, edge.intValue(), percent);
} }
private static native float jni_YGNodeStyleGetBorder(long nativePointer, int edge); private static native float jni_YGNodeStyleGetBorder(long nativePointer, int edge);
public float getBorder(YogaEdge edge) { public float getBorder(YogaEdge edge) {
if (!((mEdgeSetFlag & BORDER) == BORDER)) {
return YogaConstants.UNDEFINED;
}
return jni_YGNodeStyleGetBorder(mNativePointer, edge.intValue()); return jni_YGNodeStyleGetBorder(mNativePointer, edge.intValue());
} }
private static native void jni_YGNodeStyleSetBorder(long nativePointer, int edge, float border); private static native void jni_YGNodeStyleSetBorder(long nativePointer, int edge, float border);
public void setBorder(YogaEdge edge, float border) { public void setBorder(YogaEdge edge, float border) {
mEdgeSetFlag |= BORDER;
jni_YGNodeStyleSetBorder(mNativePointer, edge.intValue(), border); jni_YGNodeStyleSetBorder(mNativePointer, edge.intValue(), border);
} }
private static native Object jni_YGNodeStyleGetPosition(long nativePointer, int edge); private static native Object jni_YGNodeStyleGetPosition(long nativePointer, int edge);
public YogaValue getPosition(YogaEdge edge) { public YogaValue getPosition(YogaEdge edge) {
if (!mHasSetPosition) {
return YogaValue.UNDEFINED;
}
return (YogaValue) jni_YGNodeStyleGetPosition(mNativePointer, edge.intValue()); return (YogaValue) jni_YGNodeStyleGetPosition(mNativePointer, edge.intValue());
} }
private static native void jni_YGNodeStyleSetPosition(long nativePointer, int edge, float position); private static native void jni_YGNodeStyleSetPosition(long nativePointer, int edge, float position);
public void setPosition(YogaEdge edge, float position) { public void setPosition(YogaEdge edge, float position) {
mHasSetPosition = true;
jni_YGNodeStyleSetPosition(mNativePointer, edge.intValue(), position); jni_YGNodeStyleSetPosition(mNativePointer, edge.intValue(), position);
} }
private static native void jni_YGNodeStyleSetPositionPercent(long nativePointer, int edge, float percent); private static native void jni_YGNodeStyleSetPositionPercent(long nativePointer, int edge, float percent);
public void setPositionPercent(YogaEdge edge, float percent) { public void setPositionPercent(YogaEdge edge, float percent) {
mHasSetPosition = true;
jni_YGNodeStyleSetPositionPercent(mNativePointer, edge.intValue(), percent); jni_YGNodeStyleSetPositionPercent(mNativePointer, edge.intValue(), percent);
} }

View File

@@ -129,20 +129,11 @@ static void YGTransferLayoutOutputsRecursive(
static auto borderBottomField = static auto borderBottomField =
obj->getClass()->getField<jfloat>("mBorderBottom"); obj->getClass()->getField<jfloat>("mBorderBottom");
static auto edgeSetFlagField =
obj->getClass()->getField<jint>("mEdgeSetFlag");
static auto hasNewLayoutField = static auto hasNewLayoutField =
obj->getClass()->getField<jboolean>("mHasNewLayout"); obj->getClass()->getField<jboolean>("mHasNewLayout");
static auto doesLegacyStretchBehaviour = obj->getClass()->getField<jboolean>( static auto doesLegacyStretchBehaviour = obj->getClass()->getField<jboolean>(
"mDoesLegacyStretchFlagAffectsLayout"); "mDoesLegacyStretchFlagAffectsLayout");
/* Those flags needs be in sync with YogaNode.java */
const int MARGIN = 1;
const int PADDING = 2;
const int BORDER = 4;
int hasEdgeSetFlag = (int) obj->getFieldValue(edgeSetFlagField);
obj->setFieldValue(widthField, YGNodeLayoutGetWidth(root)); obj->setFieldValue(widthField, YGNodeLayoutGetWidth(root));
obj->setFieldValue(heightField, YGNodeLayoutGetHeight(root)); obj->setFieldValue(heightField, YGNodeLayoutGetHeight(root));
obj->setFieldValue(leftField, YGNodeLayoutGetLeft(root)); obj->setFieldValue(leftField, YGNodeLayoutGetLeft(root));
@@ -151,36 +142,27 @@ static void YGTransferLayoutOutputsRecursive(
doesLegacyStretchBehaviour, doesLegacyStretchBehaviour,
YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(root)); YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(root));
if ((hasEdgeSetFlag & MARGIN) == MARGIN) { obj->setFieldValue(marginLeftField, YGNodeLayoutGetMargin(root, YGEdgeLeft));
obj->setFieldValue( obj->setFieldValue(marginTopField, YGNodeLayoutGetMargin(root, YGEdgeTop));
marginLeftField, YGNodeLayoutGetMargin(root, YGEdgeLeft)); obj->setFieldValue(
obj->setFieldValue(marginTopField, YGNodeLayoutGetMargin(root, YGEdgeTop)); marginRightField, YGNodeLayoutGetMargin(root, YGEdgeRight));
obj->setFieldValue( obj->setFieldValue(
marginRightField, YGNodeLayoutGetMargin(root, YGEdgeRight)); marginBottomField, YGNodeLayoutGetMargin(root, YGEdgeBottom));
obj->setFieldValue(
marginBottomField, YGNodeLayoutGetMargin(root, YGEdgeBottom));
}
if ((hasEdgeSetFlag & PADDING) == PADDING) { obj->setFieldValue(
obj->setFieldValue( paddingLeftField, YGNodeLayoutGetPadding(root, YGEdgeLeft));
paddingLeftField, YGNodeLayoutGetPadding(root, YGEdgeLeft)); obj->setFieldValue(paddingTopField, YGNodeLayoutGetPadding(root, YGEdgeTop));
obj->setFieldValue( obj->setFieldValue(
paddingTopField, YGNodeLayoutGetPadding(root, YGEdgeTop)); paddingRightField, YGNodeLayoutGetPadding(root, YGEdgeRight));
obj->setFieldValue( obj->setFieldValue(
paddingRightField, YGNodeLayoutGetPadding(root, YGEdgeRight)); paddingBottomField, YGNodeLayoutGetPadding(root, YGEdgeBottom));
obj->setFieldValue(
paddingBottomField, YGNodeLayoutGetPadding(root, YGEdgeBottom));
}
if ((hasEdgeSetFlag & BORDER) == BORDER) { obj->setFieldValue(borderLeftField, YGNodeLayoutGetBorder(root, YGEdgeLeft));
obj->setFieldValue( obj->setFieldValue(borderTopField, YGNodeLayoutGetBorder(root, YGEdgeTop));
borderLeftField, YGNodeLayoutGetBorder(root, YGEdgeLeft)); obj->setFieldValue(
obj->setFieldValue(borderTopField, YGNodeLayoutGetBorder(root, YGEdgeTop)); borderRightField, YGNodeLayoutGetBorder(root, YGEdgeRight));
obj->setFieldValue( obj->setFieldValue(
borderRightField, YGNodeLayoutGetBorder(root, YGEdgeRight)); borderBottomField, YGNodeLayoutGetBorder(root, YGEdgeBottom));
obj->setFieldValue(
borderBottomField, YGNodeLayoutGetBorder(root, YGEdgeBottom));
}
obj->setFieldValue<jboolean>(hasNewLayoutField, true); obj->setFieldValue<jboolean>(hasNewLayoutField, true);
YGTransferLayoutDirection(root, obj); YGTransferLayoutDirection(root, obj);