Search code examples
swiftuiswiftui-sheet

Allow user interaction in views behind a sheet in SwiftUI


Apple recently announced that half sheets will soon be feasible in SwiftUI with the addition of the .presentationDetents(detents: Set<PresentationDetent>) modifier.

Sadly, this still seems to block any user interaction with the views behind the sheet.

Is there any way to allow user interaction with the views behind the sheet?


Solution

  • With the latest Xcode 14.3 Beta and iOS 16.4 Beta you can finally do this with .sheet using presentationBackgroundInteraction view modifier:

    .presentationDetents([.height(100), .medium, .large])
    .presentationBackgroundInteraction(
        .enabled(upThrough: .medium)
    )
    

    This will enable interaction with view behind the sheet when the sheet is in .height(100) or .medium detents.