Skip to content

Commit

Permalink
Allow opting out of appearance transition callbacks on presenting vie…
Browse files Browse the repository at this point in the history
…w controller (#47)
  • Loading branch information
nolanw committed Apr 12, 2021
1 parent b2f5bd7 commit 134d117
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
13 changes: 9 additions & 4 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 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

0 comments on commit 134d117

Please sign in to comment.