Skip to content

Commit 68d1a6c

Browse files
authored
Fix animations not working on iOS 17.1 (#110)
Fixes and closes #109.
1 parent 4a1397f commit 68d1a6c

File tree

2 files changed

+54
-35
lines changed

2 files changed

+54
-35
lines changed

Sources/NavigationTransitions/NavigationTransition+UIKit.swift

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ extension UINavigationController {
135135
_ transition: AnyNavigationTransition,
136136
interactivity: AnyNavigationTransition.Interactivity = .default
137137
) {
138-
backDeploy96852321()
139-
140138
if defaultDelegate == nil {
141139
defaultDelegate = delegate
142140
}
@@ -147,6 +145,30 @@ extension UINavigationController {
147145
customDelegate.transition = transition
148146
}
149147

148+
swizzle(
149+
UINavigationController.self,
150+
#selector(UINavigationController.pushViewController),
151+
#selector(UINavigationController.pushViewController_animateIfNeeded)
152+
)
153+
154+
swizzle(
155+
UINavigationController.self,
156+
#selector(UINavigationController.popViewController),
157+
#selector(UINavigationController.popViewController_animateIfNeeded)
158+
)
159+
160+
swizzle(
161+
UINavigationController.self,
162+
#selector(UINavigationController.popToViewController),
163+
#selector(UINavigationController.popToViewController_animateIfNeeded)
164+
)
165+
166+
swizzle(
167+
UINavigationController.self,
168+
#selector(UINavigationController.popToRootViewController),
169+
#selector(UINavigationController.popToRootViewController_animateIfNeeded)
170+
)
171+
150172
#if !os(tvOS) && !os(visionOS)
151173
if defaultEdgePanRecognizer.strongDelegate == nil {
152174
defaultEdgePanRecognizer.strongDelegate = NavigationGestureRecognizerDelegate(controller: self)
@@ -196,28 +218,6 @@ extension UINavigationController {
196218
#endif
197219
}
198220

199-
private func backDeploy96852321() {
200-
func forceAnimatedPopToViewController() {
201-
swizzle(
202-
UINavigationController.self,
203-
#selector(UINavigationController.popToViewController),
204-
#selector(UINavigationController.popToViewController_forceAnimated)
205-
)
206-
}
207-
208-
if #available(iOS 16.2, macCatalyst 16.2, tvOS 16.2, *) {} else {
209-
#if targetEnvironment(macCatalyst)
210-
let major = ProcessInfo.processInfo.operatingSystemVersion.majorVersion
211-
let minor = ProcessInfo.processInfo.operatingSystemVersion.minorVersion
212-
if (major, minor) < (13, 1) {
213-
forceAnimatedPopToViewController()
214-
}
215-
#else
216-
forceAnimatedPopToViewController()
217-
#endif
218-
}
219-
}
220-
221221
@available(tvOS, unavailable)
222222
@available(visionOS, unavailable)
223223
private func exclusivelyEnableGestureRecognizer(_ gestureRecognizer: UIPanGestureRecognizer?) {
@@ -232,8 +232,36 @@ extension UINavigationController {
232232
}
233233

234234
extension UINavigationController {
235-
@objc private func popToViewController_forceAnimated(_ viewController: UIViewController, animated: Bool) -> [UIViewController]? {
236-
popToViewController_forceAnimated(viewController, animated: true)
235+
@objc private func pushViewController_animateIfNeeded(_ viewController: UIViewController, animated: Bool) {
236+
if let transitionDelegate = customDelegate {
237+
pushViewController_animateIfNeeded(viewController, animated: transitionDelegate.transition.animation != nil)
238+
} else {
239+
pushViewController_animateIfNeeded(viewController, animated: animated)
240+
}
241+
}
242+
243+
@objc private func popViewController_animateIfNeeded(animated: Bool) -> UIViewController? {
244+
if let transitionDelegate = customDelegate {
245+
return popViewController_animateIfNeeded(animated: transitionDelegate.transition.animation != nil)
246+
} else {
247+
return popViewController_animateIfNeeded(animated: animated)
248+
}
249+
}
250+
251+
@objc private func popToViewController_animateIfNeeded(_ viewController: UIViewController, animated: Bool) -> [UIViewController]? {
252+
if let transitionDelegate = customDelegate {
253+
return popToViewController_animateIfNeeded(viewController, animated: transitionDelegate.transition.animation != nil)
254+
} else {
255+
return popToViewController_animateIfNeeded(viewController, animated: animated)
256+
}
257+
}
258+
259+
@objc private func popToRootViewController_animateIfNeeded(animated: Bool) -> UIViewController? {
260+
if let transitionDelegate = customDelegate {
261+
return popToRootViewController_animateIfNeeded(animated: transitionDelegate.transition.animation != nil)
262+
} else {
263+
return popToRootViewController_animateIfNeeded(animated: animated)
264+
}
237265
}
238266
}
239267

Sources/NavigationTransitions/NavigationTransitionDelegate.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,18 @@ final class NavigationTransitionDelegate: NSObject, UINavigationControllerDelega
77
var transition: AnyNavigationTransition
88
private weak var baseDelegate: UINavigationControllerDelegate?
99
var interactionController: UIPercentDrivenInteractiveTransition?
10-
private var initialAreAnimationsEnabled: Bool?
1110

1211
init(transition: AnyNavigationTransition, baseDelegate: UINavigationControllerDelegate?) {
1312
self.transition = transition
1413
self.baseDelegate = baseDelegate
1514
}
1615

1716
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
18-
if navigationController.transitionCoordinator != nil {
19-
self.initialAreAnimationsEnabled = UIView.areAnimationsEnabled
20-
UIView.setAnimationsEnabled(transition.animation != nil)
21-
}
2217
baseDelegate?.navigationController?(navigationController, willShow: viewController, animated: animated)
2318
}
2419

2520
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
2621
baseDelegate?.navigationController?(navigationController, didShow: viewController, animated: animated)
27-
if let initialAreAnimationsEnabled {
28-
UIView.setAnimationsEnabled(initialAreAnimationsEnabled)
29-
self.initialAreAnimationsEnabled = nil
30-
}
3122
}
3223

3324
func navigationController(_ navigationController: UINavigationController, interactionControllerFor animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {

0 commit comments

Comments
 (0)