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

fixed bad method call
  • Loading branch information
woehrl01 committed Apr 28, 2018
1 parent e1c19ce commit bfe53b1
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 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,19 +111,29 @@ 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));
YGTransferLayoutOutputsRecursiveImpl(YGNodeGetChild(root, i), transferAndResetNewLayoutFlag);
}
} else {
YGLog(root, YGLogLevelError, "Java YGNode was GCed during layout calculation\n");
}
}
}

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 bfe53b1

Please sign in to comment.