diff --git a/PanModal/Animator/PanModalPresentationAnimator.swift b/PanModal/Animator/PanModalPresentationAnimator.swift index f7fbdd0e..088eba76 100644 --- a/PanModal/Animator/PanModalPresentationAnimator.swift +++ b/PanModal/Animator/PanModalPresentationAnimator.swift @@ -71,8 +71,11 @@ public class PanModalPresentationAnimator: NSObject { let presentable = panModalLayoutType(from: transitionContext) - // Calls viewWillAppear and viewWillDisappear - fromVC.beginAppearanceTransition(false, animated: true) + let isAppearanceTransition = presentable?.isAppearanceTransition ?? true + if isAppearanceTransition { + // Calls viewWillAppear and viewWillDisappear + fromVC.beginAppearanceTransition(false, animated: true) + } // Presents the view in shortForm position, initially let yPos: CGFloat = presentable?.shortFormYPos ?? 0.0 @@ -92,8 +95,10 @@ public class PanModalPresentationAnimator: NSObject { PanModalAnimator.animate({ panView.frame.origin.y = yPos }, config: presentable) { [weak self] didComplete in - // Calls viewDidAppear and viewDidDisappear - fromVC.endAppearanceTransition() + if isAppearanceTransition { + // Calls viewDidAppear and viewDidDisappear + fromVC.endAppearanceTransition() + } transitionContext.completeTransition(didComplete) self?.feedbackGenerator = nil } @@ -109,18 +114,24 @@ public class PanModalPresentationAnimator: NSObject { let fromVC = transitionContext.viewController(forKey: .from) else { return } - // Calls viewWillAppear and viewWillDisappear - toVC.beginAppearanceTransition(true, animated: true) - let presentable = panModalLayoutType(from: transitionContext) + + let isAppearanceTransition = presentable?.isAppearanceTransition ?? true + if isAppearanceTransition { + // Calls viewWillAppear and viewWillDisappear + toVC.beginAppearanceTransition(true, animated: true) + } + let panView: UIView = transitionContext.containerView.panContainerView ?? fromVC.view PanModalAnimator.animate({ panView.frame.origin.y = transitionContext.containerView.frame.height }, config: presentable) { didComplete in fromVC.view.removeFromSuperview() - // Calls viewDidAppear and viewDidDisappear - toVC.endAppearanceTransition() + if isAppearanceTransition { + // Calls viewDidAppear and viewDidDisappear + toVC.endAppearanceTransition() + } transitionContext.completeTransition(didComplete) } } diff --git a/PanModal/Presentable/PanModalPresentable+Defaults.swift b/PanModal/Presentable/PanModalPresentable+Defaults.swift index 76a0679f..99328edd 100644 --- a/PanModal/Presentable/PanModalPresentable+Defaults.swift +++ b/PanModal/Presentable/PanModalPresentable+Defaults.swift @@ -97,6 +97,10 @@ public extension PanModalPresentable where Self: UIViewController { return shouldRoundTopCorners } + var isAppearanceTransition: Bool { + return true + } + func shouldRespond(to panModalGestureRecognizer: UIPanGestureRecognizer) -> Bool { return true } diff --git a/PanModal/Presentable/PanModalPresentable.swift b/PanModal/Presentable/PanModalPresentable.swift index 76c15015..54151824 100644 --- a/PanModal/Presentable/PanModalPresentable.swift +++ b/PanModal/Presentable/PanModalPresentable.swift @@ -173,6 +173,15 @@ public protocol PanModalPresentable: AnyObject { */ var showDragIndicator: Bool { get } + /** + A flag to determine whether view lifecycle methods `view(Will|Did)(A|Disa)ppear` are called on the presenting view controller. + + Since pan modal presentation does not remove the presenting view from the view hierarchy, it may not be desirable to call the relevant methods that are usually associated with removing the presenting view from the view hierarchy. + + Default value is true. + */ + var isAppearanceTransition: Bool { get } + /** Asks the delegate if the pan modal should respond to the pan modal gesture recognizer. diff --git a/Tests/PanModalTests.swift b/Tests/PanModalTests.swift index 7652b55f..f3686c06 100644 --- a/Tests/PanModalTests.swift +++ b/Tests/PanModalTests.swift @@ -60,6 +60,7 @@ class PanModalTests: XCTestCase { XCTAssertEqual(vc.shouldRoundTopCorners, false) XCTAssertEqual(vc.showDragIndicator, false) XCTAssertEqual(vc.shouldRoundTopCorners, false) + XCTAssertEqual(vc.isAppearanceTransition, true) XCTAssertEqual(vc.cornerRadius, 8.0) XCTAssertEqual(vc.transitionDuration, PanModalAnimator.Constants.defaultTransitionDuration) XCTAssertEqual(vc.transitionAnimationOptions, [.curveEaseInOut, .allowUserInteraction, .beginFromCurrentState])