From 5df3d8f6dc52e242557321d9b50ba74d279e6663 Mon Sep 17 00:00:00 2001 From: Aviv Frenkel Date: Sun, 5 Jan 2020 10:45:02 +0200 Subject: [PATCH] added shouldDismissInteractivly to support tap and swipe gestures --- .../BottomPopupPresentationController.swift | 12 +++++++++--- .../BottomPopupTransitionHandler.swift | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/BottomPopup/BottomPopupController/BottomPopupPresentationController.swift b/BottomPopup/BottomPopupController/BottomPopupPresentationController.swift index 2c0320b..2268c48 100644 --- a/BottomPopup/BottomPopupController/BottomPopupPresentationController.swift +++ b/BottomPopup/BottomPopupController/BottomPopupPresentationController.swift @@ -13,6 +13,7 @@ class BottomPopupPresentationController: UIPresentationController { fileprivate var dimmingView: UIView! fileprivate let popupHeight: CGFloat fileprivate let dimmingViewAlpha: CGFloat + fileprivate var shouldDismissInteractively: Bool override var frameOfPresentedViewInContainerView: CGRect { get { @@ -31,9 +32,10 @@ class BottomPopupPresentationController: UIPresentationController { }) } - init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?, usingHeight height: CGFloat, andDimmingViewAlpha dimmingAlpha: CGFloat) { + init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?, usingHeight height: CGFloat, andDimmingViewAlpha dimmingAlpha: CGFloat, shouldDismissInteractively: Bool) { self.popupHeight = height self.dimmingViewAlpha = dimmingAlpha + self.shouldDismissInteractively = shouldDismissInteractively super.init(presentedViewController: presentedViewController, presenting: presentingViewController) setupDimmingView() } @@ -52,11 +54,15 @@ class BottomPopupPresentationController: UIPresentationController { } @objc private func handleTap(_ tap: UITapGestureRecognizer) { - presentedViewController.dismiss(animated: true, completion: nil) + if shouldDismissInteractively { + presentedViewController.dismiss(animated: true, completion: nil) + } } @objc private func handleSwipe(_ swipe: UISwipeGestureRecognizer) { - presentedViewController.dismiss(animated: true, completion: nil) + if shouldDismissInteractively { + presentedViewController.dismiss(animated: true, completion: nil) + } } } diff --git a/BottomPopup/BottomPopupController/BottomPopupTransitionHandler.swift b/BottomPopup/BottomPopupController/BottomPopupTransitionHandler.swift index 88aa888..df4d5d2 100644 --- a/BottomPopup/BottomPopupController/BottomPopupTransitionHandler.swift +++ b/BottomPopup/BottomPopupController/BottomPopupTransitionHandler.swift @@ -36,7 +36,7 @@ class BottomPopupTransitionHandler: NSObject, UIViewControllerTransitioningDeleg //MARK: Specific animators func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? { - return BottomPopupPresentationController(presentedViewController: presented, presenting: presenting, usingHeight: popupViewController.getPopupHeight(), andDimmingViewAlpha: popupViewController.getDimmingViewAlpha()) + return BottomPopupPresentationController(presentedViewController: presented, presenting: presenting, usingHeight: popupViewController.getPopupHeight(), andDimmingViewAlpha: popupViewController.getDimmingViewAlpha(), shouldDismissInteractively: popupViewController.shouldPopupDismissInteractivelty()) } func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {