From 543de0d10013f1de2b018562eab0ae1f80d94766 Mon Sep 17 00:00:00 2001 From: Honghao Date: Sat, 24 Jan 2026 17:08:37 -0800 Subject: [PATCH] Add HStack renderable item culling tests --- .../HorizontalStackNodeTests.swift | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/ComposeUI/Tests/ComposeUITests/ComposeNodes/HorizontalStackNodeTests.swift b/ComposeUI/Tests/ComposeUITests/ComposeNodes/HorizontalStackNodeTests.swift index b9dd082..6e7d27b 100644 --- a/ComposeUI/Tests/ComposeUITests/ComposeNodes/HorizontalStackNodeTests.swift +++ b/ComposeUI/Tests/ComposeUITests/ComposeNodes/HorizontalStackNodeTests.swift @@ -238,4 +238,45 @@ class HorizontalStackNodeTests: XCTestCase { expect(items[1].frame) == CGRect(x: 50, y: 10, width: 20, height: 20) } } + + func test_renderableItems_filtersOffscreenChildren() { + var node = HStack { + LayerNode().frame(width: 10, height: 10) + LayerNode().frame(width: 10, height: 10) + LayerNode().frame(width: 10, height: 10) + } + + let context = ComposeNodeLayoutContext(scaleFactor: 1) + _ = node.layout(containerSize: CGSize(width: 30, height: 10), context: context) + + let items = node.renderableItems(in: CGRect(x: 0, y: 0, width: 10, height: 10)) + + guard items.count == 1 else { + fail("Expected 1 item") + return + } + + expect(items[0].frame) == CGRect(x: 0, y: 0, width: 10, height: 10) + } + + func test_renderableItems_includesOffsetChildren() { + var node = HStack { + LayerNode().frame(width: 10, height: 10) + LayerNode().frame(width: 10, height: 10) + .offset(x: -10, y: 0) + } + + let context = ComposeNodeLayoutContext(scaleFactor: 1) + _ = node.layout(containerSize: CGSize(width: 20, height: 10), context: context) + + let items = node.renderableItems(in: CGRect(x: 0, y: 0, width: 10, height: 10)) + + guard items.count == 2 else { + fail("Expected 2 items") + return + } + + expect(items[0].frame) == CGRect(x: 0, y: 0, width: 10, height: 10) + expect(items[1].frame) == CGRect(x: 0, y: 0, width: 10, height: 10) + } }