A minimal SwiftUI lazy container type, that:
- uses
UICollectionView
underneath and supports any self-sizingUICollectionViewLayout
you throwing at it; - can be used on iOS 13.0+ and substituted the sometimes wonky
LazyVStack
; and - does not support sections as is, does not support drag-n-drop, and does not support multiple selections.
There is no commitment to a feature roadmap. Feel free to copy & paste into your own codebase, and evolve/fork it on your own terms.
Sources/Private/Previews.swift contains a SwiftUI Preview showcasing LazyCollection
in a grid format, powered by UICollectionViewCompositionalLayout
. One thing worth noting that is also showcased is that LazyCollection
supports two ways of item selection:
-
a
Data.Element.ID?
binding which you point to a@State
variable; or -
using a
SwiftUI.Button
at the root of yourItemContent
view, akin to the vanilla usage ofSwiftUI.List
.This is made possible by
LazyCollection
always providing an ambientPrimitiveButtonStyle
, that will trigger the SwiftUI action closure in response to UICollectionView selection, and then subsequently auto-deselect the item. Note that auto-deselection is disabled if you use a binding (1).
- Samuel Défago's blog post series
- ASCollectionView — a more fully featured package.