Skip to content

Instantly share code, notes, and snippets.

@jamesporter
Last active November 5, 2023 16:50
Show Gist options
  • Save jamesporter/81ff12b767b7cbaee88c7fd0944aeead to your computer and use it in GitHub Desktop.
Save jamesporter/81ff12b767b7cbaee88c7fd0944aeead to your computer and use it in GitHub Desktop.
Nice LazyVGrid layout
// 1. Set up adapative items (repeat, with min/max width), then add spacing as second argument to GridItem:
var columns = [GridItem(.adaptive(minimum: 240, maximum: 420), spacing: spacing)]
var body: some View {
VStack {
ScrollView {
LazyVGrid(columns: columns, spacing: spacing) { // 4. also add spacing here (between rows)
ForEach(document.state.cards) { card in
// 2. Item, then with heights that take full width + some fixed height:
.frame(maxWidth: .infinity)
.frame(height: 480)
.padding()
.background(.white)
.cornerRadius(8)
}
}.padding(spacing)
// 3. Add paddding OUTSIDE the grid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment