Created
November 14, 2022 23:03
-
-
Save jordibruin/3ed5dede27a390c49415d55dc3c77944 to your computer and use it in GitHub Desktop.
Interact with background while presenting sheet
This file contains 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
@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