Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow opting out of appearance transition callbacks on presenting view controller #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions PanModal/Animator/PanModalPresentationAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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)
}
}
Expand Down
4 changes: 4 additions & 0 deletions PanModal/Presentable/PanModalPresentable+Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions PanModal/Presentable/PanModalPresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions Tests/PanModalTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down