Build SwiftUI layouts using stacks, grids, lists, scroll views, forms, and controls. Covers VStack/HStack/ZStack, LazyVGrid/LazyHGrid, List with sections and swipe actions, ScrollView with ScrollPosition and scroll-driven reveal surfaces, Form with validation, Toggle/Picker/Slider, .searchable, and overlay patterns. Use when building data-driven layouts, collection views, paged detail reveals, settings screens, search interfaces, or transient overlay UI.
SKILL.md
SwiftUI Layout & Components
Layout and component patterns for SwiftUI apps targeting iOS 26+ with Swift 6.3. Covers stack and grid layouts, list patterns, scroll views, forms, controls, search, and overlays. Patterns are backward-compatible to iOS 17 unless noted.
Non-lazy stacks: Small, fixed content (headers, toolbars, forms with few fields)
Lazy stacks: Large or unknown-size collections, feeds, chat messages
Grid Layouts
Use LazyVGrid for icon pickers, media galleries, and dense visual selections. Use .adaptive columns for layouts that scale across device sizes, or .flexible columns for a fixed column count.
// Adaptive grid -- columns adjust to fit
let columns = [GridItem(.adaptive(minimum: 120, maximum: 1024))]
LazyVGrid(columns: columns) {
ForEach(items) { item in
ThumbnailView(item: item)
.aspectRatio(1, contentMode: .fit)
}
}
Use .aspectRatio for cell sizing. Never place GeometryReader inside lazy containers -- it forces eager measurement and defeats lazy loading. Use .onGeometryChange (iOS 16+) if you need to read dimensions.
.listStyle(.plain) for feed layouts, .insetGrouped for settings
.scrollContentBackground(.hidden) + custom background for themed surfaces
.listRowInsets(...) and .listRowSeparator(.hidden) for spacing and separator control
Edge scrolling: use List + ScrollPosition with .scrollPosition($scrollPosition) for top/bottom scroll actions
Item or section jumps: use ScrollView + lazy stacks with .scrollTargetLayout() and stable targets for reliable jump-to-id behavior
Use .refreshable { } for pull-to-refresh feeds
Use .contentShape(Rectangle()) on rows that should be tappable end-to-end
For layout review or migration guidance, lead with container choice and constraints; keep code snippets tiny, and defer spring, transition, and timing choices to swiftui-animation
iOS 26: Apply .scrollEdgeEffectStyle(.soft, for: .top) for modern scroll edge effects.
See references/list.md for full list patterns including feed lists with scroll-to-top.
ScrollView
Use ScrollView with lazy stacks when you need custom layout, mixed content, or horizontal scrolling.
Use @FocusState to manage keyboard focus in input-heavy forms. Wrap in NavigationStack only when presented standalone or in a sheet.
Controls
Control
Usage
Toggle
Boolean preferences
Picker
Discrete choices; .segmented for 2-4 options
Slider
Numeric ranges with visible value label
DatePicker
Date/time selection
TextField
Text input with .keyboardType, .textInputAutocapitalization
Bind controls directly to @State, @Binding, or @AppStorage. Group related controls in Form sections. Use .disabled(...) to reflect locked or inherited settings. Use Label inside toggles to combine icon + text when it adds clarity.
Avoid .pickerStyle(.segmented) for large sets; use menu or inline styles. Don't hide labels for sliders; always show context.
Show a placeholder when search is empty. Debounce input to avoid overfetching. Keep search state local to the view. Avoid running searches for empty strings.
Overlay and Presentation
Use .overlay(alignment:) for transient UI (toasts, banners) without affecting layout.
struct AppRootView: View {
@State private var toast: Toast?
var body: some View {
content
.overlay(alignment: .top) {
if let toast {
ToastView(toast: toast)
.transition(.move(edge: .top).combined(with: .opacity))
.onAppear {
Task {
try? await Task.sleep(for: .seconds(2))
withAnimation { self.toast = nil }
}
}
}
}
}
}
Prefer overlays for transient UI rather than embedding in layout stacks. Use transitions and short auto-dismiss timers. Keep overlays aligned to a clear edge (.top or .bottom). Avoid overlays that block all interaction unless explicitly needed. Don't stack many overlays; use a queue or replace the current toast.
For modal routing, sheet detents, and full-screen presentation policy, hand off to the swiftui-navigation skill.
Common Mistakes
Placing GeometryReader inside lazy containers defeats lazy loading; use .onGeometryChange when dimensions are needed.
Array indices make unstable ForEach IDs and produce incorrect diffing.