Skip to content

Instantly share code, notes, and snippets.

@UnderscoreDavidSmith
Created May 23, 2023 15:45
Show Gist options
  • Save UnderscoreDavidSmith/08fee46b13e38347ccfc0280a415fc64 to your computer and use it in GitHub Desktop.
Save UnderscoreDavidSmith/08fee46b13e38347ccfc0280a415fc64 to your computer and use it in GitHub Desktop.
Weird ScrollView bug when backgrounding during .sheet presentation
struct ContentView: View {
@State var presentSheet1:Bool = false
@State var presentSheet2:Bool = false
var body: some View {
ScrollView {
VStack {
Button {
presentSheet1 = true
} label: {
Text("1")
.font(Font.system(size: 32))
.frame(minWidth:0, maxWidth:.infinity)
.background(Color.red)
}
Button {
presentSheet2 = true
} label: {
Text("2")
.font(Font.system(size: 32))
.frame(minWidth:0, maxWidth:.infinity)
.background(Color.green)
}
Spacer()
}.sheet(isPresented: $presentSheet1) {
Color.red
.overlay(Text("1").font(Font.system(size: 128)))
}.sheet(isPresented: $presentSheet2) {
Color.green
.overlay(Text("2").font(Font.system(size: 128)))
}
}
}
}
@UnderscoreDavidSmith
Copy link
Author

To reproduce this bug make a basic SwiftUI iOS project and replace the default ContentView with this view, then:

  1. Launch the app
  2. Tap on either of the buttons
  3. Background the app (by tapping on the Home button, or swiping up)
  4. Return to the app and dismiss the sheet by swiping down on the sheet
  5. Try to tap on the "1" button,

Instead of the "1" button being tappable instead the top several points of the screen are completely unresponsive, around the top of the "2" button there is a tappable region, but it points to the "1" button instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment