QuickBirdEng / XCoordinator

🎌 Powerful navigation library for iOS based on the coordinator pattern
MIT License
2.26k stars 177 forks source link

Transition to new UIWindow #174

Closed d2vydov closed 4 years ago

d2vydov commented 4 years ago

How to use xcoordinator transitions if we wanna push controller with new UIWindow (on top of the current, making it key and visible)?

We are using this way:

case .someRoute:
            let someVcToPresent = ....
            let someVcWrapper = WindowWrapperViewController(rootViewController: someVcToPresent)
            UIApplication.shared.keyWindow?.resignFirstResponder()
            vc.modalPresentationStyle = .overCurrentContext
            rootViewController.present(vc, animated: true, completion: nil)
            return .none() 

We creating a wrapper view controller starting a new window with our controller. The simple code is

class WindowWrapperViewController: UIViewController {

    var window: UIWindow?
    let rootViewController: UIViewController
    let parentWindow: UIWindow

    init(rootViewController: UIViewController) {

        self.rootViewController = rootViewController
        self.parentWindow = UIApplication.shared.keyWindow ?? UIWindow()
        self.window = UIWindow(frame: rootViewController.view.frame)

        super.init(nibName: nil, bundle: nil)

        self.window?.rootViewController = self
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        window?.makeKeyAndVisible()

        present(rootViewController, animated: true, completion: nil)
    }
}

Is this the only one option to do something like this?

pauljohanneskraft commented 4 years ago

I'm not entirely sure, whether I understand what you are trying to accomplish... Why do you need to handle two different windows and how would you have solved the issue without the use of XCoordinator? I only could think of an improvement by wrapping the given code into a transition, so that you can chain it.

d2vydov commented 4 years ago

thank you for reply, I have reached the same conclusion, and decided to use windows 'separately' with returns a .none() - in this case all works fine.