layout
Skill4 starsChanged 6 months agoMITView on GitHub
Use when arranging SwiftUI views, fixing layout bugs, extracting subviews, handling safe areas, replacing GeometryReader misuse, or building responsive VStack/HStack/ZStack compositions.
14 other projects use a version of this.
Adopted by
Most recently taken up by
- fracazo/design-systemtheir own version, first seen Nov 8, 2026
- theexperiencecompany/gaiatheir own version, first seen Nov 3, 2026
- vijaysuperpositionist/skillstheir own version, first seen Nov 1, 2026
- NguyenHuy190303/EEPtheir own version, first seen Oct 17, 2026
- The-Utopia-Studio/skillstheir own version, first seen Oct 13, 2026
- excatt/superclaude-plusplustheir own version, first seen Oct 13, 2026
Used with
Projects with it also use motion.
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.
leonaaardobSkillmotion
Complete Motion.dev documentation - modern animation library for React, JavaScript, and Vue (formerly Framer Motion)
Also in 3 projects that use this
Other versions14 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 14
- 10xChengTu/Mux0★ 337same name
- theexperiencecompany/gaia★ 325same name
- owshq-mec/semana-ai-data-engineer★ 122same name
- StyleSwift/StyleSwift★ 61same name
- excatt/superclaude-plusplus★ 14same name
- The-Utopia-Studio/skills★ 6same name
- fracazo/design-system★ 4same name
- tyfarrago-hub/taste★ 3same name
- IamK77/Skill★ 2same name
- NguyenHuy190303/EEP★ 2same name
4 more not listed
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 repository76 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/components.mdcCursor rule
- .cursor/rules/currency.mdcCursor rule
- .cursor/rules/design-system.mdcCursor rule
- .cursor/rules/file-structure.mdcCursor rule
- .cursor/rules/forbidden-patterns.mdcCursor rule
- .cursor/rules/mvvm-architecture.mdcCursor rule
- .cursor/rules/pricing-display.mdcCursor rule
- .cursor/rules/scope.mdcCursor rule
- .cursor/rules/swift-conventions.mdcCursor rule
- accessibilitySkill
- animationsSkill
- apple-developer-authSkill
- apple-signinSkill
- app-store-preflightSkill
- asc-app-create-uiSkill
- asc-aso-auditSkill
- asc-build-lifecycleSkill
- asc-cli-usageSkill
- asc-crash-triageSkill
- asc-id-resolverSkill
- asc-localize-metadataSkill
- asc-metadata-syncSkill
- asc-metadata-yamlSkill
- asc-notarizationSkill
- asc-ppp-pricingSkill
- asc-release-flowSkill
- asc-revenuecat-catalog-syncSkill
- asc-screenshot-resizeSkill
- asc-shots-pipelineSkill
- asc-signing-setupSkill
- ascSkill
- asc-submission-healthSkill
- asc-subscription-localizationSkill
- asc-testflight-orchestrationSkill
- asc-wall-submitSkill
- asc-whats-new-writerSkill
- asc-workflowSkill
- asc-xcode-buildSkill
- billing-finance-calculatorSkill
- buildSkill
- business-modelSkill
- chartsSkill
- consolidate-errorsSkill
- content-composerSkill
- crashSkill
- debuggingSkill
- feature-directory-structureSkill
- feedback-statesSkill
- fix-errorSkill
- formsSkill
- foundation-modelsSkill
- hapticsSkill
- healthkitSkill
- listsSkill
- navigationSkill
- notificationsSkill
- onboarding-questionnaireSkill
- onboardingSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. 0 are common, 4 are distinctive, and 9 are very specific to this project.
0
Common
Most of the 14 edited versions we read keep these.
4
Distinctive
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 95
Use conditionals when you truly have different views:
- Very specific: line 189
Use ZStack to compose multiple peer views that should be layered together.
- Very specific: line 191
Prefer overlay / background when decorating a primary view.
- Very specific: line 300
Use @Environment(\.horizontalSizeClass) for layout decisions — never device checks:
- Very specific: line 331
Always use GridItem(.adaptive(minimum:maximum:)) — automatically adjusts columns:
- Distinctive: line 368
Use when a component should pick the best layout for available space:
- Very specific: line 380
Prefer containerRelativeFrame over GeometryReader:
- Very specific: line 387
NEVER use UIDevice.current, UIScreen.main.bounds, or #if targetEnvironment for layout
- Distinctive: line 388
NEVER hardcode frame widths or column counts
- Very specific: line 389
ALWAYS use GridItem(.adaptive(minimum:)) for grids
- Distinctive: line 390
ALWAYS constrain text to ~700pt max width on wide screens
- Very specific: line 391
ALWAYS use .leading/.trailing — never .left/.right
- Very specific: line 392
Use @ScaledMetric for custom dimensions that respect Dynamic Type
“Common” is measured: kept by at least 6 in 10 of the 14 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 & View Structure Reference
Comprehensive guide to stack layouts, view composition, subview extraction, and layout best practices.
Relative Layout Over Constants
// Good - relative to actual layout
GeometryReader { geometry in
VStack {
HeaderView()
.frame(height: geometry.size.height * 0.2)
ContentView()
}
}
// Avoid - magic numbers that don't adapt
VStack {
HeaderView()
.frame(height: 150) // Doesn't adapt to different screens
ContentView()
}Context-Agnostic Views
Views should work in any context. Never assume presentation style or screen size.
// Good - adapts to given space
struct ProfileCard: View {
let user: User
var body: some View {
VStack {
Image(user.avatar)
.resizable()
.aspectRatio(contentMode: .fit)
Text(user.name)
Spacer()
}
.padding()
}
}
// Avoid - assumes full screen
Image(user.avatar)
.frame(width: UIScreen.main.bounds.width) // Wrong!Own Your Container
Custom views should own static containers but not lazy/repeatable ones.
// Good - owns static container
struct HeaderView: View {
var body: some View {
HStack {
Image(systemName: "star")
Text("Title")
Spacer()
}
}
}View Structure Principles
SwiftUI's diffing algorithm compares view hierarchies to determine what needs updating.
Prefer Modifiers Over Conditional Views
// Good - same view, different states
SomeView()
.opacity(isVisible ? 1 : 0)
// Avoid - creates/destroys view identity
if isVisible {
SomeView()
}Use conditionals when you truly have different views:
// Correct - fundamentally different views
if isLoggedIn {
DashboardView()
} else {
LoginView()
}Extract Subviews, Not Computed Properties
The Problem with @ViewBuilder Functions
// BAD - re-executes complexSection() on every tap
struct ParentView: View {
@State private var count = 0
var body: some View {
VStack {
Button("Tap: \(count)") { count += 1 }
complexSection() // Re-executes every tap!
}
}
@ViewBuilder
func complexSection() -> some View {
ForEach(0..<100) { i in
HStack {
Image(systemName: "star")
Text("Item \(i)")
}
}
}
}The Solution: Separate Structs
// GOOD - ComplexSection body SKIPPED when its inputs don't change
struct ParentView: View {
@State private var count = 0
var body: some View {
VStack {
Button("Tap: \(count)") { count += 1 }
ComplexSection() // Body skipped during re-evaluation
}
}
}
struct ComplexSection: View {
var body: some View {
ForEach(0..<100) { i in
HStack {
Image(systemName: "star")
Text("Item \(i)")
}
}
}
}Container View Pattern
// BAD - closure prevents SwiftUI from skipping updates
struct MyContainer<Content: View>: View {
let content: () -> Content
var body: some View {
VStack { Text("Header"); content() }
}
}
// GOOD - view can be compared
struct MyContainer<Content: View>: View {
@ViewBuilder let content: Content
var body: some View {
VStack { Text("Header"); content }
}
}ZStack vs overlay/background
Use ZStack to compose multiple peer views that should be layered together.
Prefer overlay / background when decorating a primary view.
// GOOD - decoration in overlay
Button("Continue") { }
.overlay(alignment: .trailing) {
Image(systemName: "lock.fill")
.padding(.trailing, 8)
}
// GOOD - background shape takes parent size
HStack(spacing: 12) {
Image(systemName: "tray")
Text("Inbox")
}
.background {
Capsule()
.strokeBorder(.blue, lineWidth: 2)
}Layout Performance
Avoid Layout Thrash
// Bad - deep nesting, excessive layout passes
VStack { HStack { VStack { HStack { Text("Deep") } } } }
// Good - flatter hierarchy
VStack { Text("Shallow"); Text("Structure") }Minimize GeometryReader (use iOS 17+ alternatives)
// Good - single geometry reader or containerRelativeFrame
containerRelativeFrame(.horizontal) { width, _ in
width * 0.8
}Gate Frequent Geometry Updates
// Good - gate by threshold
.onPreferenceChange(ViewSizeKey.self) { size in
let difference = abs(size.width - currentSize.width)
if difference > 10 { currentSize = size }
}View Logic and Testability
// Good - logic in testable model (iOS 17+)
@Observable
@MainActor
final class LoginViewModel {
var email = ""
var password = ""
var isValid: Bool {
!email.isEmpty && password.count >= 8
}
func login() async throws { }
}
struct LoginView: View {
@State private var viewModel = LoginViewModel()
var body: some View {
Form {
TextField("Email", text: $viewModel.email)
SecureField("Password", text: $viewModel.password)
Button("Login") {
Task { try? await viewModel.login() }
}
.disabled(!viewModel.isValid)
}
}
}Action Handlers
// Good - action references method
struct PublishView: View {
@State private var viewModel = PublishViewModel()
var body: some View {
Button("Publish Project", action: viewModel.handlePublish)
}
}iPad-Specific Patterns
Size Classes
Use @Environment(\.horizontalSizeClass) for layout decisions — never device checks:
@Environment(\.horizontalSizeClass) private var horizontalSizeClass| Context | horizontalSizeClass |
| iPad full-screen (any orientation) | .regular |
| iPad Split View (narrow) | .compact |
| iPad Split View (wide) | .regular |
Critical: iPad in Split View can report .compact — always use size classes, never UIDevice.current.
Adaptive Layout Switching
@Environment(\.horizontalSizeClass) private var sizeClass
var body: some View {
let layout = sizeClass == .compact
? AnyLayout(VStackLayout(spacing: 16))
: AnyLayout(HStackLayout(spacing: 24))
layout {
ContentBlockA()
ContentBlockB()
}
}Adaptive Grids
Always use GridItem(.adaptive(minimum:maximum:)) — automatically adjusts columns:
LazyVGrid(
columns: [GridItem(.adaptive(minimum: 160, maximum: 320))],
spacing: 16
) {
ForEach(items) { item in CardView(item: item) }
}
.padding()Readability on Wide Screens
Constrain text content width on iPad to maintain readability:
ScrollView {
content
.frame(maxWidth: 700)
.frame(maxWidth: .infinity)
}Form Layout
Forms should not stretch full-width on iPad:
@Environment(\.horizontalSizeClass) private var sizeClass
Form {
Section("General") { /* ... */ }
}
.formStyle(.grouped)
.frame(maxWidth: sizeClass == .regular ? 600 : .infinity)ViewThatFits (component-level)
Use when a component should pick the best layout for available space:
ViewThatFits {
HStack(spacing: 16) { icon; title; subtitle; actionButton }
VStack(alignment: .leading, spacing: 8) {
HStack { icon; title }; subtitle; actionButton
}
}Relative Sizing
Prefer containerRelativeFrame over GeometryReader:
Image("photo")
.containerRelativeFrame(.horizontal, count: 3, span: 1, spacing: 16)iPad Layout Rules
- NEVER use
UIDevice.current,UIScreen.main.bounds, or#if targetEnvironmentfor layout - NEVER hardcode frame widths or column counts
- ALWAYS use
GridItem(.adaptive(minimum:))for grids - ALWAYS constrain text to ~700pt max width on wide screens
- ALWAYS use
.leading/.trailing— never.left/.right - Use
@ScaledMetricfor custom dimensions that respect Dynamic Type
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.

