diff --git a/Sources/YogaKit/YGLayout.mm b/Sources/YogaKit/YGLayout.mm index c849ced..311b2d6 100644 --- a/Sources/YogaKit/YGLayout.mm +++ b/Sources/YogaKit/YGLayout.mm @@ -227,11 +227,13 @@ - (void)markDirty { // the measure function. Since we already know that this is a leaf, // this *should* be fine. Forgive me Hack Gods. const YGNodeRef node = self.node; - if (!YGNodeHasMeasureFunc(node)) { + if (!YGNodeHasMeasureFunc(node) && self.numberOfChildren == 0) { YGNodeSetMeasureFunc(node, YGMeasureView); } - YGNodeMarkDirty(node); + if (YGNodeHasMeasureFunc(node)) { + YGNodeMarkDirty(node); + } } - (NSUInteger)numberOfChildren { diff --git a/Tests/FlexLayoutTests/FlexLayoutTests.swift b/Tests/FlexLayoutTests/FlexLayoutTests.swift index bb215a7..555ec27 100644 --- a/Tests/FlexLayoutTests/FlexLayoutTests.swift +++ b/Tests/FlexLayoutTests/FlexLayoutTests.swift @@ -26,5 +26,18 @@ final class FlexLayoutTests: XCTestCase { XCTAssertNil(weakView, "Creation of flex should not lead to retain cycle") } + + + func testRemoveViewDynamically() { + let rootFlexContainer = UIView() + rootFlexContainer.flex.addItem(UIView()) + rootFlexContainer.flex.define { _ in } + rootFlexContainer.flex.layout() + + rootFlexContainer.subviews.forEach { $0.removeFromSuperview() } + rootFlexContainer.flex.markDirty() + rootFlexContainer.flex.layout() + XCTAssertTrue(rootFlexContainer.subviews.isEmpty) + } }