From 9dd89bde8ed8f70f664b332f8394685e78bef33d Mon Sep 17 00:00:00 2001 From: Mohamed Farouk Date: Wed, 22 Jan 2020 14:47:50 +0200 Subject: [PATCH] ADD completion block to run on dismiss the presented view controller --- CardPresentationController/CardConfiguration.swift | 10 +++++++++- .../CardPresentationController.swift | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CardPresentationController/CardConfiguration.swift b/CardPresentationController/CardConfiguration.swift index b50f461..b57dd49 100644 --- a/CardPresentationController/CardConfiguration.swift +++ b/CardPresentationController/CardConfiguration.swift @@ -36,6 +36,9 @@ public struct CardConfiguration { /// Set to false to disable interactive dismissal public var allowInteractiveDismissal = true + /// A completion block runs after dismiss the presented view controller + public var dismissCompletion: (() -> Void)? = nil + /// Default initializer, with most suitable values init() {} @@ -55,7 +58,8 @@ extension CardConfiguration { cornerRadius: CGFloat? = nil, backFadeAlpha: CGFloat? = nil, initialTransitionFrame: CGRect? = nil, - allowInteractiveDismissal: Bool? = nil) + allowInteractiveDismissal: Bool? = nil, + dismissCompletion: (() -> Void)? = nil) { if let verticalSpacing = verticalSpacing { self.verticalSpacing = verticalSpacing @@ -88,5 +92,9 @@ extension CardConfiguration { if let allowInteractiveDismissal = allowInteractiveDismissal { self.allowInteractiveDismissal = allowInteractiveDismissal } + + if let dismissCompletion = dismissCompletion { + self.dismissCompletion = dismissCompletion + } } } diff --git a/CardPresentationController/CardPresentationController.swift b/CardPresentationController/CardPresentationController.swift index fdcf029..2a5c851 100644 --- a/CardPresentationController/CardPresentationController.swift +++ b/CardPresentationController/CardPresentationController.swift @@ -200,7 +200,7 @@ public class CardPresentationController: UIPresentationController { cardAnimator.isInteractive = true // and then initiate dismissal - presentedViewController.dismiss(animated: true) + presentedViewController.dismiss(animated: true, completion: configuration.dismissCompletion) case .changed: if !hasStartedPan { return }