Expose layout border to java

Reviewed By: astreet

Differential Revision: D4543284

fbshipit-source-id: 6030915fc6f758e785a688f94c8ffbec7fbac8b8
This commit is contained in:
Emil Sjolander 2017-02-11 06:19:52 -08:00 committed by Facebook Github Bot
parent aac7b19a7c
commit 21475e58b3
3 changed files with 39 additions and 0 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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++) {