Skip to content

Commit c076928

Browse files
authored
Back-deploy fix for 96852321 (#45)
Related to #41 and #44. Makes sure to apply the workaround only on affected OSes. On OSes where it's been fixed by Apple (iOS 16.2 and later), standard behaviour will occur instead.
1 parent d319d7f commit c076928

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

Demo/Demo.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@
270270
SDKROOT = iphoneos;
271271
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
272272
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
273+
TVOS_DEPLOYMENT_TARGET = 13.0;
273274
};
274275
name = Debug;
275276
};
@@ -323,6 +324,7 @@
323324
SDKROOT = iphoneos;
324325
SWIFT_COMPILATION_MODE = wholemodule;
325326
SWIFT_OPTIMIZATION_LEVEL = "-O";
327+
TVOS_DEPLOYMENT_TARGET = 13.0;
326328
VALIDATE_PRODUCT = YES;
327329
};
328330
name = Release;
@@ -361,7 +363,6 @@
361363
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
362364
SWIFT_VERSION = 5.0;
363365
TARGETED_DEVICE_FAMILY = "1,2,3";
364-
TVOS_DEPLOYMENT_TARGET = 13.0;
365366
};
366367
name = Debug;
367368
};
@@ -398,7 +399,6 @@
398399
SWIFT_EMIT_LOC_STRINGS = YES;
399400
SWIFT_VERSION = 5.0;
400401
TARGETED_DEVICE_FAMILY = "1,2,3";
401-
TVOS_DEPLOYMENT_TARGET = 13.0;
402402
};
403403
name = Release;
404404
};

Sources/NavigationTransitions/NavigationTransition+UIKit.swift

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,7 @@ extension UINavigationController: RuntimeAssociation {
135135
_ transition: AnyNavigationTransition,
136136
interactivity: AnyNavigationTransition.Interactivity = .default
137137
) {
138-
// fix for https://stackoverflow.com/q/73753796/1922543
139-
swizzle(
140-
UINavigationController.self,
141-
#selector(UINavigationController.popToViewController),
142-
#selector(UINavigationController.popToViewController_forceAnimated)
143-
)
138+
backDeploy96852321()
144139

145140
if defaultDelegate == nil {
146141
defaultDelegate = delegate
@@ -193,6 +188,28 @@ extension UINavigationController: RuntimeAssociation {
193188
#endif
194189
}
195190

191+
private func backDeploy96852321() {
192+
func forceAnimatedPopToViewController() {
193+
swizzle(
194+
UINavigationController.self,
195+
#selector(UINavigationController.popToViewController),
196+
#selector(UINavigationController.popToViewController_forceAnimated)
197+
)
198+
}
199+
200+
if #available(iOS 16.2, macCatalyst 16.2, tvOS 16.2, *) {} else {
201+
#if targetEnvironment(macCatalyst)
202+
let major = ProcessInfo.processInfo.operatingSystemVersion.majorVersion
203+
let minor = ProcessInfo.processInfo.operatingSystemVersion.minorVersion
204+
if (major, minor) < (13, 1) {
205+
forceAnimatedPopToViewController()
206+
}
207+
#else
208+
forceAnimatedPopToViewController()
209+
#endif
210+
}
211+
}
212+
196213
@available(tvOS, unavailable)
197214
private func exclusivelyEnableGestureRecognizer(_ gestureRecognizer: UIPanGestureRecognizer?) {
198215
for recognizer in [defaultEdgePanRecognizer!, defaultPanRecognizer!, edgePanRecognizer!, panRecognizer!] {
@@ -206,8 +223,7 @@ extension UINavigationController: RuntimeAssociation {
206223
}
207224

208225
extension UINavigationController {
209-
@objc func popToViewController_forceAnimated(_ viewController: UIViewController, animated: Bool) -> [UIViewController]? {
210-
// TODO: `if #unavailable(iOS 17?...)` when fixed by Apple
226+
@objc fileprivate func popToViewController_forceAnimated(_ viewController: UIViewController, animated: Bool) -> [UIViewController]? {
211227
popToViewController_forceAnimated(viewController, animated: true)
212228
}
213229
}

0 commit comments

Comments
 (0)