Communitygithub.com

ComeOnOliver/skillshub

リファレンス — SwiftUIのスタック、グリッド、アウトライン、スクロール拡張機能(iOS 26対応)

skillshub とは?

このスキルは、SwiftUIで利用可能なコンテナビューの包括的なリファレンスを提供します。VStack、HStack、ZStackといった基本的なスタックから、LazyVStack、LazyHStackなどの遅延ロードコンテナ、Grid、LazyVGrid、LazyHGridといったグリッドレイアウト、さらに階層データを表示するためのOutlineGroupやDisclosureGroupまで、各コンテナの使い方とiOSバージョンごとの対応を詳細に解説します。iOS 26の最新パフォーマンス改善(リスト読み込みの6倍高速化など)や、containerRelativeFrame、scrollTargetLayout、scrollTransition、onScrollGeometryChangeといったスクロール拡張機能についてもカバーしています。このリファレンスは、Claude Code、Cursor、CodexなどのAIエージェントがSwiftUIのレイアウトコードを生成する際に、正確で最適なコンテナを選択するためのガイドとして機能します。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/CharlesWiltgen/Axiom/axiom-swiftui-containers-ref

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

SwiftUIコンテナリファレンス

スタック、グリッド、アウトライン、スクロール拡張機能。iOS 14からiOS 26まで。

出典: WWDC 2020-10031, 2022-10056, 2023-10148, 2024-10144, 2025-256

クイックデシジョン

ユースケースコンテナiOS
固定ビューの垂直/水平VStack / HStack13+
重なり合うビューZStack13+
大きなスクロール可能なリストLazyVStack / LazyHStack14+
マルチカラムグリッドLazyVGrid14+
マルチローグリッド(水平)LazyHGrid14+
静的グリッド、精密な配置Grid16+
階層データ(ツリー)List(children: 付き)14+
カスタム階層OutlineGroup14+
コンテンツの表示/非表示DisclosureGroup14+

パート1: スタック

VStack, HStack, ZStack

VStack(alignment: .leading, spacing: 12) {
    Text("タイトル")
    Text("サブタイトル")
}

HStack(alignment: .top, spacing: 8) {
    Image(systemName: "star")
    Text("評価")
}

ZStack(alignment: .bottomTrailing) {
    Image("photo")
    Badge()
}

ZStackの配置: .center(デフォルト)、.top、.bottom、.leading、.trailing、.topLeading、.topTrailing、.bottomLeading、.bottomTrailing

Spacer

HStack {
    Text("左")
    Spacer()
    Text("右")
}

Spacer(minLength: 20)  // 最小サイズ

LazyVStack, LazyHStack(iOS 14+)

子ビューを可視時のみレンダリングします。ScrollView内で使用します。

ScrollView {
    LazyVStack(spacing: 0) {
        ForEach(items) { item in
            ItemRow(item: item)
        }
    }
}

ピン留めセクションヘッダー

ScrollView {
    LazyVStack(pinnedViews: [.sectionHeaders]) {
        ForEach(sections) { section in
            Section(header: SectionHeader(section)) {
                ForEach(section.items) { item in
                    ItemRow(item: item)
                }
            }
        }
    }
}

パート2: グリッド

Grid(iOS 16+)

精密な配置が可能な非遅延グリッド。すべてのビューを一度に読み込みます。

Grid(alignment: .leading, horizontalSpacing: 10, verticalSpacing: 10) {
    GridRow {
        Text("名前")
        TextField("名前を入力", text: $name)
    }
    GridRow {
        Text("メール")
        TextField("メールを入力", text: $email)
    }
}

モディファイア:

  • gridCellColumns(_:) — 複数列にまたがる
  • gridColumnAlignment(_:) — 列の配置をオーバーライド
Grid {
    GridRow {
        Text("ヘッダー").gridCellColumns(2)
    }
    GridRow {
        Text("左")
        Text("右").gridColumnAlignment(.trailing)
    }
}

LazyVGrid(iOS 14+)

垂直スクロールグリッド。列を定義し、行は無制限に伸びます。

let columns = [
    GridItem(.flexible()),
    GridItem(.flexible()),
    GridItem(.flexible())
]

ScrollView {
    LazyVGrid(columns: columns, spacing: 16) {
        ForEach(items) { item in
            ItemCard(item: item)
        }
    }
}

LazyHGrid(iOS 14+)

水平スクロールグリッド。行を定義し、列は無制限に伸びます。

let rows = [GridItem(.fixed(100)), GridItem(.fixed(100))]

ScrollView(.horizontal) {
    LazyHGrid(rows: rows, spacing: 16) {
        ForEach(items) { item in
            ItemCard(item: item)
        }
    }
}

GridItem.Size

サイズ動作
.fixed(CGFloat)正確な幅/高さ
.flexible(minimum:maximum:)スペースを均等に埋める
.adaptive(minimum:maximum:)収まる数だけ作成
// Adaptive: レスポンシブな列数
let columns = [GridItem(.adaptive(minimum: 150))]

パート3: アウトライン

階層データを持つList(iOS 14+)

