Lazy containers create views on-demand based on visibility instead of building the entire view tree upfront.
They are used for:
efficient rendering of large scrollable content
LazyVStack → vertical 1D layout
LazyHStack → horizontal 1D layout
LazyVGrid → vertical 2D layout (columns)
LazyHGrid → horizontal 2D layout (rows)
Only visible views are created
Off-screen views do not exist in the view tree
Views are created and destroyed during scrolling
Lazy containers behave lazily ONLY inside a ScrollView
Example:
ScrollView {
LazyVStack {
// lazy behavior works
}
}
Without ScrollView:
acts like a normal stack (no laziness)
Lazy container = dynamic subtree generator tied to scroll position