History
Loading...
Loading...
September 24, 2025
.presentationDetents() to create half-height sheets or custom modal sizes. Chain multiple detents like .presentationDetents([.medium, .large]) to allow users to resize sheets by dragging.This pattern creates user-friendly modals that adapt to content needs while maintaining iOS native interaction patterns. Users can resize sheets naturally through drag gestures.
struct ContentView: View {
@State private var showSheet = false
@State private var selectedDetent: PresentationDetent = .medium
var body: some View {
Button("Show Smart Sheet") {
showSheet = true
}
.sheet(isPresented: $showSheet) {
SheetContent()
.presentationDetents(
[.height(200), .medium, .large],
selection: $selectedDetent
)
.presentationDragIndicator(.visible)
}
}
}
struct SheetContent: View {
var body: some View {
NavigationStack {
VStack(spacing: 20) {
Text("Adaptive Sheet Content")
.font(.title2)
ScrollView {
LazyVStack(spacing: 12) {
ForEach(1...20, id: \.self) { index in
Text("Item \(index)")
.padding()
.background(.regularMaterial)
.cornerRadius(8)
}
}
.padding()
}
}
.navigationTitle("Settings")
.navigationBarTitleDisplayMode(.inline)
}
}
}Multiple detents provide better UX by allowing users to choose their preferred view size, reduce cognitive load by showing appropriate content amounts, and maintain familiar iOS interaction patterns that users expect from native apps.