Commit ba8cd017 by Daniel Dahan

fixed NavigationController pushViewController issue where it would stutter when…

fixed NavigationController pushViewController issue where it would stutter when taking a snapshot and immediately animating
parent 8d2499ed
...@@ -139,7 +139,7 @@ extension UIViewController: MotionDelegate, UIViewControllerTransitioningDelegat ...@@ -139,7 +139,7 @@ extension UIViewController: MotionDelegate, UIViewControllerTransitioningDelegat
extension UIViewController { extension UIViewController {
open func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { open func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return isMotionEnabled ? Motion(isPresenting: true) : nil return isMotionEnabled ? Motion(isPresenting: true, isContainer: false) : nil
} }
open func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { open func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
...@@ -159,13 +159,13 @@ extension UINavigationController: UINavigationControllerDelegate { ...@@ -159,13 +159,13 @@ extension UINavigationController: UINavigationControllerDelegate {
@objc(navigationController:animationControllerForOperation:fromViewController:toViewController:) @objc(navigationController:animationControllerForOperation:fromViewController:toViewController:)
open func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { open func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return fromVC.isMotionEnabled ? Motion(isPresenting: operation == .push) : nil return fromVC.isMotionEnabled ? Motion(isPresenting: operation == .push, isContainer: true) : nil
} }
} }
extension UITabBarController: UITabBarControllerDelegate { extension UITabBarController: UITabBarControllerDelegate {
open func tabBarController(_ tabBarController: UITabBarController, animationControllerForTransitionFrom fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { open func tabBarController(_ tabBarController: UITabBarController, animationControllerForTransitionFrom fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return fromVC.isMotionEnabled ? Motion() : nil return fromVC.isMotionEnabled ? Motion(isPresenting: true, isContainer: true) : nil
} }
} }
...@@ -308,7 +308,8 @@ public protocol MotionDelegate { ...@@ -308,7 +308,8 @@ public protocol MotionDelegate {
} }
open class Motion: NSObject { open class Motion: NSObject {
open var isPresenting: Bool open fileprivate(set) var isPresenting: Bool
open fileprivate(set) var isContainer: Bool
open fileprivate(set) var transitionPairs = [(UIView, UIView)]() open fileprivate(set) var transitionPairs = [(UIView, UIView)]()
...@@ -334,11 +335,13 @@ open class Motion: NSObject { ...@@ -334,11 +335,13 @@ open class Motion: NSObject {
public override init() { public override init() {
isPresenting = false isPresenting = false
isContainer = false
super.init() super.init()
} }
public init(isPresenting: Bool) { public init(isPresenting: Bool, isContainer: Bool) {
self.isPresenting = isPresenting self.isPresenting = isPresenting
self.isContainer = isContainer
super.init() super.init()
} }
...@@ -560,7 +563,7 @@ extension Motion { ...@@ -560,7 +563,7 @@ extension Motion {
let snapshot = from.transitionSnapshot(afterUpdates: true) let snapshot = from.transitionSnapshot(afterUpdates: true)
transitionView.addSubview(snapshot) transitionView.addSubview(snapshot)
Motion.delay(motionDelay(animations: to.motionAnimations)) { [weak self, weak to] in Motion.delay(motionDelay(animations: to.motionAnimations) + (isContainer ? 0.2 : 0)) { [weak self, weak to] in
guard let s = self else { guard let s = self else {
return return
} }
...@@ -660,7 +663,7 @@ extension Motion { ...@@ -660,7 +663,7 @@ extension Motion {
extension Motion { extension Motion {
fileprivate func cleanupAnimation() { fileprivate func cleanupAnimation() {
Motion.delay(transitionDuration(using: transitionContext) + modifiedDelay) { [weak self] in Motion.delay(transitionDuration(using: transitionContext) + modifiedDelay + (isContainer ? 0.2 : 0)) { [weak self] in
guard let s = self else { guard let s = self else {
return return
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment