mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 04:35:36 +08:00
Expose layout paddding in java api
Reviewed By: passy Differential Revision: D4377069 fbshipit-source-id: 2e0c04104560e1be586562b27b3457576590dc18
This commit is contained in:
committed by
Facebook Github Bot
parent
d9c35e8952
commit
0cdda4d8d9
@@ -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++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user