Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
dpearson2699 avatar

Swiftui Layout Components

  • 2.9k installs
  • 944 repo stars
  • Updated July 15, 2026
  • dpearson2699/swift-ios-skills

swiftui-layout-components is a Swift iOS skill for stacks, grids, lists, scroll views, forms, controls, search, and overlay UI patterns on iOS 26+.

About

SwiftUI Layout and Components teaches stack, grid, list, scroll, form, control, search, and overlay patterns for iOS 26+ apps using Swift 6.3, with backward compatibility notes to iOS 17. It contrasts non-lazy VStack, HStack, and ZStack for small fixed content against LazyVStack and LazyHStack inside ScrollView for large collections. Grid guidance covers adaptive and flexible LazyVGrid columns, aspect ratio sizing, and avoiding GeometryReader inside lazy containers. List patterns include insetGrouped settings rows, scrollContentBackground hiding, refreshable feeds, ScrollPosition jump-to-id, and iOS 26 scroll edge effects. Form and control sections document Toggle, Picker, Slider, DatePicker, TextField binding, and FocusState keyboard management. Searchable examples show debounced async search with searchScopes and task id triggers. Overlay patterns cover transient toasts and fullScreenCover presentations. A common mistakes list and review checklist guard against index-based ForEach IDs, nested scroll views, and empty-query searches. Reference files expand grids, lists, scroll views, and forms.

  • Lazy versus non-lazy stack selection for collection size.
  • LazyVGrid adaptive and flexible column patterns with aspect ratio sizing.
  • List feed and settings styles with ScrollPosition and refreshable.
  • Form controls with FocusState and searchable debounced async search.
  • Overlay toasts and iOS 26 scroll edge effect patterns.

Swiftui Layout Components by the numbers

  • 2,875 all-time installs (skills.sh)
  • +137 installs in the week ending Jul 29, 2026 (Skillselion tracking)
  • Ranked #56 of 1,039 Mobile Development skills by installs in the Skillselion catalog
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Jul 31, 2026 (Skillselion catalog sync)
At a glance

swiftui-layout-components capabilities & compatibility

Capabilities
stack and lazy stack selection guidance · lazyvgrid adaptive and flexible column setup · list feed and settings row patterns · form control binding with focusstate · searchable debounced async query flow · overlay toast and fullscreencover presentation
Use cases
frontend · ui design
Platforms
macOS
Pricing
Free
npx skills add https://github.com/dpearson2699/swift-ios-skills --skill swiftui-layout-components

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs2.9k
repo stars944
Security audit3 / 3 scanners passed
Last updatedJuly 15, 2026
Repositorydpearson2699/swift-ios-skills

How do I choose lazy stacks, list styles, forms, and searchable patterns without common SwiftUI layout pitfalls?

Build SwiftUI layouts with stacks, grids, lists, scroll views, forms, controls, search, and overlays for iOS 26+ apps.

Who is it for?

iOS developers building feeds, settings screens, search interfaces, and transient overlay UI in SwiftUI.

Skip if: Skip for UIKit-only projects, navigation routing architecture, or server-side API work.

When should I use this skill?

User builds SwiftUI layouts, collection views, settings forms, searchable lists, or toast overlays.

What you get

Correct stack or grid choice, list and form patterns, debounced search setup, and overlay presentation aligned to Apple layout guidance.

  • swiftui layout code
  • list and grid implementations
  • form and search ui components

By the numbers

  • Targets iOS 26+ with Swift 6.3
  • Covers VStack, HStack, ZStack, LazyVGrid, LazyHGrid, List, ScrollView, and Form patterns

Files

SKILL.mdMarkdownGitHub ↗

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.

Contents

Layout Fundamentals

Standard Stacks

Use VStack, HStack, and ZStack for small, fixed-size content. They render all children immediately.

VStack(alignment: .leading) {
    Text(title).font(.headline)
    Text(subtitle).font(.subheadline).foregroundStyle(.secondary)
}

Lazy Stacks

Use LazyVStack and LazyHStack inside ScrollView for large or dynamic collections. They create child views on demand as they scroll into view.

