diff --git a/java/jni/YGJNI.cpp b/java/jni/YGJNI.cpp index 69cbb38115..cddb80ecd1 100644 --- a/java/jni/YGJNI.cpp +++ b/java/jni/YGJNI.cpp @@ -42,7 +42,7 @@ static void YGTransferLayoutDirection(YGNodeRef node, alias_ref javaNod javaNode->setFieldValue(layoutDirectionField, static_cast(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("mWidth"); @@ -111,9 +111,11 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) { obj->setFieldValue(borderBottomField, YGNodeLayoutGetBorder(root, YGEdgeBottom)); } - obj->setFieldValue(hasNewLayoutField, true); YGTransferLayoutDirection(root, obj); - root->setHasNewLayout(false); + if(transferAndResetNewLayoutFlag){ + obj->setFieldValue(hasNewLayoutField, true); + root->setHasNewLayout(false); + } for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) { YGTransferLayoutOutputsRecursive(YGNodeGetChild(root, i)); @@ -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; @@ -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("baseline"); + YGTransferLayoutOutputsRecursiveForBaseline(obj); return baselineFunc(obj, width, height); } else { return height;