diff --git a/Sources/NavigationTransitions/NavigationTransition+UIKit.swift b/Sources/NavigationTransitions/NavigationTransition+UIKit.swift index 9ddbcb1..fe95c5f 100644 --- a/Sources/NavigationTransitions/NavigationTransition+UIKit.swift +++ b/Sources/NavigationTransitions/NavigationTransition+UIKit.swift @@ -135,8 +135,6 @@ extension UINavigationController { _ transition: AnyNavigationTransition, interactivity: AnyNavigationTransition.Interactivity = .default ) { - backDeploy96852321() - if defaultDelegate == nil { defaultDelegate = delegate } @@ -147,6 +145,30 @@ extension UINavigationController { customDelegate.transition = transition } + swizzle( + UINavigationController.self, + #selector(UINavigationController.pushViewController), + #selector(UINavigationController.pushViewController_animateIfNeeded) + ) + + swizzle( + UINavigationController.self, + #selector(UINavigationController.popViewController), + #selector(UINavigationController.popViewController_animateIfNeeded) + ) + + swizzle( + UINavigationController.self, + #selector(UINavigationController.popToViewController), + #selector(UINavigationController.popToViewController_animateIfNeeded) + ) + + swizzle( + UINavigationController.self, + #selector(UINavigationController.popToRootViewController), + #selector(UINavigationController.popToRootViewController_animateIfNeeded) + ) + #if !os(tvOS) && !os(visionOS) if defaultEdgePanRecognizer.strongDelegate == nil { defaultEdgePanRecognizer.strongDelegate = NavigationGestureRecognizerDelegate(controller: self) @@ -196,28 +218,6 @@ extension UINavigationController { #endif } - private func backDeploy96852321() { - func forceAnimatedPopToViewController() { - swizzle( - UINavigationController.self, - #selector(UINavigationController.popToViewController), - #selector(UINavigationController.popToViewController_forceAnimated) - ) - } - - if #available(iOS 16.2, macCatalyst 16.2, tvOS 16.2, *) {} else { - #if targetEnvironment(macCatalyst) - let major = ProcessInfo.processInfo.operatingSystemVersion.majorVersion - let minor = ProcessInfo.processInfo.operatingSystemVersion.minorVersion - if (major, minor) < (13, 1) { - forceAnimatedPopToViewController() - } - #else - forceAnimatedPopToViewController() - #endif - } - } - @available(tvOS, unavailable) @available(visionOS, unavailable) private func exclusivelyEnableGestureRecognizer(_ gestureRecognizer: UIPanGestureRecognizer?) { @@ -232,8 +232,36 @@ extension UINavigationController { } extension UINavigationController { - @objc private func popToViewController_forceAnimated(_ viewController: UIViewController, animated: Bool) -> [UIViewController]? { - popToViewController_forceAnimated(viewController, animated: true) + @objc private func pushViewController_animateIfNeeded(_ viewController: UIViewController, animated: Bool) { + if let transitionDelegate = customDelegate { + pushViewController_animateIfNeeded(viewController, animated: transitionDelegate.transition.animation != nil) + } else { + pushViewController_animateIfNeeded(viewController, animated: animated) + } + } + + @objc private func popViewController_animateIfNeeded(animated: Bool) -> UIViewController? { + if let transitionDelegate = customDelegate { + return popViewController_animateIfNeeded(animated: transitionDelegate.transition.animation != nil) + } else { + return popViewController_animateIfNeeded(animated: animated) + } + } + + @objc private func popToViewController_animateIfNeeded(_ viewController: UIViewController, animated: Bool) -> [UIViewController]? { + if let transitionDelegate = customDelegate { + return popToViewController_animateIfNeeded(viewController, animated: transitionDelegate.transition.animation != nil) + } else { + return popToViewController_animateIfNeeded(viewController, animated: animated) + } + } + + @objc private func popToRootViewController_animateIfNeeded(animated: Bool) -> UIViewController? { + if let transitionDelegate = customDelegate { + return popToRootViewController_animateIfNeeded(animated: transitionDelegate.transition.animation != nil) + } else { + return popToRootViewController_animateIfNeeded(animated: animated) + } } } diff --git a/Sources/NavigationTransitions/NavigationTransitionDelegate.swift b/Sources/NavigationTransitions/NavigationTransitionDelegate.swift index 69b842b..bb0be79 100644 --- a/Sources/NavigationTransitions/NavigationTransitionDelegate.swift +++ b/Sources/NavigationTransitions/NavigationTransitionDelegate.swift @@ -7,7 +7,6 @@ final class NavigationTransitionDelegate: NSObject, UINavigationControllerDelega var transition: AnyNavigationTransition private weak var baseDelegate: UINavigationControllerDelegate? var interactionController: UIPercentDrivenInteractiveTransition? - private var initialAreAnimationsEnabled: Bool? init(transition: AnyNavigationTransition, baseDelegate: UINavigationControllerDelegate?) { self.transition = transition @@ -15,19 +14,11 @@ final class NavigationTransitionDelegate: NSObject, UINavigationControllerDelega } func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) { - if navigationController.transitionCoordinator != nil { - self.initialAreAnimationsEnabled = UIView.areAnimationsEnabled - UIView.setAnimationsEnabled(transition.animation != nil) - } baseDelegate?.navigationController?(navigationController, willShow: viewController, animated: animated) } func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) { baseDelegate?.navigationController?(navigationController, didShow: viewController, animated: animated) - if let initialAreAnimationsEnabled { - UIView.setAnimationsEnabled(initialAreAnimationsEnabled) - self.initialAreAnimationsEnabled = nil - } } func navigationController(_ navigationController: UINavigationController, interactionControllerFor animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {