Dont measure single flex grow+shrink child

Summary: If there is a single child which is flex grow and flex shrink then instead of measuring and then shrinking we can just set the flex basis to zero as we know the final result will be that the child take up all remaining space.

Reviewed By: gkassabli

Differential Revision: D4147298

fbshipit-source-id: 51152e57eff8e322a833a6d698c30f8c5e2dcc35
This commit is contained in:
Emil Sjolander
2016-11-08 15:23:08 -08:00
committed by Facebook Github Bot
parent 3e567fdcae
commit 12ebaa56b6
4 changed files with 88 additions and 38 deletions

View File

@@ -10,18 +10,42 @@
#include <CSSLayout/CSSLayout.h>
#include <gtest/gtest.h>
#if GTEST_HAS_DEATH_TEST
static CSSSize _measure(CSSNodeRef node,
float width,
CSSMeasureMode widthMode,
float height,
CSSMeasureMode heightMode) {
int *measureCount = (int*) CSSNodeGetContext(node);
if (measureCount) {
(*measureCount)++;
}
return CSSSize {
.width = 0,
.height = 0,
.width = 10,
.height = 10,
};
}
TEST(CSSLayoutTest, dont_measure_single_grow_shrink_child) {
const CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetWidth(root, 100);
CSSNodeStyleSetHeight(root, 100);
int measureCount = 0;
const CSSNodeRef root_child0 = CSSNodeNew();
CSSNodeSetContext(root_child0, &measureCount);
CSSNodeSetMeasureFunc(root_child0, _measure);
CSSNodeStyleSetFlexGrow(root_child0, 1);
CSSNodeStyleSetFlexShrink(root_child0, 1);
CSSNodeInsertChild(root, root_child0, 0);
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
ASSERT_EQ(0, measureCount);
}
#if GTEST_HAS_DEATH_TEST
TEST(CSSLayoutTest, cannot_add_child_to_node_with_measure_func) {
const CSSNodeRef root = CSSNodeNew();
CSSNodeSetMeasureFunc(root, _measure);