From b2f5bd7d169cba564d5c5b7203864f79be3fe826 Mon Sep 17 00:00:00 2001 From: Jordan Pichler Date: Tue, 21 Apr 2020 20:16:30 +0200 Subject: [PATCH] Add completion block to present function (#94) --- PanModal/Presenter/PanModalPresenter.swift | 5 ++++- .../Presenter/UIViewController+PanModalPresenter.swift | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/PanModal/Presenter/PanModalPresenter.swift b/PanModal/Presenter/PanModalPresenter.swift index f27ba698..8763fdac 100644 --- a/PanModal/Presenter/PanModalPresenter.swift +++ b/PanModal/Presenter/PanModalPresenter.swift @@ -29,7 +29,10 @@ protocol PanModalPresenter: AnyObject { /** Presents a view controller that conforms to the PanModalPresentable protocol */ - func presentPanModal(_ viewControllerToPresent: PanModalPresentable.LayoutType, sourceView: UIView?, sourceRect: CGRect) + func presentPanModal(_ viewControllerToPresent: PanModalPresentable.LayoutType, + sourceView: UIView?, + sourceRect: CGRect, + completion: (() -> Void)?) } #endif diff --git a/PanModal/Presenter/UIViewController+PanModalPresenter.swift b/PanModal/Presenter/UIViewController+PanModalPresenter.swift index 48358c21..b252d8f7 100644 --- a/PanModal/Presenter/UIViewController+PanModalPresenter.swift +++ b/PanModal/Presenter/UIViewController+PanModalPresenter.swift @@ -35,10 +35,14 @@ extension UIViewController: PanModalPresenter { - viewControllerToPresent: The view controller to be presented - sourceView: The view containing the anchor rectangle for the popover. - sourceRect: The rectangle in the specified view in which to anchor the popover. + - completion: The block to execute after the presentation finishes. You may specify nil for this parameter. - Note: sourceView & sourceRect are only required for presentation on an iPad. */ - public func presentPanModal(_ viewControllerToPresent: PanModalPresentable.LayoutType, sourceView: UIView? = nil, sourceRect: CGRect = .zero) { + public func presentPanModal(_ viewControllerToPresent: PanModalPresentable.LayoutType, + sourceView: UIView? = nil, + sourceRect: CGRect = .zero, + completion: (() -> Void)? = nil) { /** Here, we deliberately do not check for size classes. More info in `PanModalPresentationDelegate` @@ -55,7 +59,7 @@ extension UIViewController: PanModalPresenter { viewControllerToPresent.transitioningDelegate = PanModalPresentationDelegate.default } - present(viewControllerToPresent, animated: true, completion: nil) + present(viewControllerToPresent, animated: true, completion: completion) } }