I stumbled into a very weird bug that seems to concern SwiftUI as a whole. I am able to reproduce the bug with the following very simple view:
struct ContentView: View {
@State private var sheetVisible = false
var body: some View {
VStack {
Text("Some Button")
.onTapGesture {
sheetVisible = true
}
Spacer()
}
.sheet(isPresented: $sheetVisible) {
Text("Sheet Content")
}
}
}
The steps to reproduce the bug are as follows:
- Tap on the button to open the sheet
- Move the app into the background with the sheet open
- Open the app again and pull down the sheet
After that, the touch area of the button to open the sheet has moved down by approximately the height that the parent view is moved down visually when the sheet is open. Meaning, you cannot tap the button anymore, you have to tap way below the button.
I am not sure whether I did something wrong, though I cannot really imagine that being the case with the bug existing in an example as simple as the above.
My setup is as follows:
- Xcode 14.2 Build 14C18
- iPhone 14 Pro Simulator with iOS 16.2 (however we can reproduce the bug on our real devices with an iPhone 11 Pro, 12 Pro and 13 Pro across different iOS versions for a while now)
I filed a bug report but I also wanted to draw attention to the bug here and ask other developers to test whether they can confirm this is a bug and whether this affects their apps as well.
Your example sums it up well. My app has the same issue on iOS >= 16.1. iOS 15 seems not to be affected.
Using the Accessibility Inspector or View Debugger confirms the shifted controls though it is rendered at the correct position.
I'm still looking for a solution or at least a quick-fix, because it breaks my app's flow pretty bad.