Fix performance issues with lists
This commit is contained in:
parent
dc7ab6fb15
commit
1bc40bfb47
@ -51,13 +51,19 @@ struct FileListView: View {
|
|||||||
TextField("", text: $searchString, prompt: Text("Search"))
|
TextField("", text: $searchString, prompt: Text("Search"))
|
||||||
.textFieldStyle(.roundedBorder)
|
.textFieldStyle(.roundedBorder)
|
||||||
.padding(.horizontal, 8)
|
.padding(.horizontal, 8)
|
||||||
List(filteredFiles) { file in
|
ScrollView {
|
||||||
SelectableListItem(selected: selectedFile == file) {
|
LazyVStack(spacing: 0) {
|
||||||
Text(file.id)
|
ForEach(filteredFiles) { file in
|
||||||
}
|
SelectableListItem(selected: selectedFile == file) {
|
||||||
.onTapGesture {
|
Text(file.id)
|
||||||
selectedFile = file
|
}
|
||||||
|
.id(file.id)
|
||||||
|
.onTapGesture {
|
||||||
|
selectedFile = file
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
.padding(.horizontal, 8)
|
||||||
}
|
}
|
||||||
.onChange(of: selectedFileType) { oldValue, newValue in
|
.onChange(of: selectedFileType) { oldValue, newValue in
|
||||||
guard oldValue != newValue else {
|
guard oldValue != newValue else {
|
||||||
|
@ -2,25 +2,28 @@ import SwiftUI
|
|||||||
|
|
||||||
struct SelectableListItem<Content>: View where Content: View {
|
struct SelectableListItem<Content>: View where Content: View {
|
||||||
|
|
||||||
let content: Content
|
let content: () -> Content
|
||||||
|
|
||||||
let selected: Bool
|
let selected: Bool
|
||||||
|
|
||||||
public init(selected: Bool, @ViewBuilder content: () -> Content) {
|
public init(selected: Bool, @ViewBuilder content: @escaping () -> Content) {
|
||||||
self.selected = selected
|
self.selected = selected
|
||||||
self.content = content()
|
self.content = content
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
HStack {
|
HStack {
|
||||||
content
|
content()
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
|
.padding(.horizontal, 4)
|
||||||
|
.padding(.vertical, 7)
|
||||||
.foregroundStyle(selected ? Color.white : Color.primary)
|
.foregroundStyle(selected ? Color.white : Color.primary)
|
||||||
.listRowBackground(RoundedRectangle(cornerRadius: 5)
|
.background(selected ? Color.blue : Color.clear)
|
||||||
.fill(selected ? Color.blue : Color.clear)
|
.clipShape(RoundedRectangle(cornerRadius: 5))
|
||||||
.padding(.horizontal, 10)
|
|
||||||
)
|
|
||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
|
.listRowInsets(.init(top: 0, leading: -8, bottom: 0, trailing: -8))
|
||||||
|
.listRowBackground(Color.clear)
|
||||||
|
.listRowSeparator(.hidden)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,13 +63,18 @@ struct PageListView: View {
|
|||||||
TextField("", text: $searchString, prompt: Text("Search"))
|
TextField("", text: $searchString, prompt: Text("Search"))
|
||||||
.textFieldStyle(.roundedBorder)
|
.textFieldStyle(.roundedBorder)
|
||||||
.padding(.horizontal, 8)
|
.padding(.horizontal, 8)
|
||||||
List(filteredPages) { page in
|
ScrollView {
|
||||||
SelectableListItem(selected: selection.page == page) {
|
LazyVStack(spacing: 0) {
|
||||||
PageListItem(page: page)
|
ForEach(filteredPages) { page in
|
||||||
}
|
SelectableListItem(selected: selection.page == page) {
|
||||||
.onTapGesture {
|
PageListItem(page: page)
|
||||||
selection.page = page
|
}
|
||||||
}
|
.id(page)
|
||||||
|
.onTapGesture {
|
||||||
|
selection.page = page
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.padding(.horizontal, 8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
|
@ -72,13 +72,18 @@ struct PostListView: View {
|
|||||||
TextField("", text: $searchString, prompt: Text("Search"))
|
TextField("", text: $searchString, prompt: Text("Search"))
|
||||||
.textFieldStyle(.roundedBorder)
|
.textFieldStyle(.roundedBorder)
|
||||||
.padding(.horizontal, 8)
|
.padding(.horizontal, 8)
|
||||||
List(filteredAndSortedPosts) { post in
|
ScrollView {
|
||||||
SelectableListItem(selected: selection.post == post) {
|
LazyVStack(spacing: 0) {
|
||||||
PostListItem(post: post)
|
ForEach(filteredAndSortedPosts) { post in
|
||||||
}
|
SelectableListItem(selected: selection.post == post) {
|
||||||
.onTapGesture {
|
PostListItem(post: post)
|
||||||
selection.post = post
|
}
|
||||||
}
|
.id(post)
|
||||||
|
.onTapGesture {
|
||||||
|
selection.post = post
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.padding(.horizontal, 8)
|
||||||
}
|
}
|
||||||
}.onAppear {
|
}.onAppear {
|
||||||
if selection.post == nil, let first = content.posts.first {
|
if selection.post == nil, let first = content.posts.first {
|
||||||
|
@ -32,13 +32,18 @@ struct TagListView: View {
|
|||||||
TextField("", text: $searchString, prompt: Text("Search"))
|
TextField("", text: $searchString, prompt: Text("Search"))
|
||||||
.textFieldStyle(.roundedBorder)
|
.textFieldStyle(.roundedBorder)
|
||||||
.padding(.horizontal, 8)
|
.padding(.horizontal, 8)
|
||||||
List(filteredAndSortedTags) { tag in
|
ScrollView {
|
||||||
SelectableListItem(selected: selection.tag == tag) {
|
LazyVStack(spacing: 0) {
|
||||||
TagListItem(tag: tag.localized(in: language))
|
ForEach(filteredAndSortedTags) { tag in
|
||||||
}
|
SelectableListItem(selected: selection.tag == tag) {
|
||||||
.onTapGesture {
|
TagListItem(tag: tag.localized(in: language))
|
||||||
selection.tag = tag
|
}
|
||||||
}
|
.id(tag)
|
||||||
|
.onTapGesture {
|
||||||
|
selection.tag = tag
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.padding(.horizontal, 8)
|
||||||
}
|
}
|
||||||
}.onAppear {
|
}.onAppear {
|
||||||
if selection.tag == nil, let first = content.tags.first {
|
if selection.tag == nil, let first = content.tags.first {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user