iosswiftui

Sheet dismiss gesture with swipe back gesture causes app to freeze


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):

  1. swipe down to dismiss the sheet
  2. swipe back (from left edge to the right) to dismiss the navigation view

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.

enter image description here

EDIT: Oct 2022: This bug is still present in iOS 16

EDIT: Sep 2023: This bug is still present in iOS 17


Solution

  • This is confirmed as fixed on iOS 17.2.1 (FB12402900).