Skip to content

Commit 473fc15

Browse files
committed
YGNodeFree: mark parent dirty when child is freed
1 parent 4a59d09 commit 473fc15

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

tests/YGDirtyMarkingTest.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,38 @@ TEST(YogaTest, dirty_removed_child_nodes_when_removing_all) {
304304
YGNodeFree(child1);
305305
YGNodeFreeRecursive(root);
306306
}
307+
308+
TEST(YogaTest, dirty_parent_when_child_freed) {
309+
YGNodeRef root = YGNodeNew();
310+
YGNodeStyleSetWidth(root, 100);
311+
YGNodeStyleSetHeight(root, 100);
312+
313+
YGNodeRef child = YGNodeNew();
314+
YGNodeStyleSetWidth(child, 50);
315+
YGNodeStyleSetHeight(child, 50);
316+
YGNodeInsertChild(root, child, 0);
317+
318+
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
319+
EXPECT_FALSE(YGNodeIsDirty(root));
320+
321+
YGNodeFree(child);
322+
323+
EXPECT_TRUE(YGNodeIsDirty(root));
324+
YGNodeFree(root);
325+
}
326+
327+
TEST(YogaTest, dirty_parent_when_subtree_freed_recursive) {
328+
YGNodeRef root = YGNodeNew();
329+
YGNodeRef child = YGNodeNew();
330+
YGNodeRef grandchild = YGNodeNew();
331+
YGNodeInsertChild(root, child, 0);
332+
YGNodeInsertChild(child, grandchild, 0);
333+
334+
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
335+
EXPECT_FALSE(YGNodeIsDirty(root));
336+
337+
YGNodeFreeRecursive(child);
338+
339+
EXPECT_TRUE(YGNodeIsDirty(root));
340+
YGNodeFree(root);
341+
}

yoga/YGNode.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void YGNodeFree(const YGNodeRef nodeRef) {
4444
if (auto owner = node->getOwner()) {
4545
owner->removeChild(node);
4646
node->setOwner(nullptr);
47+
owner->markDirtyAndPropagate();
4748
}
4849

4950
const size_t childCount = node->getChildCount();

0 commit comments

Comments
 (0)