Skip to content

Instantly share code, notes, and snippets.

@jordibruin
Created November 14, 2022 23:03
Show Gist options
  • Save jordibruin/3ed5dede27a390c49415d55dc3c77944 to your computer and use it in GitHub Desktop.
Save jordibruin/3ed5dede27a390c49415d55dc3c77944 to your computer and use it in GitHub Desktop.
Interact with background while presenting sheet
@available(iOS 16.0, *)
extension View {
func presentationDetents(
undimmed detents: Set<PresentationDetent>
) -> some View {
self.presentationDetents(detents)
.background(UndimmedDetentView())
}
func presentationDetents(
undimmed detents: Set<PresentationDetent>,
selection: Binding<PresentationDetent>
) -> some View {
self.presentationDetents(detents, selection: selection)
.background(UndimmedDetentView())
}
}
class UndimmedDetentController<Content: View>: UIHostingController<Content> {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
sheetPresentationController?.largestUndimmedDetentIdentifier = .large
sheetPresentationController?.preferredCornerRadius = 30
parent?.presentingViewController?.view.tintAdjustmentMode = .normal
}
}
@available(iOS 16.0, *)
struct UndimmedDetentView: UIViewControllerRepresentable {
var largestUndimmedDetent: PresentationDetent?
func makeUIViewController(context: Context) -> UIViewController {
UndimmedDetentController(rootView: Color.clear)
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment