Post

Replies

Boosts

Views

Activity

Offset on tap items when reopening app with a sheet open
I am facing out a strange behavior that really looks like a SwiftUI bug. When I leave the app with a .sheet open and reopen it, all tappable content from parent view (such as Buttons) have an offset on tap. It is difficult to explain so here is a really simple example: struct ContentView: View { @State private var isOpen = false var body: some View { Button(action: { isOpen.toggle() }, label: { Text("Open sheet") .foregroundColor(.white) .padding() .background(.blue) }) .sheet(isPresented: $isOpen, content: { Text("Sheet content") }) } } To reproduce the issue follow those steps: Tap just below to the top border of blue button Open sheet: the sheet opens as expected. When the sheet is open, close the app (go back to Springboard, cmd+shift+H on Simulator). Reopen the app. You're still on the sheet view. Close the sheet. You're back on main view with blue button. Here is the bug: Tap again on the top of blue button, right below the top border. Nothing happens. You have to click few pixels below. There is an offset that makes all tappable items on main view (and children) not aligned. Other notices: When closing the app from main view, the bug doesn't appear. And even when the bug is here and I close the app from main view and reopen, the bug disappears. If I use a .fullScreenCover instead of .sheet, the bug doesn't appear. It really looks like a bug with .sheets open. Expected result would be that this offset does not appear and Buttons are still tappable on their area. Tested on Xcode 14.0 (14A309), iOS 16.0.x (Simulator and iPhone 14 Pro device) and Swift 5.
11
10
4.2k
Oct ’22