Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting another coordinator as root does not remove previous coordinators navigation controller from window stack on iOS 12 #169

Open
Rendel27 opened this issue May 4, 2020 · 3 comments

Comments

@Rendel27
Copy link

Rendel27 commented May 4, 2020

Hello everyone,

There is a bug that prevents previous coordinators navigation controller (it's children and presented view controllers as well) to remove from UIApplication.shared.keyWindow's stack, when you set another coordinator as root:

let firstCoordinator = FirstCoordinator()
firstCoordinator.strongRouter.trigger(.another)

`
class FirstCoordinator: NavigationCoordinator {

override func prepareTransition(for route: FirstRoute) -> NavigationTransition {
    switch route {
    case .another:
        let secondCoordinator = SecondCoordinator()
        secondCoordinator.trigger(.pushSomething)
        return .present(secondCoordinator)
    }
}

}

class SecondCoordinator: NavigationCoordinator {

override func prepareTransition(for route: SecondRoute) -> NavigationTransition {
    switch route {
    case .push:
        DispatchQueue(label: "asdf").asyncAfter(deadline: .now() + 3) {
            DispatchQueue.main.async {
                let viewController = UIViewController()
                viewController.view.backgroundColor = UIColor(red: 0, green: 1, blue: 1, alpha: 0.5)
                UIApplication.shared.keyWindow?.rootViewController = viewController
            }
        }
        let viewController = UIViewController()
        viewController.view.backgroundColor = UIColor(red: 1, green: 1, blue: 0, alpha: 0.5)
        return .push(viewController)
    }
}

}
`

In this case if you check ui debugger you will see old view controllers and navigation controller in the stack.

NOTE: This happens on iOS 12 (and maybe 11 as well, but not sure).
It works good on iOS 13.

I have attached sample project too see the problem more detailed:
testMultiXCoordinator.zip

Thanks
Giorgi

@anthonygeranio
Copy link

@Rendel27 Did you fix this issue?

@Rendel27
Copy link
Author

@Rendel27 Did you fix this issue?

Nope :( Have not tried it again

@d2vydov
Copy link
Contributor

d2vydov commented Jun 16, 2020

you can try to use this way:

    public override var viewController: UIViewController! {
        return autoreleaseController
    }
    
    private weak var autoreleaseController: UIViewController?
    
    ..
    
    override func prepareTransition(for route: SecondRoute) -> NavigationTransition {
    switch route {
    case .push:
        DispatchQueue(label: "asdf").asyncAfter(deadline: .now() + 3) {
            DispatchQueue.main.async {
                let viewController = UIViewController()
                viewController.view.backgroundColor = UIColor(red: 0, green: 1, blue: 1, alpha: 0.5)
                UIApplication.shared.keyWindow?.rootViewController = viewController
            }
        }
        let viewController = UIViewController()
        viewController.view.backgroundColor = UIColor(red: 1, green: 1, blue: 0, alpha: 0.5)
        autoreleaseController = viewController
        return .push(viewController)
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants