Skip to content
Nick Sarno edited this page Jan 13, 2024 · 1 revision

NonLazyVGrid

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

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)
     }
)
Clone this wiki locally