Detents & Drag Indicators
Resize sheets with presentation detents.
Detents & Drag Indicators is a free SwiftUI Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the SwiftUI Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Are Detents?
A detent is a stopping height a sheet can rest at, like half-open or full. They let users resize the sheet by dragging it. 📏
The presentationDetents Modifier
Add presentationDetents inside the sheet content to list the heights it can snap to. Pass a set of detents to enable resizing.
.presentationDetents([.medium, .large])Medium and Large
The two built-in detents are .medium, about half the screen, and .large, nearly full height. Offer both so users pick what fits.
.presentationDetents([.medium, .large])A Fixed Height Detent
Use .height to pin a sheet to an exact point size. This is great for short forms that should not grow taller than needed.
.presentationDetents([.height(220)])A Fraction Detent
The .fraction detent sizes the sheet to a share of the screen, like a third. It adapts nicely across different device sizes.
.presentationDetents([.fraction(0.33)])The Drag Indicator
The little grabber bar at the top is the drag indicator. It hints that the sheet can be pulled up, down, or dismissed.
Showing the Grabber
Add presentationDragIndicator set to .visible to always show the grabber, even when only one detent is available.
.presentationDragIndicator(.visible)Combining Modifiers
Detents and the drag indicator stack together on the sheet content. Apply both for a resizable sheet with a clear grab handle. ✨
ContentView()
.presentationDetents([.medium, .large])
.presentationDragIndicator(.visible)Tracking the Selected Detent
Bind presentationDetents to a state value to know which height the user chose, so your layout can react to the current size.
.presentationDetents([.medium, .large], selection: $detent)Why Detents Matter
Detents keep sheets non-blocking. A medium sheet lets users glance at content while still seeing the screen behind it.
One Detent, No Resize
If you pass a single detent, the sheet stays one fixed height and cannot be resized, though it can still be swiped to dismiss.
.presentationDetents([.medium])Quick Check
Which modifier lets a sheet snap to multiple heights?
Recap: Detents
You can now resize sheets with detents like .medium, .large, and .fraction, plus show a grabber with the drag indicator. Great progress! 🎉
Frequently asked questions
Is the “Detents & Drag Indicators” lesson free?
Yes — the full text of “Detents & Drag Indicators” is free to read here on the web, and the SwiftUI Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the SwiftUI Academy course, upgrade to CoddyKit PRO.
What will I learn in “Detents & Drag Indicators”?
Resize sheets with presentation detents. You practise SwiftUI Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start SwiftUI Academy?
No prior experience is required. SwiftUI Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Detents & Drag Indicators” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this SwiftUI Academy lesson?
Yes. Every SwiftUI Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Presenting a Sheet
- Detents & Drag Indicators
- Alerts with Actions
- Confirmation Dialogs