Skip to content

Commit

Permalink
Bug fix for push transition and dismiss interactive gesture
Browse files Browse the repository at this point in the history
  • Loading branch information
ikrisliu committed Jan 8, 2021
1 parent 7757806 commit 2a803f5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
5 changes: 5 additions & 0 deletions App/App/Classes/DetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class DetailViewController: UIViewController, Navigatable {
debugPrint("FREE MEMORY: \(self)")
}

override var hidesBottomBarWhenPushed: Bool {
get { true }
set { super.hidesBottomBarWhenPushed = newValue }
}

override var ignoreDeepLinking: Bool { true }
}

Expand Down
2 changes: 1 addition & 1 deletion SmartNavigator.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SmartNavigator'
s.version = '1.4.0'
s.version = '1.4.1'
s.license = 'MIT'
s.summary = 'Generic navigation framework for view controllers'
s.homepage = 'https://github.com/iKrisLiu/Navigator'
Expand Down
2 changes: 1 addition & 1 deletion Sources/Navigator/Navigator+Private.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ extension Navigator {
let toVC = viewController.navigationController ?? viewController

// Must set presentation style first for `UIModalPresentationStylePopover`
toVC.modalPresentationStyle = page.presentationStyle
toVC.modalPresentationStyle = viewController.hidesBottomBarWhenPushed ? page.presentationStyle : .currentContext
passPageObject(page, fromVC: topViewController, toVC: viewController)
sendDataBeforeShow(page.extraData, fromVC: topViewController, toVC: viewController)

Expand Down
9 changes: 7 additions & 2 deletions Sources/Navigator/Transitions/PushTransition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,16 @@ import UIKit
UIView.animate(withDuration: animationDuration, animations: {
self.dimmedBackgroundView.alpha = 0.0

self.setNavigationBarAlpha(navBar: fromNavBar, alpha: 0.0)
fromTransView?.transform = CGAffineTransform(translationX: fromView.bounds.width, y: 0)
if toNavBar?.isTranslucent == false {
self.setNavigationBarAlpha(navBar: fromNavBar, alpha: 0.0)
fromTransView?.transform = CGAffineTransform(translationX: fromView.bounds.width, y: 0)
} else {
fromView.transform = CGAffineTransform(translationX: fromView.bounds.width, y: 0)
}

toTransView?.transform = .identity
}, completion: { _ in
toTransView?.transform = .identity
self.transitionContext.completeTransition(!self.transitionContext.transitionWasCancelled)
})
}
Expand Down
13 changes: 9 additions & 4 deletions Sources/Navigator/Transitions/Transition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import UIKit
@objc public var sourceRect: CGRect = .zero

@objc public var isVertical: Bool { orientation == .vertical }
@objc public private(set) weak var transitionContext: UIViewControllerContextTransitioning!
@objc public var transitionContext: UIViewControllerContextTransitioning { _transitionContext! }
private weak var _transitionContext: UIViewControllerContextTransitioning?

/// Show or Dismiss
@objc public private(set) var isShow = false
Expand Down Expand Up @@ -81,7 +82,7 @@ extension Transition: UIViewControllerAnimatedTransitioning {
}

public func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
self.transitionContext = transitionContext
_transitionContext = transitionContext

let fromView = transitionContext.view(forKey: .from)
let toView = transitionContext.view(forKey: .to)
Expand Down Expand Up @@ -202,6 +203,10 @@ extension Transition {

switch recognizer.state {
case .began:
if _transitionContext?.isAnimated == true {
finish()
return
}
if verticalPanGesture != nil && translation.y < 0 { return }

isInteractive = true
Expand All @@ -220,10 +225,10 @@ extension Transition {
let isFinish = isVertical ? offset > recognizerView.bounds.height / 2 : offset > recognizerView.bounds.width / 2

if isFinish {
completionSpeed = (1.0 - percentComplete) / 2
completionSpeed = (1.0 - percentComplete)
finish()
} else {
completionSpeed = 0.1
completionSpeed = 0.25
cancel()
}

Expand Down

0 comments on commit 2a803f5

Please sign in to comment.