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
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,52 @@ struct ForEachUITests {
// openSwiftUIAssertAnimationSnapshot(of: ContentView())
}
}

@Test(
.bug(
"https://github.com/OpenSwiftUIProject/OpenSwiftUI/issues/669",
id: 669
)
)
func dynamicContainerIndex() {
struct ContentView1: View {
var body: some View {
VStack {
Color.red
Color.green
ForEach(0 ..< 1) { index in
Color.red.frame(width: 20, height: 20)
Spacer()
Color.blue.frame(width: 20, height: 20)
}
}
}
}
struct ContentView2: View {
var body: some View {
VStack {
Color.red
Color.green
ForEach(0 ..< 1) { index in
Spacer()
Color.blue
}
}
}
}
struct ContentView3: View {
var body: some View {
VStack {
Color.red.frame(width: 10, height: 10)
Color.green.frame(width: 20, height: 20)
ForEach(0 ..< 1) { index in
Color.blue.frame(width: 40, height: 40)
}
}
}
}
openSwiftUIAssertSnapshot(of: ContentView1(), named: "1")
openSwiftUIAssertSnapshot(of: ContentView2(), named: "2")
openSwiftUIAssertSnapshot(of: ContentView3(), named: "3")
}
}
5 changes: 3 additions & 2 deletions Sources/OpenSwiftUICore/Layout/Dynamic/DynamicContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ package struct DynamicContainer {
fileprivate(set) var seed: UInt32 = .zero

func viewIndex(id: ID) -> Int? {
guard let value = indexMap[id.uniqueId] else {
guard let index = indexMap[id.uniqueId] else {
return nil
}
return value + Int(id.viewIndex)
let item = items[index]
return Int(item.precedingViewCount + id.viewIndex)
}

func item(for subgraph: Subgraph) -> ItemInfo? {
Expand Down
Loading