Code Block struct ModalView<Content: View>: UIViewControllerRepresentable { var content: () -> Content func makeUIViewController(context: Context) -> UIHostingController<Content> { let controller = UIHostingController(rootView: content()) controller.isModalInPresentation = true return controller } func updateUIViewController(_ imagePickerController: UIHostingController<Content>, context: Context) {} }
From my main app view, I then present the ModalView as a sheet:
Code Block struct ContentView: View { @State var presentSheet: Bool = true var body: some View { Text("Hello, world!") .sheet(isPresented: $presentSheet) { ModalView { Text("Sheet") } } } }
But the user is still able to dismiss the ModalView by swiping down. I would expect this sheet to be non-dismissible. Is anything like this supposed to work? If not, is there some other way to prevent the dismissal of a sheet in SwiftUI?
The closest workaround I've found is to apply .highPriorityGesture(DragGesture()) to the content of the sheet, but swiping down with two fingers still works.
My ideal API for this would be one of a few things:
Another argument isModal passed to the .sheet modifier.
A modifier like the Stack Overflow answer enables
Behavior is automatically enabled if I call .sheet(isPresented: .constant(shouldPresentSheet).