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

@ -72,13 +72,18 @@ struct PostListView: View {
TextField("", text: $searchString, prompt: Text("Search"))
.textFieldStyle(.roundedBorder)
.padding(.horizontal, 8)
List(filteredAndSortedPosts) { post in
SelectableListItem(selected: selection.post == post) {
PostListItem(post: post)
}
.onTapGesture {
selection.post = post
}
ScrollView {
LazyVStack(spacing: 0) {
ForEach(filteredAndSortedPosts) { post in
SelectableListItem(selected: selection.post == post) {
PostListItem(post: post)
}
.id(post)
.onTapGesture {
selection.post = post
}
}
}.padding(.horizontal, 8)
}
}.onAppear {
if selection.post == nil, let first = content.posts.first {