From 06ddef3dbf749f4dce32de83ed0f1851635cff4c Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 18 Oct 2025 23:05:29 +0800 Subject: [PATCH 1/4] Fix DynamicLayoutMap index issue A follow up fix after #579 --- .../Layout/Dynamic/DynamicLayoutMap.swift | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Sources/OpenSwiftUICore/Layout/Dynamic/DynamicLayoutMap.swift b/Sources/OpenSwiftUICore/Layout/Dynamic/DynamicLayoutMap.swift index acc2210f1..8e07e4235 100644 --- a/Sources/OpenSwiftUICore/Layout/Dynamic/DynamicLayoutMap.swift +++ b/Sources/OpenSwiftUICore/Layout/Dynamic/DynamicLayoutMap.swift @@ -31,17 +31,23 @@ package struct DynamicLayoutMap { map.first(where: { $0.id == id })?.value ?? .init() } set { - let index = map.firstIndex(where: { $0.id == id }) - if let index { - if newValue.isEmpty { - map.remove(at: index) - } else { - map[index].value = newValue - } - } else { + if map.isEmpty { if !newValue.isEmpty { map.insert((id, newValue), at: 0) } + } else { + let index = map.lowerBound { $0.id < id } + if index != map.count, map[index].id == id { + if newValue.isEmpty { + map.remove(at: index) + } else { + map[index].value = newValue + } + } else { + if !newValue.isEmpty { + map.insert((id, .init()), at: index) + } + } } sortedSeed = .zero } From c801a0081cf851b860424dfb424f83ece2dbd8e8 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 18 Oct 2025 23:20:36 +0800 Subject: [PATCH 2/4] Fix non-first view layout computer nil issue --- Sources/OpenSwiftUICore/Layout/Dynamic/DynamicLayoutMap.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/OpenSwiftUICore/Layout/Dynamic/DynamicLayoutMap.swift b/Sources/OpenSwiftUICore/Layout/Dynamic/DynamicLayoutMap.swift index 8e07e4235..b541ea150 100644 --- a/Sources/OpenSwiftUICore/Layout/Dynamic/DynamicLayoutMap.swift +++ b/Sources/OpenSwiftUICore/Layout/Dynamic/DynamicLayoutMap.swift @@ -45,7 +45,7 @@ package struct DynamicLayoutMap { } } else { if !newValue.isEmpty { - map.insert((id, .init()), at: index) + map.insert((id, newValue), at: index) } } } From 0148012f7b60a58600ad7f7af00ba030dc74b722 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sun, 19 Oct 2025 00:02:10 +0800 Subject: [PATCH 3/4] Add zIndexDisplayList test case --- .../Layout/ZIndexTests.swift | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/Tests/OpenSwiftUICoreTests/Layout/ZIndexTests.swift b/Tests/OpenSwiftUICoreTests/Layout/ZIndexTests.swift index 8924eef12..6410e7635 100644 --- a/Tests/OpenSwiftUICoreTests/Layout/ZIndexTests.swift +++ b/Tests/OpenSwiftUICoreTests/Layout/ZIndexTests.swift @@ -3,9 +3,9 @@ // OpenSwiftUICoreTests import OpenAttributeGraphShims -@_spi(ForOpenSwiftUIOnly) import OpenSwiftUICore import Testing +import Foundation @MainActor struct ZIndexTests { @@ -16,4 +16,45 @@ struct ZIndexTests { collection.zIndex = 1.5 #expect(collection.zIndex.isApproximatelyEqual(to: 1.5)) } + + #if canImport(Darwin) + @Test + func zIndexDisplayList() { + struct ContentView: View { + var body: some View { + GeometryReader { proxy in + VStack { + Color.white + .frame(width: 100, height: 100, alignment: .center) + .zIndex(1) + Color.black + .frame(width: 100, height: 100, alignment: .center) + } + .frame(width: 200, height: 200) + } + .ignoresSafeArea() + } + } + let graph = ViewGraph( + rootViewType: ContentView.self, + requestedOutputs: [.layout, .displayList] + ) + graph.instantiateOutputs() + graph.setRootView(ContentView()) + graph.setProposedSize(CGSize(width: 1000, height: 1000)) + let (displayList, _) = graph.displayList() + let expectRegex = try! Regex(#""" + \(display-list + \(item #:identity \d+ #:version \d+ + \(frame \(50.0 104.0; 100.0 100.0\)\) + \(content-seed \d+\) + \(color #000000FF\)\) + \(item #:identity \d+ #:version \d+ + \(frame \(50.0 -4.0; 100.0 100.0\)\) + \(content-seed \d+\) + \(color #FFFFFFFF\)\)\) + """#) + #expect(displayList.description.contains(expectRegex)) + } + #endif } From a37df6a8e0f4bdb8b9fa15742008915b5d220412 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 18 Oct 2025 23:45:43 +0800 Subject: [PATCH 4/4] Update ZStackIndexUITests --- .../Layout/Stack/ZStackIndexUITests.swift | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Example/OpenSwiftUIUITests/Layout/Stack/ZStackIndexUITests.swift b/Example/OpenSwiftUIUITests/Layout/Stack/ZStackIndexUITests.swift index dcad0457d..9280e55ba 100644 --- a/Example/OpenSwiftUIUITests/Layout/Stack/ZStackIndexUITests.swift +++ b/Example/OpenSwiftUIUITests/Layout/Stack/ZStackIndexUITests.swift @@ -10,7 +10,7 @@ import SnapshotTesting @Suite(.snapshots(record: .never, diffTool: diffTool)) struct ZStackIndexUITests { @Test - func zIndexExample() { + func rotateOverlap() { struct ContentView: View { var body: some View { VStack { @@ -30,11 +30,9 @@ struct ZStackIndexUITests { } } } - withKnownIssue { - openSwiftUIAssertSnapshot( - of: ContentView(), - size: CGSize(width: 200, height: 200) - ) - } + openSwiftUIAssertSnapshot( + of: ContentView(), + size: CGSize(width: 200, height: 200) + ) } }