mirror of
https://github.com/dscyrescotti/Memola.git
synced 2026-05-17 21:27:09 +02:00
42 lines
1.1 KiB
Swift
42 lines
1.1 KiB
Swift
//
|
|
// MemoGrid.swift
|
|
// Memola
|
|
//
|
|
// Created by Dscyre Scotti on 6/29/24.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct MemoGrid<Card: View>: View {
|
|
@Environment(\.horizontalSizeClass) var horizontalSizeClass
|
|
let memoObjects: FetchedResults<MemoObject>
|
|
let placeholder: Placeholder.Info
|
|
@ViewBuilder let card: (MemoObject) -> Card
|
|
|
|
var cellWidth: CGFloat {
|
|
if horizontalSizeClass == .compact {
|
|
return 180
|
|
}
|
|
return 250
|
|
}
|
|
|
|
var body: some View {
|
|
if memoObjects.isEmpty {
|
|
Placeholder(info: placeholder)
|
|
} else {
|
|
GeometryReader { proxy in
|
|
let count = Int(proxy.size.width / cellWidth)
|
|
let columns: [GridItem] = .init(repeating: GridItem(.flexible(), spacing: 15), count: count)
|
|
ScrollView {
|
|
LazyVGrid(columns: columns, spacing: 15) {
|
|
ForEach(memoObjects) { memoObject in
|
|
card(memoObject)
|
|
}
|
|
}
|
|
.padding()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|