swiftui-layout

Select SwiftUI layout tools based on available space and dynamics.

1.1k|81|Updated Nov 30, 2025
One-click install
npx skills add https://github.com/CharlesWiltgen/Axiom --skill swiftui-layout
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftui-layout
Source: https://github.com/CharlesWiltgen/Axiom/tree/main/.claude-plugin/plugins/axiom/skills/swiftui-layout
Command: npx skills add https://github.com/CharlesWiltgen/Axiom --skill swiftui-layout

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This discipline guides building responsive SwiftUI layouts that adapt to available space and new windowing features, avoiding device-specific assumptions.

Core Features & Use Cases

  • Choosing between ViewThatFits, AnyLayout, and onGeometryChange
  • Handling size classes and windowing changes
  • Anti-patterns to prevent device-based layout mistakes

Quick Start

Prompt: "Create a two-column layout that collapses on narrow widths."

Frequently Asked Questions about swiftui-layout

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create responsive layouts that work across iPhone and iPad in SwiftUI?

Responsive layouts in SwiftUI adapt to available space using ViewThatFits, AnyLayout, or onGeometryChange rather than device assumptions. ViewThatFits tries layout options in order and picks the first that fits; AnyLayout switches layouts based on space; onGeometryChange responds to size changes. Choose based on whether you need simple fallbacks, dynamic switching, or continuous monitoring of available width and height.

What's the difference between ViewThatFits and AnyLayout for SwiftUI layouts?

ViewThatFits attempts layouts sequentially and locks to the first that fits the container, ideal for discrete options like single-column or multi-column. AnyLayout animates between completely different layout types as space changes, suited for smooth transitions. AnyLayout adds animation overhead; ViewThatFits is lighter but less fluid.

How do I handle layout changes when rotating between portrait and landscape in SwiftUI?

Detect orientation and space changes using onGeometryChange to monitor the available width, then conditionally apply different layouts or spacing. Pair with size classes via Environment to distinguish compact from regular widths. For Stage Manager and Split View, track actual geometry rather than device orientation, since windows resize independently.

Can I use custom Layout protocols to build adaptive SwiftUI layouts?

Yes. The custom Layout protocol lets you define sizing and positioning logic that responds to available space and child counts. This powers advanced decision-tree patterns and container-driven sizing. Use it when ViewThatFits and AnyLayout don't capture your specific adaptation rules.

What layout mistakes should I avoid when building multi-device SwiftUI interfaces?

Avoid device-based assumptions (checking for iPhone vs iPad); instead measure available space with geometry. Don't hardcode fixed widths or assume device traits remain constant during Split View or Stage Manager transitions. Prefer space-responsive decisions over platform detection to handle all windowing scenarios.

How do I collapse a two-column layout to a single column on narrow widths?

Use ViewThatFits with two layout options: the two-column layout first, then a single-column fallback. ViewThatFits automatically selects the layout that fits available width. Alternatively, measure width with onGeometryChange and conditionally render different stacks based on the threshold you set.