From 22b4ddd47e55fc73319d42bc0b593c6688e40681 Mon Sep 17 00:00:00 2001 From: Stephen Sowole Date: Wed, 25 Mar 2020 00:34:58 -0700 Subject: [PATCH] [PanModal] Track all dismiss events through panModalPresentable callbacks (#91) --- .../PanModalPresentationController.swift | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/PanModal/Controller/PanModalPresentationController.swift b/PanModal/Controller/PanModalPresentationController.swift index 490fb66..11fb2a6 100644 --- a/PanModal/Controller/PanModalPresentationController.swift +++ b/PanModal/Controller/PanModalPresentationController.swift @@ -113,7 +113,7 @@ open class PanModalPresentationController: UIPresentationController { } view.didTap = { [weak self] _ in if self?.presentable?.allowsTapToDismiss == true { - self?.dismissPresentedViewController() + self?.presentedViewController.dismiss(animated: true) } } return view @@ -192,7 +192,14 @@ open class PanModalPresentationController: UIPresentationController { }) } + override public func presentationTransitionDidEnd(_ completed: Bool) { + if completed { return } + + backgroundView.removeFromSuperview() + } + override public func dismissalTransitionWillBegin() { + presentable?.panModalWillDismiss() guard let coordinator = presentedViewController.transitionCoordinator else { backgroundView.dimState = .off @@ -210,10 +217,10 @@ open class PanModalPresentationController: UIPresentationController { }) } - override public func presentationTransitionDidEnd(_ completed: Bool) { - if completed { return } - - backgroundView.removeFromSuperview() + override public func dismissalTransitionDidEnd(_ completed: Bool) { + if !completed { return } + + presentable?.panModalDidDismiss() } /** @@ -516,7 +523,7 @@ private extension PanModalPresentationController { transition(to: .shortForm) } else { - dismissPresentedViewController() + presentedViewController.dismiss(animated: true) } } else { @@ -534,7 +541,7 @@ private extension PanModalPresentationController { transition(to: .shortForm) } else { - dismissPresentedViewController() + presentedViewController.dismiss(animated: true) } } } @@ -673,16 +680,6 @@ private extension PanModalPresentationController { else { return number } return nearestVal } - - /** - Dismiss presented view - */ - func dismissPresentedViewController() { - presentable?.panModalWillDismiss() - presentedViewController.dismiss(animated: true) { [weak self] in - self?.presentable?.panModalDidDismiss() - } - } } // MARK: - UIScrollView Observer