Skip to content

Commit 4307f2a

Browse files
committed
Fixed bug that UINavigationController could not be obtained.
1 parent f88f9ca commit 4307f2a

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

Sources/LicenseList/LicenseListView.swift

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,26 @@ public struct LicenseListView: View {
5252
var navigationController: UINavigationController? {
5353
guard let scene = UIApplication.shared.connectedScenes.first,
5454
let sceneDelegate = scene as? UIWindowScene,
55-
let rootVC = sceneDelegate.windows.first?.rootViewController,
56-
let navigationController = rootVC as? UINavigationController
55+
var controller = sceneDelegate.windows.first?.rootViewController
5756
else { return nil }
58-
return navigationController
57+
while true {
58+
if let navigationController = controller as? UINavigationController,
59+
let visibleViewController = navigationController.visibleViewController {
60+
controller = visibleViewController
61+
continue
62+
}
63+
if let tabBarController = controller as? UITabBarController,
64+
let selectedViewController = tabBarController.selectedViewController {
65+
controller = selectedViewController
66+
continue
67+
}
68+
if let presentedViewController = controller.presentedViewController {
69+
controller = presentedViewController
70+
continue
71+
}
72+
break
73+
}
74+
return controller.navigationController
5975
}
6076

6177
func libraryButton(_ library: Library) -> some View {

0 commit comments

Comments
 (0)