I have a button and when I click on it a new View will present as a sheet. In SwiftUI by default swipe down gesture will dismiss the sheet view. I want to restrict it.
I'll have a button for dismissing. Until I press that button sheet should not get dismissed.
iOS 14: workaround -> fullScreenCover
fullScreenCover(isPresented:onDismiss:content:)
https://developer.apple.com/documentation/swiftui/view/fullscreencover(ispresented:ondismiss:content:)
iOS 15: interactiveDismissDisabled
.interactiveDismissDisabled(false)
https://developer.apple.com/documentation/swiftui/path/interactivedismissdisabled(_:)
We have created a SwiftUI style extension, at https://gist.github.com/mobilinked/9b6086b3760bcf1e5432932dad0813c0
/// Example:
struct ContentView: View {
@State private var presenting = false
var body: some View {
VStack {
Button {
presenting = true
} label: {
Text("Present")
}
}
.sheet(isPresented: $presenting) {
ModalContent()
.allowAutoDismiss { false }
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With