-
Notifications
You must be signed in to change notification settings - Fork 31
Grids
Nick Sarno edited this page Jan 13, 2024
·
1 revision
The native SwiftUI LazyVGrid has performance implications and can cause undesired bugs. For Grids with low cell count (where it's ok to render all cells at once), use NonLazyVGrid instead.
Note: returned item can be nil (for cells where there is no item but the grid must render a blank cell). Developer should handle this gracefully.
NonLazyVGrid(
columns: 2,
alignment: .center,
spacing: 16,
items: ["one", "two", "three", "four", "five"],
content: { item in
Text(item ?? "")
.frame(maxWidth: .infinity)
.background(Color.red)
.opacity(item == nil ? 0 : 1)
}
)
NonLazyHGrid(
rows: 2,
alignment: .center,
spacing: 16,
items: ["one", "two", "three", "four", "five"],
content: { item in
Text(item ?? "")
.frame(maxWidth: .infinity)
.background(Color.red)
.opacity(item == nil ? 0 : 1)
}
)