FlowLayout

Custom SwiftUI Layout that wraps children to next line (like CSS flex-wrap).

Usage

FlowLayout(spacing: 8) {
    ForEach(items) { item in
        TagButton(item)
    }
}

Behavior

  • Lays out children horizontally
  • When width exceeded, wraps to next row
  • Maintains consistent spacing between items
  • Adapts to container width

Implementation

Implements SwiftUI Layout protocol:

  • sizeThatFits(): Calculates total height needed
  • placeSubviews(): Positions each child

Known Issues

Context menu closures evaluated once at build time (SwiftUI bug). Workaround: Use Menu with primaryAction instead of contextMenu.

Used By

Related