presentationDetents(_:selection:)
Sets the available detents for the enclosing sheet, giving you programmatic control of the currently selected detent.
Declaration
nonisolated func presentationDetents(_ detents: Set<PresentationDetent>, selection: Binding<PresentationDetent>) -> some View
Parameters
- detents:
A set of supported detents for the sheet. If you provide more that one detent, people can drag the sheet to resize it.
- selection:
A Binding to the currently selected detent. Ensure that the value matches one of the detents that you provide for the
detentsparameter.
Discussion
By default, sheets support the large detent.
struct ContentView: View {
@State private var showSettings = false
@State private var settingsDetent = PresentationDetent.medium
var body: some View {
Button("View Settings") {
showSettings = true
}
.sheet(isPresented: $showSettings) {
SettingsView()
.presentationDetents(
[.medium, .large],
selection: $settingsDetent
)
}
}
}