I want on opening max height content with .sheet(isPresented:), not to animate and shrink content behind (in red rectangle). Is it possible?
The background view gets smaller when the presentation detent is too large. You can see that the background view does not get smaller when using a .medium
detent for example.
Presumably there is a threshold for presentation detents, and if you go above that threshold, the background view gets smaller. You can set the detent to something just below that threshold.
What I've found to work is .fraction(0.999)
, or a custom detent whose height is 1 less than the maximum height.
struct ContentView: View {
@State var x = false
var body: some View {
Button("Click") {
x = true
}
.sheet(isPresented: $x) {
Text("Foo")
.presentationDetents([
.custom(CustomDetent.self) // or .fraction(0.999)
])
}
}
}
struct CustomDetent: CustomPresentationDetent {
static func height(in context: Context) -> CGFloat? {
return context.maxDetentValue - 1
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With