diff options
| author | Fuwn <[email protected]> | 2026-02-18 12:26:07 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-18 12:26:11 -0800 |
| commit | 314ebb285d11caad11482885769402df80c45391 (patch) | |
| tree | 67a8a254e3d6bac23501134b08d6daf5d14710a8 /Sora/Views/Shared/ThumbnailGridView.swift | |
| parent | perf: memoize generic list derived data and folder grouping (diff) | |
| download | sora-testing-314ebb285d11caad11482885769402df80c45391.tar.xz sora-testing-314ebb285d11caad11482885769402df80c45391.zip | |
perf: eliminate repeated favorites sort map and grid recompute
Diffstat (limited to 'Sora/Views/Shared/ThumbnailGridView.swift')
| -rw-r--r-- | Sora/Views/Shared/ThumbnailGridView.swift | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Sora/Views/Shared/ThumbnailGridView.swift b/Sora/Views/Shared/ThumbnailGridView.swift new file mode 100644 index 0000000..a7130c2 --- /dev/null +++ b/Sora/Views/Shared/ThumbnailGridView.swift @@ -0,0 +1,45 @@ +import SwiftUI +import WaterfallGrid + +struct ThumbnailGridView<Item: Hashable & Identifiable, Content: View>: View { + let items: [Item] + let columnCount: Int + let useAlternativeGrid: Bool + let columnsData: [[Item]] + let content: (Item) -> Content + + var body: some View { + if useAlternativeGrid { + HStack(alignment: .top) { + ForEach(0..<columnCount, id: \.self) { columnIndex in + LazyVStack { + ForEach(columnsData[columnIndex], id: \.id) { item in + content(item) + .id(item.id) + } + } + .transaction { $0.animation = nil } + } + } + #if os(macOS) + .padding(8) + #else + .padding(.horizontal) + #endif + .transition(.opacity) + } else { + WaterfallGrid(items, id: \.id) { item in + content(item) + .id(item.id) + } + .gridStyle(columns: columnCount) + .transaction { $0.animation = nil } + #if os(macOS) + .padding(8) + #else + .padding(.horizontal) + #endif + .transition(.opacity) + } + } +} |