Slather logo

Coverage for "UIViewController+PrivateExtension.swift" : 100.00%

(29 of 29 relevant lines covered)

RouteComposer/Classes/Router/Internal/UIViewController+PrivateExtension.swift

1
//
2
// RouteComposer
3
// UIViewController+PrivateExtension.swift
4
// https://github.com/ekazaev/route-composer
5
//
6
// Created by Eugene Kazaev in 2018-2022.
7
// Distributed under the MIT license.
8
//
9
// Become a sponsor:
10
// https://github.com/sponsors/ekazaev
11
//
12
13
import Foundation
14
import UIKit
15
16
extension UIViewController {
17
18
    var allPresentedViewControllers: [UIViewController] {
112x
19
        var allPresentedViewControllers: [UIViewController] = []
112x
20
        var presentingViewController = self
112x
21
112x
22
        while let presentedViewController = presentingViewController.presentedViewController, !presentedViewController.isBeingDismissed {
112x
23
            allPresentedViewControllers.append(presentedViewController)
20x
24
            presentingViewController = presentedViewController
20x
25
        }
112x
26
112x
27
        return allPresentedViewControllers
112x
28
    }
112x
29
30
    var allParents: [UIViewController] {
345x
31
        var allParents: [UIViewController] = []
345x
32
        var currentViewController: UIViewController? = parentViewController
345x
33
        while let currentParent = currentViewController {
345x
34
            allParents.append(currentParent)
280x
35
            currentViewController = currentParent.parentViewController
280x
36
        }
345x
37
        return allParents
345x
38
    }
345x
39
40
    static func findContainer<Container: ContainerViewController>(of viewController: UIViewController) -> Container? {
29x
41
        [[viewController], viewController.allParents].joined().first(where: { $0 is Container }) as? Container
46x
42
    }
29x
43
44
    var parentViewController: UIViewController? {
635x
45
        guard let interceptableViewController = self as? RoutingInterceptable else {
635x
46
            return parent
203x
47
        }
432x
48
        return interceptableViewController.overriddenParentViewController
432x
49
    }
635x
50
51
}