Sheet background doesn't reach bottom when programmatically changing detent
Which platform is most relevant for your report?
iOS
Which technology does your report involve?
SwiftUI
What type of feedback are you reporting?
Incorrect/Unexpected Behavior
What build does the issue occur on?
iOS 17.4 Seed 3 (21E5200d)
Where does the issue occur?
On device
Run the given code.
Make sure the sheet is presented.
Press "Toggle detent" to toggle the sheet detent.
When going from a larger detent to a shorter detent, the background of the sheet doesn't reach the bottom of the screen.
Unexpectedly, we can see a gap during the animation. This gap should not exist.
See the attached workaround, where extra padding is added to the bottom of the background.
Demo
Workaround
import SwiftUI
struct ContentView : View {
@State private var presented = true
@State private var detent : PresentationDetent = . large
var body : some View {
Button ( " Present " ) {
presented = true
}
. sheet ( isPresented: $presented) {
VStack {
Button ( " Toggle detent " ) {
if detent == . large {
detent = . medium
} else {
detent = . large
}
}
. padding ( . top, 50 )
Spacer ( )
}
. presentationBackground {
Color . red
}
. presentationDetents ( [ . medium, . large] , selection: $detent)
}
}
}
#Preview {
ContentView ( )
}
import SwiftUI
struct ContentView : View {
@State private var presented = true
@State private var detent : PresentationDetent = . large
var body : some View {
Button ( " Present " ) {
presented = true
}
. sheet ( isPresented: $presented) {
VStack {
Button ( " Toggle detent " ) {
if detent == . large {
detent = . medium
} else {
detent = . large
}
}
. padding ( . top, 50 )
Spacer ( )
}
. presentationBackground {
Color . red
. padding ( . bottom, - 1000 )
}
. presentationDetents ( [ . medium, . large] , selection: $detent)
}
}
}
#Preview {
ContentView ( )
}