dpearson2699/swift-ios-skills / skills/swiftui-layout-components
swiftui-layout-components
VerifiedBuild 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.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 11.5 KB |
| evals/evals.json | config | 4.9 KB |
| references/form.md | markdown | 3.0 KB |
| references/grids.md | markdown | 6.5 KB |
| references/list.md | markdown | 3.7 KB |
| references/scrollview.md | markdown | 9.1 KB |
references/list.md
View on GitHub# List and Section
## Contents
- [Intent](#intent)
- [Core patterns](#core-patterns)
- [Example: feed list with scroll-to-top](#example-feed-list-with-scroll-to-top)
- [Example: settings-style list](#example-settings-style-list)
- [Design choices to keep](#design-choices-to-keep)
- [iOS 26 Scroll Edge Effects](#ios-26-scroll-edge-effects)
- [Pitfalls](#pitfalls)
## Intent
Use `List` for feed-style content and settings-style rows where built-in row reuse, selection, and accessibility matter.
## Core patterns
- Prefer `List` for long, vertically scrolling content with repeated rows.
- Use `Section` headers to group related rows.
- **Edge scrolls:** use `List` + `ScrollPosition` with
`.scrollPosition($scrollPosition)` for top/bottom scroll actions on iOS 18+.
- **Item or section jumps:** use `ScrollView` + `LazyVStack` with
`.scrollTargetLayout()` and stable explicit IDs for reliable jump-to-id
behavior; do not assume `List` section headers are scroll targets.
- Use `.listStyle(.plain)` for modern feed layouts.
- Use `.listStyle(.grouped)` for multi-section discovery/search pages where section grouping helps.
- Apply `.scrollContentBackground(.hidden)` + a custom background when you need a themed surface.
- Use `.listRowInsets(...)` and `.listRowSeparator(.hidden)` to tune row spacing and separators.
- Use `.environment(\.defaultMinListRowHeight, ...)` to control dense list layouts.
## Example: feed list with scroll-to-top
```swift
@MainActor
struct TimelineListView: View {
@Environment(\.selectedTabScrollToTop) private var selectedTabScrollToTop
@State private var scrollPosition = ScrollPosition(idType: String.self)
var body: some View {
List {
ForEach(items) { item in
TimelineRow(item: item)
.id(item.id)
.listRowInsets(.init(top: 12, leading: 16, bottom: 12, trailing: 16))
.listRowSeparator(.hidden)
}
}
.listStyle(.plain)
.environment(\.defaultMinListRowHeight, 1)
.scrollPosition($scrollPosition)
.onChange(of: selectedTabScrollToTop) {
withAnimation {
scrollPosition.scrollTo(edge: .top)
}
}
}
}
```
## Example: settings-style list
```swift
@MainActor
struct SettingsView: View {
var body: some View {
List {
Section("General") {
NavigationLink("Display") { DisplaySettingsView() }
NavigationLink("Haptics") { HapticsSettingsView() }
}
Section("Account") {
Button("Sign Out", role: .destructive) {}
}
}
.listStyle(.insetGrouped)
}
}
```
## Design choices to keep
- Use `List` for dynamic feeds, settings, and any UI where row semantics help.
- Use stable IDs for rows to keep diffing and scroll positioning reliable.
- Prefer `.contentShape(Rectangle())` on rows that should be tappable end-to-end.
- Use `.refreshable` for pull-to-refresh feeds when the data source supports it.
- Treat dynamically changing row heights as a practical `List` gotcha:
expanding or collapsing row content may snap instead of smoothly
interpolating. Keep `List` rows structurally simple, or move complex
expanding content to `ScrollView` + `LazyVStack`. Frame this as a
container/layout decision, not as a full animation recipe. Do not prescribe
spring parameters, transition styles, or animation timing here; defer those
choices to `swiftui-animation`.
## iOS 26 Scroll Edge Effects
Apply edge effects to lists for modern scroll behavior:
```swift
List {
// rows
}
.scrollEdgeEffectStyle(.soft, for: .top)
```
See `scrollview.md` for the full scroll edge effect and `backgroundExtensionEffect()` API reference.
## Pitfalls
- Avoid heavy custom layouts inside a `List` row; use `ScrollView` + `LazyVStack` instead.
- Be careful mixing `List` and nested `ScrollView`; it can cause gesture conflicts.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |