layout
Skill777 starsChanged 5 months agoMITView on GitHub
SwiftUI layout beyond stacks — the Layout protocol (when custom layout beats GeometryReader), Grid vs lazy grids, custom containers with sections and container values, and lazy-stack/ScrollView performance rules (what breaks laziness, prefetch discipline, scroll APIs). Use when building custom layouts or containers, fixing lazy-stack jank or memory growth, or wiring programmatic/snapping scrolling.
9 other projects use a version of this.
Adopted by
Most recently taken up by
- IamK77/Skilltheir own version, first seen Sep 19, 2026
- theexperiencecompany/gaiatheir own version, first seen Sep 17, 2026
- excatt/superclaude-plusplustheir own version, first seen Sep 7, 2026
- HugoLopes45/design-skillstheir own version, first seen Aug 26, 2026
- moasq/ios-dev-agenttheir own version, first seen May 26, 2026
- tyfarrago-hub/tastetheir own version, first seen May 16, 2026
Used with
Projects with it also use overdrive, shape and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
nikafastovets-langSkilloverdrive
Push interfaces past conventional limits with technically ambitious implementations. Whether that's a shader, a 60fps virtual table, spring physics on a dialog, or scroll-driven reveals — make users ask "how did they do that?
Also in 5 projects that use this
tdiminoSkillshape
Plan the UX and UI for a feature before writing code. Run a structured discovery interview, then produce a design brief (.design-context.md) that guides implementation. Establishes design direction, constraints, and strategy before any code is written. Triggers on plan the design, design brief, shape the UX, before we build, design discovery.
Also in 5 projects that use this
nikafastovets-langSkilltypeset
Improve typography by fixing font choices, hierarchy, sizing, weight consistency, and readability. Makes text feel intentional and polished.
Also in 5 projects that use this
mtctSkillquieter
Tone down overly bold or visually aggressive designs. Reduces intensity while maintaining design quality and impact.
Also in 5 projects that use this
mtctSkilldelight
Add moments of joy, personality, and unexpected touches that make interfaces memorable and enjoyable to use. Elevates functional to delightful.
Also in 5 projects that use this
MindrallySkillmotion
Expert guidelines for building performant animations with Motion (formerly Motion One) vanilla JavaScript animation library
Also in 3 projects that use this
- +4 more from mtct
Other versions9 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 9
- 10xChengTu/Mux0★ 346same name
- theexperiencecompany/gaia★ 306same name
- StyleSwift/StyleSwift★ 62same name
- excatt/superclaude-plusplus★ 14same name
- moasq/ios-dev-agent★ 4same name
- tyfarrago-hub/taste★ 4same name
- Qredence/skills★ 3same name
- IamK77/Skill★ 2same name
- HugoLopes45/design-skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository183 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- app-intentsSkill
- foundation-modelsSkill
- apple-intelligenceSkill
- visual-intelligenceSkill
- ad-attributionSkill
- app-description-writerSkill
- apple-search-adsSkill
- iap-finalizerSkill
- keyword-optimizerSkill
- marketing-strategySkill
- originality-checkSkill
- ratings-mechanicsSkill
- rejection-handlerSkill
- review-response-writerSkill
- screenshot-plannerSkill
- app-storeSkill
- web-presenceSkill
- core-mlSkill
- animation-patternsSkill
- game-feelSkill
- liquid-glassSkill
- sf-symbolsSkill
- designSkill
- typographySkill
- ui-prototypingSkill
- ux-writingSkill
- attributed-stringSkill
- foundationSkill
- accessibility-generatorSkill
- account-deletionSkill
- analytics-setupSkill
- announcement-bannerSkill
- app-clipSkill
- app-extensionsSkill
- app-icon-generatorSkill
- app-store-assetsSkill
- auth-flowSkill
- background-processingSkill
- ci-cd-setupSkill
- cloudkit-syncSkill
- consent-flowSkill
- custom-product-pagesSkill
- data-exportSkill
- debug-menuSkill
- deep-linkingSkill
- error-monitoringSkill
- feature-flagsSkill
- featuring-nominationSkill
- feedback-formSkill
- force-updateSkill
- http-cacheSkill
- image-loadingSkill
- in-app-eventsSkill
- lapsed-userSkill
- live-activity-generatorSkill
- localization-setupSkill
- logging-setupSkill
- milestone-celebrationSkill
- networking-layerSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
2 rules. 0 are common, 0 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 9 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 42
Don't build fallbacks into the layout — wrap alternatives in ViewThatFits.
- Very specific: line 87
Don't drive layout from onGeometryChange height feedback (content shoves, targeting breaks) — that's the custom Layout case above.
“Common” is measured: kept by at least 6 in 10 of the 9 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
SwiftUI Layout & Containers
The layer between "stacks and spacers" and "it scrolls like butter with 100k rows" — Apple's
Layout protocol, container composition, and the lazy-stack rules from the WWDC26 deep dive.
View identity/data-flow questions route to swiftui/data-flow.
When This Skill Activates
- "Make these buttons equal width" / measurement-dependent layout
- Building a reusable container (custom List/board/carousel) that should accept ForEach + sections
- Lazy stack jank, memory growth, scroll-position bugs, broken scroll targeting
- Programmatic scrolling, paging/snapping, scroll-linked effects
- GeometryReader causing layout loops or mangled sizing
Custom Layout protocol (not GeometryReader)
Reach for a custom Layout whenever you must measure subviews and feed the measurement back
into layout — GeometryReader only measures its container and can't influence the engine.
Canonical case: equal-width buttons.
sizeThatFits: propose.unspecifiedto read each subview's ideal size (subviews.map { $0.sizeThatFits(.unspecified) }); guard empty subviews;replacingUnspecifiedDimensions()for nil proposal dimensions.placeSubviews: never assume origin (0,0) — usebounds.minX/midX(non-zero origins are what make layouts composable);place(at:anchor:proposal:)with a proposal that may differ from the ideal size (that's how equal widths happen).- Respect spacing preferences:
subviews[i].spacing.distance(to:along:), taking the larger of conflicting preferences — matching built-in containers. No hardcoded 8s. - Per-subview data via
LayoutValueKey(+ alayoutValueconvenience modifier), read assubview[Key.self]. - Cache only after Instruments shows layout cost — it's an optimization, not a requirement.
- Switch layouts without killing identity:
AnyLayout(HStackLayout())↔ custom layout with.animation(_:value:)— SwiftUI sees one changing view, so state survives and it animates. - Don't build fallbacks into the layout — wrap alternatives in
ViewThatFits.
Grid decisions
| Need | Use |
| Static 2D with cross-row alignment | Grid/GridRow (+ gridCellColumns to span, gridColumnAlignment per column) |
| Scrollable, large content | LazyVGrid/LazyHGrid (only visible views load; one axis fixed up front) |
| "First arrangement that fits" | ViewThatFits |
Custom containers (Demystify Containers)
Make containers that compose like List does:
- API shape: a trailing
@ViewBuilder var content: Content— callers can then mix static views,ForEach, and conditionals. - Iterate resolved children with
ForEach(subviews: content); need the whole collection (count/chunking)?Group(subviews: content) { subviews in … }. - Internalize declared vs resolved: one declared ForEach resolves to N subviews; Group to
its children; EmptyView to zero;
ifconditionally. Counting declared views is a bug. - Sections are opt-in:
ForEach(sections: content), readingsection.header/section.content; checkheader.isEmptybefore rendering the slot. - Per-child customization via container values:
extension ContainerValues { @Entry var … }, set with a convenience modifier, read viasubview.containerValues. Scoping model: Environment flows down · Preferences flow up · container values reach only the direct container. Setting one on aSectionstyles the whole section.
Lazy stacks & scrolling performance (WWDC26 rules)
LazyVStack builds views only until the viewport fills; totals and offsets are estimated from average placed-view size and corrected as you scroll. Everything below follows from that:
- One subview per ForEach element, always. An
ifinside a row (0-or-1 views) forces the stack to keep off-screen views + their@Statealive to preserve indices — and environment changes then re-evaluate off-screen bodies. Filter at the data layer (@Querypredicate); gate auth-type conditions outside the stack. - Never key logic off absolute scroll offset in a lazy stack (
onScrollGeometryChangesees estimates) — useonScrollTargetVisibilityChange(threshold: 0.8)for visibility triggers. - Set up in
init, notonAppear(_model = State(initialValue:)): body runs during prefetch;onAppearfires only on-screen, throwing prefetch work away and causing post-appearance size jumps. Start async loads ininit/task. - Don't persist meaningful state in row
@State— off-screen views are eventually released. Hoist (@State var highlighted: Set<ID>outside,@Bindingdown). scrollTransitiontransforms must stay inside the original frame (scale ✅; rotations escaping the frame make views vanish early).- Don't drive layout from
onGeometryChangeheight feedback (content shoves, targeting breaks) — that's the customLayoutcase above. - Nest
LazyHStackinsideLazyVStackfreely (unscrolled rows stay unloaded) — but fix child heights (lineLimit, explicit frames) in the horizontal stacks. pinnedViews: [.sectionHeaders]pins headers; infinite scroll = trailingProgressView().onAppear { fetchNextPage() }after the ForEach.
The scroll API map
- Snapping/paging:
scrollTargetLayout()+scrollTargetBehavior(.viewAligned/.paging). - Track/control position:
scrollPositionbinding; programmaticScrollPosition+scrollTo(id:)— works for unloaded targets if IDs map to stable one-subview elements. - Scroll-linked effects:
scrollTransition(enter/leave viewport) andvisualEffect(geometry without GeometryReader) — details indesign/animation-patterns. - Reactions:
onScrollGeometryChange(fine outside lazy estimation),onScrollVisibilityChange(autoplay/analytics). - Performance floor: list/scroll internals were rewritten (WWDC25) — macOS lists ~6× faster at
100k+ rows, and lazy loading works in nested
ScrollView+LazyVStack; profile with the SwiftUI instrument (performance/swiftui-debugging).
Output Format
Layout review: Symptom | Rule violated | Fix — check the one-subview-per-element rule first
in any lazy-stack complaint; it explains most jank, memory growth, and targeting bugs.
References
- https://developer.apple.com/videos/play/wwdc2022/10056/ (Compose custom layouts)
- https://developer.apple.com/videos/play/wwdc2024/10146/ (Demystify SwiftUI containers)
- https://developer.apple.com/videos/play/wwdc2026/321/ (Dive into lazy stacks and scrolling)
- Related skills:
swiftui/data-flow(identity/ForEach IDs),performance/swiftui-debugging,design/animation-patterns(scroll-linked effects)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