ScrollView {
    LazyVStack {
        ForEach(items) { item in
            ItemRow(item: item)
        }
    }
    .padding(.horizontal)
}

When to use which:

  • 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)
    }
}
// Fixed 3-column grid
let columns = Array(repeating: GridItem(.flexible(minimum: 100), spacing: 4), count: 3)

LazyVGrid(columns: columns, spacing: 4) {
    ForEach(items) { item in
        ThumbnailView(item: item)
    }
}

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.

See references/grids.md for full grid patterns and design choices.

List Patterns

Use List for feed-style content and settings rows where built-in row reuse, selection, and accessibility matter.

List {
    Section("General") {
        NavigationLink("Display") { DisplaySettingsView() }
        NavigationLink("Haptics") { HapticsSettingsView() }
    }
    Section("Account") {
        Button("Sign Out", role: .destructive) { }
    }
}
.listStyle(.insetGrouped)

Key patterns:

  • .listStyle(.plain) for feed layouts, .insetGrouped for settings
  • .scrollContentBackground(.hidden) + custom background for themed surfaces
  • .listRowInsets(...) and .listRowSeparator(.hidden) for spacing and separator control
  • Use ScrollPosition with .scrollPosition($scrollPosition) for scroll-to-top or jump-to-id
  • Use .refreshable { } for pull-to-refresh feeds
  • Use .contentShape(Rectangle()) on rows that should be tappable end-to-end

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.

ScrollView(.horizontal, showsIndicators: false) {
    LazyHStack {
        ForEach(chips) { chip in
            ChipView(chip: chip)
        }
    }
}

ScrollPosition: Enables declarative, bidirectional scroll position tracking and programmatic scrolling.

@State private var scrollPosition = ScrollPosition(edge: .bottom)

ScrollView {
    LazyVStack {
        ForEach(messages) { message in
            MessageRow(message: message)
        }
    }
    .scrollTargetLayout()
}
.scrollPosition($scrollPosition)
.onChange(of: messages.last?.id) {
    withAnimation { scrollPosition.scrollTo(edge: .bottom) }
}

See references/scrollview.md for full ScrollPosition patterns including scroll-to-id and user-scroll detection.

`safeAreaInset(edge:)` pins content (input bars, toolbars) above the keyboard without affecting scroll layout.

iOS 26 additions:

  • .scrollEdgeEffectStyle(.soft, for: .top) -- fading edge effect
  • .backgroundExtensionEffect() -- mirror/blur at safe area edges (use sparingly, one per screen)
  • .safeAreaBar(edge:) -- attach bar views that integrate with scroll effects

See references/scrollview.md for full scroll patterns and iOS 26 edge effects.

Form and Controls

Form

Use Form for structured settings and input screens. Group related controls into Section blocks.

Form {
    Section("Notifications") {
        Toggle("Mentions", isOn: $prefs.mentions)
        Toggle("Follows", isOn: $prefs.follows)
    }
    Section("Appearance") {
        Picker("Theme", selection: $theme) {
            ForEach(Theme.allCases, id: \.self) { Text($0.title).tag($0) }
        }
        Slider(value: $fontScale, in: 0.5...1.5, step: 0.1)
    }
}
.formStyle(.grouped)
.scrollContentBackground(.hidden)

Use @FocusState to manage keyboard focus in input-heavy forms. Wrap in NavigationStack only when presented standalone or in a sheet.

Controls

ControlUsage
ToggleBoolean preferences
PickerDiscrete choices; .segmented for 2-4 options
SliderNumeric ranges with visible value label
DatePickerDate/time selection
TextFieldText 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.

// Toggle sections
Form {
  Section("Notifications") {
    Toggle("Mentions", isOn: $preferences.notificationsMentionsEnabled)
    Toggle("Follows", isOn: $preferences.notificationsFollowsEnabled)
  }
}

// Slider with value text
Section("Font Size") {
  Slider(value: $fontSizeScale, in: 0.5...1.5, step: 0.1)
  Text("Scale: \(String(format: "%.1f", fontSizeScale))")
}

