I found a strange and frustrating behavior in SwiftUI. If you present a sheet from within a view in a navigation link and then (quickly and in order):
The app will freeze before going back to the root view. Backgrounding the app and foregrounding it will unstick it.
You have to perform the steps very quickly. Is there a workaround? I would like both gestures to work without interfering with each other.
This code will reproduce the issue:
struct ContentView: View {
@State var showSheet = false
var body: some View {
NavigationView {
VStack {
NavigationLink("blah") {
VStack {
Button("Show Sheet") {
showSheet.toggle()
}
.sheet(isPresented: $showSheet, onDismiss: nil) {
Text("Sheet")
}
}
}
}
}
}
}
Here is a gif of the issue in the simulator. First showing the issue, then showing that if you background the app, it resolves on it's own.
EDIT: Oct 2022: This bug is still present in iOS 16
EDIT: Sep 2023: This bug is still present in iOS 17
This is confirmed as fixed on iOS 17.2.1 (FB12402900).