Fixing potential measure call with negative size value
Summary: There is a case when measure() function will be called with negative width/height because of margin/padding. This diff fixes that scenario Reviewed By: emilsjolander Differential Revision: D5111534 fbshipit-source-id: 99f09b85f0c6a0e5dec89a26baba8f9d560100da
This commit is contained in:
committed by
Facebook Github Bot
parent
bf4ff0769d
commit
cd1dbc3f0f
@@ -39,6 +39,19 @@ static YGSize _simulate_wrapping_text(YGNodeRef node,
|
||||
};
|
||||
}
|
||||
|
||||
static YGSize _measure_assert_negative(YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
EXPECT_GE(width, 0);
|
||||
EXPECT_GE(height, 0);
|
||||
|
||||
return YGSize{
|
||||
.width = 0, .height = 0,
|
||||
};
|
||||
}
|
||||
|
||||
TEST(YogaTest, dont_measure_single_grow_shrink_child) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root, 100);
|
||||
@@ -563,3 +576,41 @@ TEST(YogaTest, can_nullify_measure_func_on_any_node) {
|
||||
ASSERT_TRUE(YGNodeGetMeasureFunc(root) == NULL);
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(YogaTest, cant_call_negative_measure) {
|
||||
const YGConfigRef config = YGConfigNew();
|
||||
|
||||
const YGNodeRef root = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
|
||||
YGNodeStyleSetWidth(root, 50);
|
||||
YGNodeStyleSetHeight(root, 10);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure_assert_negative);
|
||||
YGNodeStyleSetMargin(root_child0, YGEdgeTop, 20);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
YGConfigFree(config);
|
||||
}
|
||||
|
||||
TEST(YogaTest, cant_call_negative_measure_horizontal) {
|
||||
const YGConfigRef config = YGConfigNew();
|
||||
|
||||
const YGNodeRef root = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
||||
YGNodeStyleSetWidth(root, 10);
|
||||
YGNodeStyleSetHeight(root, 20);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure_assert_negative);
|
||||
YGNodeStyleSetMargin(root_child0, YGEdgeStart, 20);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
YGConfigFree(config);
|
||||
}
|
||||
|
Reference in New Issue
Block a user