Expose layout paddding in java api
Summary: Expose layout padding api from D4376572 Reviewed By: passy Differential Revision: D4377069 fbshipit-source-id: 2e0c04104560e1be586562b27b3457576590dc18
This commit is contained in:
committed by
Facebook Github Bot
parent
bf5eeaf61e
commit
e539ecc9aa
@@ -69,6 +69,14 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
|
|||||||
@DoNotStrip
|
@DoNotStrip
|
||||||
private float mLeft = YogaConstants.UNDEFINED;
|
private float mLeft = YogaConstants.UNDEFINED;
|
||||||
@DoNotStrip
|
@DoNotStrip
|
||||||
|
private float mPaddingLeft = 0;
|
||||||
|
@DoNotStrip
|
||||||
|
private float mPaddingTop = 0;
|
||||||
|
@DoNotStrip
|
||||||
|
private float mPaddingRight = 0;
|
||||||
|
@DoNotStrip
|
||||||
|
private float mPaddingBottom = 0;
|
||||||
|
@DoNotStrip
|
||||||
private int mLayoutDirection = 0;
|
private int mLayoutDirection = 0;
|
||||||
|
|
||||||
private native long jni_YGNodeNew();
|
private native long jni_YGNodeNew();
|
||||||
@@ -564,6 +572,26 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
|
|||||||
return mHeight;
|
return mHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getLayoutPadding(YogaEdge edge) {
|
||||||
|
switch (edge) {
|
||||||
|
case LEFT:
|
||||||
|
return mPaddingLeft;
|
||||||
|
case TOP:
|
||||||
|
return mPaddingTop;
|
||||||
|
case RIGHT:
|
||||||
|
return mPaddingRight;
|
||||||
|
case BOTTOM:
|
||||||
|
return mPaddingBottom;
|
||||||
|
case START:
|
||||||
|
return getLayoutDirection() == YogaDirection.RTL ? mPaddingRight : mPaddingLeft;
|
||||||
|
case END:
|
||||||
|
return getLayoutDirection() == YogaDirection.RTL ? mPaddingLeft : mPaddingRight;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Cannot get layout paddings of multi-edge shorthands");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public YogaDirection getLayoutDirection() {
|
public YogaDirection getLayoutDirection() {
|
||||||
return YogaDirection.values()[mLayoutDirection];
|
return YogaDirection.values()[mLayoutDirection];
|
||||||
|
@@ -81,6 +81,7 @@ public interface YogaNodeAPI<YogaNodeType extends YogaNodeAPI> {
|
|||||||
float getLayoutY();
|
float getLayoutY();
|
||||||
float getLayoutWidth();
|
float getLayoutWidth();
|
||||||
float getLayoutHeight();
|
float getLayoutHeight();
|
||||||
|
float getLayoutPadding(YogaEdge edge);
|
||||||
YogaDirection getLayoutDirection();
|
YogaDirection getLayoutDirection();
|
||||||
YogaOverflow getOverflow();
|
YogaOverflow getOverflow();
|
||||||
void setOverflow(YogaOverflow overflow);
|
void setOverflow(YogaOverflow overflow);
|
||||||
|
@@ -30,10 +30,21 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
|
|||||||
static auto leftField = obj->getClass()->getField<jfloat>("mLeft");
|
static auto leftField = obj->getClass()->getField<jfloat>("mLeft");
|
||||||
static auto topField = obj->getClass()->getField<jfloat>("mTop");
|
static auto topField = obj->getClass()->getField<jfloat>("mTop");
|
||||||
|
|
||||||
|
static auto paddingLeftField = obj->getClass()->getField<jfloat>("mPaddingLeft");
|
||||||
|
static auto paddingTopField = obj->getClass()->getField<jfloat>("mPaddingTop");
|
||||||
|
static auto paddingRightField = obj->getClass()->getField<jfloat>("mPaddingRight");
|
||||||
|
static auto paddingBottomField = obj->getClass()->getField<jfloat>("mPaddingBottom");
|
||||||
|
|
||||||
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));
|
||||||
obj->setFieldValue(topField, YGNodeLayoutGetTop(root));
|
obj->setFieldValue(topField, YGNodeLayoutGetTop(root));
|
||||||
|
|
||||||
|
obj->setFieldValue(paddingLeftField, YGNodeLayoutGetPadding(root, YGEdgeLeft));
|
||||||
|
obj->setFieldValue(paddingTopField, YGNodeLayoutGetPadding(root, YGEdgeTop));
|
||||||
|
obj->setFieldValue(paddingRightField, YGNodeLayoutGetPadding(root, YGEdgeRight));
|
||||||
|
obj->setFieldValue(paddingBottomField, YGNodeLayoutGetPadding(root, YGEdgeBottom));
|
||||||
|
|
||||||
YGTransferLayoutDirection(root, obj);
|
YGTransferLayoutDirection(root, obj);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) {
|
for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) {
|
||||||
|
@@ -138,4 +138,21 @@ public class YogaNodeTest {
|
|||||||
node0.copyStyle(node1);
|
node0.copyStyle(node1);
|
||||||
assertEquals(100, (int) node0.getMaxHeight().value);
|
assertEquals(100, (int) node0.getMaxHeight().value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLayoutPadding() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
node.setWidth(100);
|
||||||
|
node.setHeight(100);
|
||||||
|
node.setPadding(YogaEdge.START, 1);
|
||||||
|
node.setPadding(YogaEdge.END, 2);
|
||||||
|
node.setPadding(YogaEdge.TOP, 3);
|
||||||
|
node.setPadding(YogaEdge.BOTTOM, 4);
|
||||||
|
node.calculateLayout();
|
||||||
|
|
||||||
|
assertEquals(1, (int) node.getLayoutPadding(YogaEdge.LEFT));
|
||||||
|
assertEquals(2, (int) node.getLayoutPadding(YogaEdge.RIGHT));
|
||||||
|
assertEquals(3, (int) node.getLayoutPadding(YogaEdge.TOP));
|
||||||
|
assertEquals(4, (int) node.getLayoutPadding(YogaEdge.BOTTOM));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user