VisionOS : Cannot Dismiss a Presented Sheet

74 views Asked by At

I need to use a presented sheet (not Popover) in a VisionOS app. It is trivial to get the sheet to appear correctly but I cannot get it to disappear by gesture (i.e. swipe down) in the simulator? Programmatic dismissal works but is clumsy from a UI perspective.

This is the code:

struct ContentView: View {
    
    @State var displaySheet : Bool = false
    
    var body: some View {
        VStack {
        
            
            Toggle("Display Sheet", isOn: $displaySheet)
                .toggleStyle(.switch)
                .padding(.horizontal,100)
        }
        .padding()
        .sheet(isPresented: $displaySheet, content: {
            PresentedSheetView()
        })
    }
}


struct PresentedSheetView: View {
   
    var body: some View {
        VStack {
        
            Text("This is the presented sheet!")
            
        }
       
        .padding()
        .frame(width: 400, height: 400)
    }
}

Swipe down does not work. .onTapGesture to dismiss also will not work because in the real app there are other controls that are activated by tapping.

1

There are 1 answers

0
lorem ipsum On

I can reproduce the issue. You should file a bug report with Feedback Assistant.

For now you could add a Button to the toolbar or an onTapGesture but none of these solutions are ideal.

    .sheet(isPresented: $displaySheet, content: {
        PresentedSheetView()
            .onTapGesture {
                displaySheet.toggle()
            }
    })