Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions Example/OpenSwiftUIUITests/Layout/Stack/ZStackIndexUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
)
}
}
22 changes: 14 additions & 8 deletions Sources/OpenSwiftUICore/Layout/Dynamic/DynamicLayoutMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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, newValue), at: index)
}
}
}
sortedSeed = .zero
}
Expand Down
43 changes: 42 additions & 1 deletion Tests/OpenSwiftUICoreTests/Layout/ZIndexTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// OpenSwiftUICoreTests

import OpenAttributeGraphShims
@_spi(ForOpenSwiftUIOnly)
import OpenSwiftUICore
import Testing
import Foundation

@MainActor
struct ZIndexTests {
Expand All @@ -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
}