Mark all children as dirty if display changes
Summary: If we set ```display:none``` all children are set with layout sizes/values of 0. We need do mark all those children as dirty to force a relayout if we toggle the display on a higher parent node. This fixes #443 Closes https://github.com/facebook/yoga/pull/448 Reviewed By: astreet Differential Revision: D4642273 Pulled By: emilsjolander fbshipit-source-id: dfdb920e2049952bd6c7f48cfa53b1448e1f3e8f
This commit is contained in:
committed by
Facebook Github Bot
parent
feb365a77b
commit
a706f4c97c
@@ -70,6 +70,54 @@ TEST(YogaTest, dirty_propagation_only_if_prop_changed) {
|
|||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Yogatest, dirty_mark_all_children_as_dirty_when_display_changes){
|
||||||
|
const YGNodeRef root = YGNodeNew();
|
||||||
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
||||||
|
YGNodeStyleSetHeight(root, 100);
|
||||||
|
|
||||||
|
const YGNodeRef child0 = YGNodeNew();
|
||||||
|
YGNodeStyleSetFlexGrow(child0, 1);
|
||||||
|
const YGNodeRef child1 = YGNodeNew();
|
||||||
|
YGNodeStyleSetFlexGrow(child1, 1);
|
||||||
|
|
||||||
|
const YGNodeRef child1_child0 = YGNodeNew();
|
||||||
|
const YGNodeRef child1_child0_child0 = YGNodeNew();
|
||||||
|
YGNodeStyleSetWidth(child1_child0_child0, 8);
|
||||||
|
YGNodeStyleSetHeight(child1_child0_child0, 16);
|
||||||
|
|
||||||
|
YGNodeInsertChild(child1_child0, child1_child0_child0, 0);
|
||||||
|
|
||||||
|
YGNodeInsertChild(child1, child1_child0, 0);
|
||||||
|
YGNodeInsertChild(root, child0, 0);
|
||||||
|
YGNodeInsertChild(root, child1, 0);
|
||||||
|
|
||||||
|
YGNodeStyleSetDisplay(child0, YGDisplayFlex);
|
||||||
|
YGNodeStyleSetDisplay(child1, YGDisplayNone);
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(child1_child0_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(child1_child0_child0));
|
||||||
|
|
||||||
|
YGNodeStyleSetDisplay(child0, YGDisplayNone);
|
||||||
|
YGNodeStyleSetDisplay(child1, YGDisplayFlex);
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
ASSERT_FLOAT_EQ(8, YGNodeLayoutGetWidth(child1_child0_child0));
|
||||||
|
ASSERT_FLOAT_EQ(16, YGNodeLayoutGetHeight(child1_child0_child0));
|
||||||
|
|
||||||
|
YGNodeStyleSetDisplay(child0, YGDisplayFlex);
|
||||||
|
YGNodeStyleSetDisplay(child1, YGDisplayNone);
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(child1_child0_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(child1_child0_child0));
|
||||||
|
|
||||||
|
YGNodeStyleSetDisplay(child0, YGDisplayNone);
|
||||||
|
YGNodeStyleSetDisplay(child1, YGDisplayFlex);
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
ASSERT_FLOAT_EQ(8, YGNodeLayoutGetWidth(child1_child0_child0));
|
||||||
|
ASSERT_FLOAT_EQ(16, YGNodeLayoutGetHeight(child1_child0_child0));
|
||||||
|
|
||||||
|
YGNodeFreeRecursive(root);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(YogaTest, dirty_node_only_if_children_are_actually_removed) {
|
TEST(YogaTest, dirty_node_only_if_children_are_actually_removed) {
|
||||||
const YGNodeRef root = YGNodeNew();
|
const YGNodeRef root = YGNodeNew();
|
||||||
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
||||||
|
@@ -1791,6 +1791,12 @@ static void YGZeroOutLayoutRecursivly(const YGNodeRef node) {
|
|||||||
node->layout.position[YGEdgeBottom] = 0;
|
node->layout.position[YGEdgeBottom] = 0;
|
||||||
node->layout.position[YGEdgeLeft] = 0;
|
node->layout.position[YGEdgeLeft] = 0;
|
||||||
node->layout.position[YGEdgeRight] = 0;
|
node->layout.position[YGEdgeRight] = 0;
|
||||||
|
node->layout.cachedLayout.availableHeight = 0;
|
||||||
|
node->layout.cachedLayout.availableWidth = 0;
|
||||||
|
node->layout.cachedLayout.heightMeasureMode = YGMeasureModeExactly;
|
||||||
|
node->layout.cachedLayout.widthMeasureMode = YGMeasureModeExactly;
|
||||||
|
node->layout.cachedLayout.computedWidth = 0;
|
||||||
|
node->layout.cachedLayout.computedHeight = 0;
|
||||||
const uint32_t childCount = YGNodeGetChildCount(node);
|
const uint32_t childCount = YGNodeGetChildCount(node);
|
||||||
for (uint32_t i = 0; i < childCount; i++) {
|
for (uint32_t i = 0; i < childCount; i++) {
|
||||||
const YGNodeRef child = YGNodeListGet(node->children, i);
|
const YGNodeRef child = YGNodeListGet(node->children, i);
|
||||||
|
Reference in New Issue
Block a user