I am trying to render a list of entities that are split into sections (think CoreData NSFetchedResultsSectionInfo).
I believe this solution (or very similar) used to be in the documentation. I have tried several ways of doing this, either I get the scrolling issue or pinnedViews won't pin.
I also asked this question in Apple Dev Forum, no takers so far.
This my solution, however it renders poorly. The ScrollView's content is far too long, scrolling is not fluid and may freeze.
struct SectionsGridView: View {
let sections: Sections<ListItemViewModel>
let columns = [ GridItem(.adaptive(minimum: .cellSize)) ]
var body: some View {
ScrollView {
LazyVGrid(columns: columns, spacing: .gridSpacing, pinnedViews: .sectionHeaders) {
ForEach(sections) { list in
Section(header: Text(list.title?.uppercased() ?? "error")) {
ForEach(list) { item in
GridCell().environmentObject(item)
}
}
}
}
}
}
}
private extension CGFloat {
static let gridSpacing = 8.0
static let cellSize = 100.0
}