Skip to content

Commit a00588e

Browse files
Jonathan MauriceOlimpiaZurek
Jonathan Maurice
authored andcommitted
Fix negative value rounding issue for nodes across an axis (facebook#688)
Summary: This fix issue facebook/yoga#683 the rounding calculation is incorrect if a node is crossing an axis and it will shrink it's width/height on layout calculation. The following test reproduce the issue : ``` TEST(YogaTest, node_shrink_on_axis) { const YGConfigRef config = YGConfigNew(); const YGNodeRef root = YGNodeNewWithConfig(config); const YGNodeRef child = YGNodeNewWithConfig(config); YGNodeInsertChild(root, child, 0); YGNodeStyleSetWidth(child, 10); YGNodeStyleSetHeight(child, 10); YGNodeStyleSetPosition(root, YGEdgeLeft, -0.75f); YGNodeStyleSetPosition(root, YGEdgeTop, -0.75f); YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); ASSERT_FLOAT_EQ(YGNodeLayoutGetWidth(child), 10); ASSERT_FLOAT_EQ(YGNodeLayoutGetHeight(child), 10); YGNodeFreeRecursive(root); YGConfigFree(config); } ``` X-link: facebook/yoga#688 Reviewed By: NickGerleman Differential Revision: D13866122 Pulled By: rozele fbshipit-source-id: 4faf8a9efc86723c303f600d730660a2e13d8a73
1 parent 8c7ea5a commit a00588e

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

ReactCommon/yoga/yoga/Yoga.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3701,16 +3701,12 @@ YOGA_EXPORT float YGRoundValueToPixelGrid(
37013701
scaledValue = scaledValue - fractial + 1.0;
37023702
} else if (forceCeil) {
37033703
// Next we check if we need to use forced rounding
3704-
scaledValue = scaledValue - fractial + 1.0;
3704+
scaledValue = ceil(scaledValue);
37053705
} else if (forceFloor) {
3706-
scaledValue = scaledValue - fractial;
3706+
scaledValue = floor(scaledValue);
37073707
} else {
37083708
// Finally we just round the value
3709-
scaledValue = scaledValue - fractial +
3710-
(!YGDoubleIsUndefined(fractial) &&
3711-
(fractial > 0.5 || YGDoubleEqual(fractial, 0.5))
3712-
? 1.0
3713-
: 0.0);
3709+
scaledValue = round(scaledValue);
37143710
}
37153711
return (YGDoubleIsUndefined(scaledValue) ||
37163712
YGDoubleIsUndefined(pointScaleFactor))

0 commit comments

Comments
 (0)