Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Replace PartialSheetPresentationControllerDelegate (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedinicolatt authored Sep 27, 2024
1 parent 1831445 commit 895d983
Showing 1 changed file with 6 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
import UIKit

// TODO: (team) Much of what's included in this delegate has been added to UIAdaptivePresentationControllerDelegate
// in iOS 13. Once we're on a minimum target of iOS 13, we can get rid of PartialSheetPresentationControllerDelegate and
// just use UIAdaptivePresentationControllerDelegate directly (for which UIPresentationController already has a delegate
// property)
@objc
public protocol PartialSheetPresentationControllerDelegate: UIAdaptivePresentationControllerDelegate {
@objc
optional func partialSheetPresentationControllerShouldDismissSheet(_ partialSheetPresentationController: PartialSheetPresentationController) -> Bool

@objc
optional func partialSheetPresentationControllerWillDismissSheet(_ partialSheetPresentationController: PartialSheetPresentationController)

/**
Called upon dismissal of the modal
- Parameters:
- partialSheetPresentationController: The partial sheet presentation controller responsible for the partial sheet presentation
- interactively: true if the modal was dismissed either by tapping on the background area or swiping down
*/
@objc
optional func partialSheetPresentationControllerDidDismissSheet(_ partialSheetPresentationController: PartialSheetPresentationController, interactively: Bool)
}

open class PartialSheetPresentationController: UIPresentationController {
public static let partialSheetDidPresentNotification = Notification.Name("PartialSheetDidPresentNotification")
public static let partialSheetDidDismissNotification = Notification.Name("PartialSheetDidDismissNotification")
Expand Down Expand Up @@ -105,9 +83,9 @@ open class PartialSheetPresentationController: UIPresentationController {
userDidDismissModal = true
}

public var partialSheetDelegate: PartialSheetPresentationControllerDelegate? {
public var partialSheetDelegate: UISheetPresentationControllerDelegate? {
get {
delegate as? PartialSheetPresentationControllerDelegate
delegate as? UISheetPresentationControllerDelegate
}
set {
delegate = newValue
Expand Down Expand Up @@ -185,7 +163,7 @@ open class PartialSheetPresentationController: UIPresentationController {

@objc
private func backgroundTapGestureRecognizerHandler(sender: UITapGestureRecognizer) {
guard let shouldDismissSheetMethod = partialSheetDelegate?.partialSheetPresentationControllerShouldDismissSheet else {
guard let shouldDismissSheetMethod = partialSheetDelegate?.presentationControllerShouldDismiss else {
userDidDismissModal = true
presentingViewController.dismiss(animated: true, completion: nil)
return
Expand All @@ -203,7 +181,7 @@ open class PartialSheetPresentationController: UIPresentationController {
return
}

guard let shouldDismissSheetMethod = partialSheetDelegate?.partialSheetPresentationControllerShouldDismissSheet else {
guard let shouldDismissSheetMethod = partialSheetDelegate?.presentationControllerShouldDismiss else {
presentingViewController.dismiss(animated: true, completion: nil)
return
}
Expand All @@ -220,7 +198,7 @@ open class PartialSheetPresentationController: UIPresentationController {
fatalError("Somehow reached dismissalTransitionWillBegin with no container view being set")
}

partialSheetDelegate?.partialSheetPresentationControllerWillDismissSheet?(self)
partialSheetDelegate?.presentationControllerWillDismiss?(self)

if let transitionCoordinator = presentedViewController.transitionCoordinator {
currentTransitionCoordinator = transitionCoordinator
Expand All @@ -246,7 +224,7 @@ open class PartialSheetPresentationController: UIPresentationController {
super.dismissalTransitionDidEnd(completed)

if completed {
partialSheetDelegate?.partialSheetPresentationControllerDidDismissSheet?(self, interactively: userDidDismissModal)
partialSheetDelegate?.presentationControllerDidDismiss?(self)

NotificationCenter.default.post(name: PartialSheetPresentationController.partialSheetDidDismissNotification, object: nil)
} else {
Expand Down

0 comments on commit 895d983

Please sign in to comment.