Skip to content

Commit

Permalink
transfer current layout before calling basline function
Browse files Browse the repository at this point in the history
do not reset newLayoutFlag on baseline transfer
  • Loading branch information
woehrl01 committed Apr 28, 2018
1 parent e1c19ce commit c981db0
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions java/jni/YGJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static void YGTransferLayoutDirection(YGNodeRef node, alias_ref<jobject> javaNod
javaNode->setFieldValue(layoutDirectionField, static_cast<jint>(YGNodeLayoutGetDirection(node)));
}

static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
static void YGTransferLayoutOutputsRecursiveImpl(YGNodeRef root, bool transferAndResetNewLayoutFlag) {
if (root->getHasNewLayout()) {
if (auto obj = YGNodeJobject(root)->lockLocal()) {
static auto widthField = obj->getClass()->getField<jfloat>("mWidth");
Expand Down Expand Up @@ -111,9 +111,11 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
obj->setFieldValue(borderBottomField, YGNodeLayoutGetBorder(root, YGEdgeBottom));
}

obj->setFieldValue<jboolean>(hasNewLayoutField, true);
YGTransferLayoutDirection(root, obj);
root->setHasNewLayout(false);
if(transferAndResetNewLayoutFlag){
obj->setFieldValue<jboolean>(hasNewLayoutField, true);
root->setHasNewLayout(false);
}

for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) {
YGTransferLayoutOutputsRecursive(YGNodeGetChild(root, i));
Expand All @@ -124,6 +126,14 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
}
}

static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
YGTransferLayoutOutputsRecursiveImpl(root, true);
}

static void YGTransferLayoutOutputsRecursiveForBaseline(YGNodeRef root) {
YGTransferLayoutOutputsRecursiveImpl(root, false);
}

static void YGPrint(YGNodeRef node) {
if (auto obj = YGNodeJobject(node)->lockLocal()) {
cout << obj->toString() << endl;
Expand All @@ -136,6 +146,7 @@ static float YGJNIBaselineFunc(YGNodeRef node, float width, float height) {
if (auto obj = YGNodeJobject(node)->lockLocal()) {
static auto baselineFunc = findClassStatic("com/facebook/yoga/YogaNode")
->getMethod<jfloat(jfloat, jfloat)>("baseline");
YGTransferLayoutOutputsRecursiveForBaseline(obj);
return baselineFunc(obj, width, height);
} else {
return height;
Expand Down

0 comments on commit c981db0

Please sign in to comment.