struct FileItem: Identifiable {
    let id = UUID()
    var name: String
    var children: [FileItem]?  // nil = リーフ
}

List(files, children: \.children) { file in
    Label(file.name, systemImage: file.children != nil ? "folder" : "doc")
}
.listStyle(.sidebar)

OutlineGroup(iOS 14+)

List以外でカスタム階層レイアウトを作成する場合に使用します。

List {
    ForEach(canvases) { canvas in
        Section(header: Text(canvas.name)) {
            OutlineGroup(canvas.graphics, children: \.children) { graphic in
                GraphicRow(graphic: graphic)
            }
        }
    }
}

DisclosureGroup(iOS 14+)

@State private var isExpanded = false

DisclosureGroup("詳細オプション", isExpanded: $isExpanded) {
    Toggle("機能を有効にする", isOn: $feature)
    Slider(value: $intensity)
}

パート4: 共通パターン

フォトグリッド

let columns = [GridItem(.adaptive(minimum: 100), spacing: 2)]

ScrollView {
    LazyVGrid(columns: columns, spacing: 2) {
        ForEach(photos) { photo in
            AsyncImage(url: photo.thumbnailURL) { image in
                image.resizable().aspectRatio(1, contentMode: .fill)
            } placeholder: { Color.gray }
            .aspectRatio(1, contentMode: .fill)
            .clipped()
        }
    }
}

水平カルーセル

ScrollView(.horizontal, showsIndicators: false) {
    LazyHStack(spacing: 16) {
        ForEach(items) { item in
            CarouselCard(item: item).frame(width: 280)
        }
    }
    .padding(.horizontal)
}

ファイルブラウザ

List(selection: $selection) {
    OutlineGroup(rootItems, children: \.children) { item in
        Label {
            Text(item.name)
        } icon: {
            Image(systemName: item.children != nil ? "folder.fill" : "doc.fill")
        }
    }
}
.listStyle(.sidebar)

パート5: パフォーマンス

Lazyを使用するタイミング

サイズスクロール可能?使用するもの
1-20いいえVStack/HStack
1-20はいScrollView内のVStack/HStack
20-100はいLazyVStack/LazyHStack
100+はいLazyVStack/LazyHStackまたはList
グリッド <50いいえGrid
グリッド 50+はいLazyVGrid/LazyHGrid

GridItem配列をキャッシュ — bodyの外部で定義:

struct ContentView: View {
    let columns = [GridItem(.adaptive(minimum: 150))]  // ✅
    var body: some View {
        LazyVGrid(columns: columns) { ... }
    }
}

iOS 26のパフォーマンス

  • 10万件以上のアイテムで6倍高速なリスト読み込み
  • 16倍高速なリスト更新
  • スクロール時のドロップフレーム低減
  • LazyスタックをネストしたScrollViewが適切に読み込みを遅延:
ScrollView(.horizontal) {
    LazyHStack {
        ForEach(photoSets) { set in
            ScrollView(.vertical) {
                LazyVStack {
                    ForEach(set.photos) { PhotoView(photo: $0) }
                }
            }
        }
    }
}

パート6: スクロール拡張機能

containerRelativeFrame(iOS 17+)

ビューのサイズをスクロールコンテナに相対的に設定します。

ScrollView(.horizontal) {
    LazyHStack {
        ForEach(cards) { card in
            CardView(card: card)
                .containerRelativeFrame(.horizontal, count: 3, span: 1, spacing: 16)
        }
    }
}

scrollTargetLayout(iOS 17+)

スナップを有効にします。

ScrollView(.horizontal) {
    LazyHStack {
        ForEach(items) { ItemCard(item: $0) }
    }
    .scrollTargetLayout()
}
.scrollTargetBehavior(.viewAligned)

scrollPosition(iOS 17+)

先頭に表示されているアイテムを追跡します。各アイテムに .id() が必要です。

@State private var position: Item.ID?

ScrollView {
    LazyVStack {
        ForEach(items) { item in
            ItemRow(item: item).id(item.id)
        }
    }
}
.scrollPosition(id: $position)

scrollTransition(iOS 17+)

.scrollTransition { content, phase in
    content
        .opacity(1 - abs(phase.value) * 0.5)
        .scaleEffect(phase.isIdentity ? 1.0 : 0.75)
}

onScrollGeometryChange(iOS 18+)

.onScrollGeometryChange(for: Bool.self) { geo in
    geo.contentOffset.y < geo.contentInsets.top
} action: { _, isTop in
    showBackButton = !isTop
}

onScrollVisibilityChange(iOS 18+)

VideoPlayer(player: player)
    .onScrollVisibilityChange(threshold: 0.2) { visible in
        visible ? player.play() : player.pause()
    }

リソース

WWDC: 2020-10031, 2022-10056, 2023-10148, 2024-10144, 2025-256

ドキュメント: /swiftui/lazyvstack, /swiftui/lazyvgrid, /swiftui/lazyhgrid, /swiftui/grid, /swiftui/outlinegroup, /swiftui/disclosuregroup

スキル: axiom-swiftui-layout, axiom-swiftui-layout-ref, axiom-swiftui-nav, axiom-swiftui-26-ref

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

関連スキル