Reputation: 316
I'm having this weird issue with the List
in macOS Montery Beta 3, where some of the list's items are being clipped, and you have to scroll up and back down to unclip it.
Example: https://i.sstatic.net/IWZDj.jpg
struct Bla: Identifiable {
var text: String
var subtext: String
var id = UUID()
}
struct ContentView: View {
@State var data = (0..<100).map { Bla(text: "Text: \($0)", subtext: "Subtext: \($0)")}
var body: some View {
NavigationView {
List(data) { item in
VStack(alignment: .leading) {
Text(item.text)
Text(item.subtext)
.foregroundColor(.secondary)
}
}
.toolbar {
Button(action: {
var offset = 0
for i in 0..<data.count {
if i % 2 == 0 {
continue
}
data.remove(at: i - offset)
offset += 1
}
}) {
Image(systemName: "plus")
}
}
}
}
}
Is this something with my code, or with SwiftUI's List
?
Upvotes: 3
Views: 731
Reputation: 3712
After adding the .listStyle
I dont see the clipping issue anymore, try this:
List(data) { item in
VStack(alignment: .leading) {
Text(item.text)
Text(item.subtext)
.foregroundColor(.secondary)
}
}.listStyle(SidebarListStyle())
Upvotes: 3