Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save edudnyk/f755008c1cb750c9aa7e735f670399fc to your computer and use it in GitHub Desktop.
Save edudnyk/f755008c1cb750c9aa7e735f670399fc to your computer and use it in GitHub Desktop.
Initial sandwich solution implementation in SheeKit
final class AdaptiveDelegate<Item>: NSObject, UIPopoverPresentationControllerDelegate, UISheetPresentationControllerDelegate where Item : Identifiable {
weak var sheetHost: SheetHostingController<Item>?
var dismissedByUserCallback: DismissAction?
var isInteractiveDismissDisabled = false
var selectedDetentIdentifierBinding: Binding<UISheetPresentationController.Detent.Identifier?>?
override init() {
super.init()
}
func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
dismissedByUserCallback?()
}
func presentationControllerShouldDismiss(_ presentationController: UIPresentationController) -> Bool {
!isInteractiveDismissDisabled
}
func sheetPresentationControllerDidChangeSelectedDetentIdentifier(_ sheetPresentationController: UISheetPresentationController) {
selectedDetentIdentifierBinding?.wrappedValue = sheetPresentationController.selectedDetentIdentifier
}
}
final class SheetPresenterController: UIViewController {}
struct SheetPresenterControllerRepresentable<Item>: UIViewControllerRepresentable where Item : Identifiable {
@Binding var item: Item?
@Environment(\.shee_isInteractiveDismissDisabled) private var isInteractiveDismissDisabled
let onDismiss: (() -> Void)?
func makeCoordinator() -> AdaptiveDelegate<Item> { .init() }
func makeUIViewController(context: Context) -> SheetPresenterController { .init() }
func updateUIViewController(_ presenter: SheetPresenterController, context: Context) {}
static func dismantleUIViewController(_ presenter: SheetPresenterController, coordinator: AdaptiveDelegate<Item>) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment