Skip to content

ObuchiYuki/SwiftUISheetExtension

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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()
    }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages