Expose layout border to java
Summary: Expose layout border to java Reviewed By: astreet Differential Revision: D4543284 fbshipit-source-id: 6030915fc6f758e785a688f94c8ffbec7fbac8b8
This commit is contained in:
committed by
Facebook Github Bot
parent
240c2dd657
commit
6ceb4af2d4
@@ -86,6 +86,14 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
|
||||
@DoNotStrip
|
||||
private float mPaddingBottom = 0;
|
||||
@DoNotStrip
|
||||
private float mBorderLeft = 0;
|
||||
@DoNotStrip
|
||||
private float mBorderTop = 0;
|
||||
@DoNotStrip
|
||||
private float mBorderRight = 0;
|
||||
@DoNotStrip
|
||||
private float mBorderBottom = 0;
|
||||
@DoNotStrip
|
||||
private int mLayoutDirection = 0;
|
||||
|
||||
private native long jni_YGNodeNew();
|
||||
@@ -633,6 +641,26 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLayoutBorder(YogaEdge edge) {
|
||||
switch (edge) {
|
||||
case LEFT:
|
||||
return mBorderLeft;
|
||||
case TOP:
|
||||
return mBorderTop;
|
||||
case RIGHT:
|
||||
return mBorderRight;
|
||||
case BOTTOM:
|
||||
return mBorderBottom;
|
||||
case START:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mBorderRight : mBorderLeft;
|
||||
case END:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mBorderLeft : mBorderRight;
|
||||
default:
|
||||
throw new IllegalArgumentException("Cannot get layout border of multi-edge shorthands");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public YogaDirection getLayoutDirection() {
|
||||
return YogaDirection.fromInt(mLayoutDirection);
|
||||
|
@@ -84,6 +84,7 @@ public interface YogaNodeAPI<YogaNodeType extends YogaNodeAPI> {
|
||||
float getLayoutHeight();
|
||||
float getLayoutMargin(YogaEdge edge);
|
||||
float getLayoutPadding(YogaEdge edge);
|
||||
float getLayoutBorder(YogaEdge edge);
|
||||
YogaDirection getLayoutDirection();
|
||||
YogaOverflow getOverflow();
|
||||
void setOverflow(YogaOverflow overflow);
|
||||
|
@@ -40,6 +40,11 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
|
||||
static auto paddingRightField = obj->getClass()->getField<jfloat>("mPaddingRight");
|
||||
static auto paddingBottomField = obj->getClass()->getField<jfloat>("mPaddingBottom");
|
||||
|
||||
static auto borderLeftField = obj->getClass()->getField<jfloat>("mBorderLeft");
|
||||
static auto borderTopField = obj->getClass()->getField<jfloat>("mBorderTop");
|
||||
static auto borderRightField = obj->getClass()->getField<jfloat>("mBorderRight");
|
||||
static auto borderBottomField = obj->getClass()->getField<jfloat>("mBorderBottom");
|
||||
|
||||
obj->setFieldValue(widthField, YGNodeLayoutGetWidth(root));
|
||||
obj->setFieldValue(heightField, YGNodeLayoutGetHeight(root));
|
||||
obj->setFieldValue(leftField, YGNodeLayoutGetLeft(root));
|
||||
@@ -55,6 +60,11 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
|
||||
obj->setFieldValue(paddingRightField, YGNodeLayoutGetPadding(root, YGEdgeRight));
|
||||
obj->setFieldValue(paddingBottomField, YGNodeLayoutGetPadding(root, YGEdgeBottom));
|
||||
|
||||
obj->setFieldValue(borderLeftField, YGNodeLayoutGetBorder(root, YGEdgeLeft));
|
||||
obj->setFieldValue(borderTopField, YGNodeLayoutGetBorder(root, YGEdgeTop));
|
||||
obj->setFieldValue(borderRightField, YGNodeLayoutGetBorder(root, YGEdgeRight));
|
||||
obj->setFieldValue(borderBottomField, YGNodeLayoutGetBorder(root, YGEdgeBottom));
|
||||
|
||||
YGTransferLayoutDirection(root, obj);
|
||||
|
||||
for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) {
|
||||
|
@@ -202,6 +202,23 @@ public class YogaNodeTest {
|
||||
assertEquals(4, (int) node.getLayoutPadding(YogaEdge.BOTTOM));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLayoutBorder() {
|
||||
final YogaNode node = new YogaNode();
|
||||
node.setWidth(100);
|
||||
node.setHeight(100);
|
||||
node.setBorder(YogaEdge.START, 1);
|
||||
node.setBorder(YogaEdge.END, 2);
|
||||
node.setBorder(YogaEdge.TOP, 3);
|
||||
node.setBorder(YogaEdge.BOTTOM, 4);
|
||||
node.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(1, (int) node.getLayoutBorder(YogaEdge.LEFT));
|
||||
assertEquals(2, (int) node.getLayoutBorder(YogaEdge.RIGHT));
|
||||
assertEquals(3, (int) node.getLayoutBorder(YogaEdge.TOP));
|
||||
assertEquals(4, (int) node.getLayoutBorder(YogaEdge.BOTTOM));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPercentPaddingOnRoot() {
|
||||
final YogaNode node = new YogaNode();
|
||||
|
Reference in New Issue
Block a user