// Picker for enums
Picker("Default Visibility", selection: $visibility) {
  ForEach(Visibility.allCases, id: \.self) { option in
    Text(option.title).tag(option)
  }
}

Avoid .pickerStyle(.segmented) for large sets; use menu or inline styles. Don't hide labels for sliders; always show context.

See references/form.md for full form examples.

Searchable

Add native search UI with .searchable. Use .searchScopes for multiple modes and .task(id:) for debounced async results.

@MainActor
struct ExploreView: View {
  @State private var searchQuery = ""
  @State private var searchScope: SearchScope = .all
  @State private var isSearching = false
  @State private var results: [SearchResult] = []

  var body: some View {
    List {
      if isSearching {
        ProgressView()
      } else {
        ForEach(results) { result in
          SearchRow(result: result)
        }
      }
    }
    .searchable(
      text: $searchQuery,
      placement: .navigationBarDrawer(displayMode: .always),
      prompt: Text("Search")
    )
    .searchScopes($searchScope) {
      ForEach(SearchScope.allCases, id: \.self) { scope in
        Text(scope.title)
      }
    }
    .task(id: searchQuery) {
      await runSearch()
    }
  }

  private func runSearch() async {
    guard !searchQuery.isEmpty else {
      results = []
      return
    }
    isSearching = true
    defer { isSearching = false }
    try? await Task.sleep(for: .milliseconds(250))
    results = await fetchResults(query: searchQuery, scope: searchScope)
  }
}

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.

fullScreenCover: Use .fullScreenCover(item:) for immersive presentations that cover the entire screen (media viewers, onboarding flows).

Common Mistakes

1. Using non-lazy stacks for large collections -- causes all children to render immediately 2. Placing GeometryReader inside lazy containers -- defeats lazy loading 3. Using array indices as ForEach IDs -- causes incorrect diffing and UI bugs 4. Nesting scroll views of the same axis -- causes gesture conflicts 5. Heavy custom layouts inside List rows -- use ScrollView + LazyVStack instead 6. Missing .contentShape(Rectangle()) on tappable rows -- tap area is text-only 7. Hard-coding frame dimensions for sheets -- use .presentationSizing instead 8. Running searches on empty strings -- always guard against empty queries 9. Mixing List and ScrollView in the same hierarchy -- gesture conflicts 10. Using .pickerStyle(.segmented) for large option sets -- use menu or inline styles 11. Hard-coding spacing: on stacks and grids by default -- omit to get platform-adaptive spacing; only specify for intentional tight (0–4pt) or wide gaps

Review Checklist

  • [ ] LazyVStack/LazyHStack used for large or dynamic collections
  • [ ] Stable Identifiable IDs on all ForEach items (not array indices)
  • [ ] No GeometryReader inside lazy containers
  • [ ] List style matches context (.plain for feeds, .insetGrouped for settings)
  • [ ] Form used for structured input screens (not custom stacks)
  • [ ] .searchable debounces input with .task(id:)
  • [ ] .refreshable added where data source supports pull-to-refresh
  • [ ] Overlays use transitions and auto-dismiss timers
  • [ ] .contentShape(Rectangle()) on tappable rows
  • [ ] @FocusState manages keyboard focus in forms
  • [ ] Stack/grid spacing: omitted unless a specific value is required

References

  • Grid patterns: references/grids.md
  • List and section patterns: references/list.md
  • ScrollView and lazy stacks: references/scrollview.md
  • Form patterns: references/form.md
  • Architecture and state management: see swiftui-patterns skill
  • Navigation patterns: see swiftui-navigation skill

Related skills

How it compares

Use swiftui-layout-components for opinionated SwiftUI layout recipes instead of generic Swift snippets without iOS 26 ScrollPosition or List patterns.

FAQ

When should I use LazyVStack instead of VStack?

Use lazy stacks inside ScrollView for large or unknown-size collections; non-lazy stacks suit small fixed headers and toolbars.

Why avoid GeometryReader in lazy containers?

It forces eager measurement and defeats lazy loading performance benefits.

How should searchable queries debounce?

Use task id on the search query with a short sleep before fetching and guard against empty strings.

Is Swiftui Layout Components safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.