CustomPresentationDetent
The definition of a custom detent with a calculated height.
Declaration
protocol CustomPresentationDetentOverview
You can create and use a custom detent with built-in detents.
extension PresentationDetent {
static let bar = Self.custom(BarDetent.self)
static let small = Self.height(100)
static let extraLarge = Self.fraction(0.75)
}
private struct BarDetent: CustomPresentationDetent {
static func height(in context: Context) -> CGFloat? {
max(44, context.maxDetentValue * 0.1)
}
}
struct ContentView: View {
@State private var showSettings = false
@State private var selectedDetent = PresentationDetent.bar
var body: some View {
Button("View Settings") {
showSettings = true
}
.sheet(isPresented: $showSettings) {
SettingsView(selectedDetent: $selectedDetent)
.presentationDetents(
[.bar, .small, .medium, .large, .extraLarge],
selection: $selectedDetent)
}
}
}