Fix performance issues with lists
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user