Last active
October 2, 2021 14:43
-
-
Save edudnyk/f755008c1cb750c9aa7e735f670399fc to your computer and use it in GitHub Desktop.
Initial sandwich solution implementation in SheeKit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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