Skip to content

Latest commit

 

History

History
53 lines (41 loc) · 1.35 KB

README.md

File metadata and controls

53 lines (41 loc) · 1.35 KB

SwiftUISheetExtension

Japanese README: README-ja.md

example screenshot

A SwiftUI extension that provides sheet_, behaving like the standard sheet, but with two extra features:

  • @Environment(\.dismissSheet) to programmatically dismiss the currently presented sheet
  • onDismissAttempt_, triggered only if you’ve set interactiveDismissDisabled(true) and the user attempts to dismiss

Usage

Presenting a sheet

@State private var isSheetPresented = false

Button("Open Sheet") {
    isSheetPresented = true
}
.sheet_(
    isPresented: $isSheetPresented,
    onDismiss: { print("Sheet dismissed") }
) {
    SheetContentView()
}

Dismissing from inside

@Environment(\.dismissSheet) private var dismissSheet

Button("Dismiss") {
    dismissSheet()
}

Intercepting dismiss (requires interactiveDismissDisabled(true))

@Environment(\.dismissSheet) private var dismissSheet

.interactiveDismissDisabled(true)
.onInteractiveDismissAttempt_ {
    showAlert = true
}
.alert("Dismiss?", isPresented: $showAlert) {
    Button("Cancel", role: .cancel) {}
    Button("Dismiss", role: .destructive) {
        dismissSheet()
    }
}