From d5f5e99010969a2c5db3fcdd00a772c170635f74 Mon Sep 17 00:00:00 2001 From: Shin Yamamoto Date: Mon, 17 Dec 2018 13:27:21 +0900 Subject: [PATCH] Fix dismiss swizzling --- Framework/Sources/FloatingPanel.swift | 6 +++-- .../Sources/FloatingPanelController.swift | 24 +++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Framework/Sources/FloatingPanel.swift b/Framework/Sources/FloatingPanel.swift index dff333d..0a940aa 100644 --- a/Framework/Sources/FloatingPanel.swift +++ b/Framework/Sources/FloatingPanel.swift @@ -411,8 +411,10 @@ class FloatingPanel: NSObject, UIGestureRecognizerDelegate, UIScrollViewDelegate viewcontroller.delegate?.floatingPanelDidEndDraggingToRemove(viewcontroller, withVelocity: velocity) self.startRemovalAnimation(with: velocityVector) { [weak self] in guard let self = self else { return } - self.viewcontroller.dismiss(animated: false) - self.viewcontroller.delegate?.floatingPanelDidEndRemove(self.viewcontroller) + self.viewcontroller.dismiss(animated: false, completion: { [weak self] in + guard let self = self else { return } + self.viewcontroller.delegate?.floatingPanelDidEndRemove(self.viewcontroller) + }) } return } diff --git a/Framework/Sources/FloatingPanelController.swift b/Framework/Sources/FloatingPanelController.swift index d63cc94..b291b28 100644 --- a/Framework/Sources/FloatingPanelController.swift +++ b/Framework/Sources/FloatingPanelController.swift @@ -451,10 +451,26 @@ public extension UIViewController { // Implementation will be replaced by IMP of self.dismiss(animated:completion:) } @objc public func fp_dismiss(animated flag: Bool, completion: (() -> Void)? = nil) { - if let fpc = parent as? FloatingPanelController, fpc.parent != nil { - fpc.removePanelFromParent(animated: flag, completion: completion) - } else { - self.fp_original_dismiss(animated: flag, completion: completion) + // Call dismiss(animated:completion:) to a content view controller + if let fpc = parent as? FloatingPanelController { + if fpc.presentingViewController != nil { + self.fp_original_dismiss(animated: flag, completion: completion) + } else { + fpc.removePanelFromParent(animated: flag, completion: completion) + } + return } + // Call dismiss(animated:completion:) to FloatingPanelController directly + if let fpc = self as? FloatingPanelController { + if fpc.presentingViewController != nil { + self.fp_original_dismiss(animated: flag, completion: completion) + } else { + fpc.removePanelFromParent(animated: flag, completion: completion) + } + return + } + + // For other view controllers + self.fp_original_dismiss(animated: flag, completion: completion) } }