5

The behavior I am getting when using the .sheet modifier on SwiftUI is that the displayed sheet cannot be dismissed using swipe down gesture on a Mac (Catalyst) which is expected because ... Mac doesn't come with a touchscreen. This leads to having to add many #if targetEnvironment(macCatalyst) ... #endif to add a button to close the sheet:

struct ContentView: View {
    @State private var showSheet = false

    var body: some View {
        VStack {
            Button("Show dialog") {
                showSheet = true
            }
        }.sheet(isPresented: $showSheet) {
            VStack {
                Text("Dialog").font(.title)
#if targetEnvironment(macCatalyst)
                Button("Close", action: { showSheet = false })
#endif
                Spacer()
            }.padding(10)
        }
    }
}

Is there a better solution?

An Hoa
  • 1,207
  • 12
  • 38

0 Answers0