SwiftUIMidOpen-ended

Why does `FlowLayout` (using the `Layout` protocol) break inside a `ScrollView`?

Explanation & Code

Inside a ScrollView, SwiftUI's vertical scroll direction makes height unconstrained. In some layout passes, proposal.width can arrive as nil. FlowLayout falls back to .infinity → items never wrap → height calculation is wrong → views overlap.

The root cause: FlowLayout relies on the parent correctly proposing a finite width via proposal.width. ScrollView doesn't always guarantee this.

WrapHStack avoids this entirely because GeometryReader reads the actual rendered frame width, bypassing the layout proposal system.

Rate your understanding:

Ready to practice more SwiftUI?

Test yourself with our interactive quiz mode or browse all curated questions for this topic.