Skip to content

Commit

Permalink
Mark all children as dirty if display changes
Browse files Browse the repository at this point in the history
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 facebook#443
Closes facebook#448

Reviewed By: astreet

Differential Revision: D4642273

Pulled By: emilsjolander

fbshipit-source-id: dfdb920e2049952bd6c7f48cfa53b1448e1f3e8f
  • Loading branch information
woehrl01 authored and facebook-github-bot committed Mar 3, 2017
1 parent feb365a commit a706f4c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/YGDirtyMarkingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,54 @@ TEST(YogaTest, dirty_propagation_only_if_prop_changed) {
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) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
Expand Down
6 changes: 6 additions & 0 deletions yoga/Yoga.c
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,12 @@ static void YGZeroOutLayoutRecursivly(const YGNodeRef node) {
node->layout.position[YGEdgeBottom] = 0;
node->layout.position[YGEdgeLeft] = 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);
for (uint32_t i = 0; i < childCount; i++) {
const YGNodeRef child = YGNodeListGet(node->children, i);
Expand Down

0 comments on commit a706f4c

Please sign in to comment.