Skip to content

Commit e30f180

Browse files
authored
Fix DynamicContainer inusedCount issue (#705)
1 parent ab517e3 commit e30f180

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Example/OpenSwiftUIUITests/View/DynamicViewContent/ForEachUITests.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,28 @@ struct ForEachUITests {
113113
openSwiftUIAssertSnapshot(of: ContentView2(), named: "2")
114114
openSwiftUIAssertSnapshot(of: ContentView3(), named: "3")
115115
}
116+
117+
@Test(
118+
.bug(
119+
"https://github.com/OpenSwiftUIProject/OpenSwiftUI/issues/701",
120+
id: 701
121+
)
122+
)
123+
func emptyDynamicContainer() {
124+
struct ContentView: View {
125+
@State private var items = [6]
126+
var body: some View {
127+
VStack(spacing: 10) {
128+
ForEach(items, id: \.self) { item in
129+
Color.blue.opacity(Double(item) / 6.0)
130+
.frame(height: 50)
131+
}
132+
}
133+
.onAppear {
134+
items.removeAll { $0 == 6 }
135+
}
136+
}
137+
}
138+
openSwiftUIAssertSnapshot(of: ContentView())
139+
}
116140
}

Sources/OpenSwiftUICore/Layout/Dynamic/DynamicContainer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ struct DynamicContainerInfo<Adapter>: StatefulRule, AsyncAttribute, ObservedAttr
369369
}
370370
info.indexMap.removeAll(keepingCapacity: true)
371371
info.allUnary = true
372-
Swift.assert(inusedCount > 0)
372+
Swift.assert(inusedCount >= 0)
373373
if totalCount != unusedCount {
374374
var precedingCount: Int32 = 0
375375
var allUnary = true

0 commit comments

Comments
 (0)