Fix performance issues with lists

This commit is contained in:
Christoph Hagen
2025-02-07 14:09:07 +01:00
parent dc7ab6fb15
commit 1bc40bfb47
5 changed files with 59 additions and 35 deletions

View File

@ -2,25 +2,28 @@ import SwiftUI
struct SelectableListItem<Content>: View where Content: View {
let content: Content
let content: () -> Content
let selected: Bool
public init(selected: Bool, @ViewBuilder content: () -> Content) {
public init(selected: Bool, @ViewBuilder content: @escaping () -> Content) {
self.selected = selected
self.content = content()
self.content = content
}
var body: some View {
HStack {
content
content()
Spacer()
}
.padding(.horizontal, 4)
.padding(.vertical, 7)
.foregroundStyle(selected ? Color.white : Color.primary)
.listRowBackground(RoundedRectangle(cornerRadius: 5)
.fill(selected ? Color.blue : Color.clear)
.padding(.horizontal, 10)
)
.background(selected ? Color.blue : Color.clear)
.clipShape(RoundedRectangle(cornerRadius: 5))
.contentShape(Rectangle())
.listRowInsets(.init(top: 0, leading: -8, bottom: 0, trailing: -8))
.listRowBackground(Color.clear)
.listRowSeparator(.hidden)
}
}