Last active
November 5, 2023 16:50
-
-
Save jamesporter/81ff12b767b7cbaee88c7fd0944aeead to your computer and use it in GitHub Desktop.
Nice LazyVGrid layout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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