Files
Memola/Memola/Features/Dashboard/Details/Shared/MemoGrid.swift
T
2024-06-30 17:42:51 +07:00

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()
}
}
}
}
}