ios-template icon indicating copy to clipboard operation
ios-template copied to clipboard

Unbalanced calls to begin/end appearance transition

Open ahtierney opened this issue 8 years ago • 2 comments

Currently the app coordinator launches the app with:

    func start(animated: Bool, completion: VoidClosure?) {
        // Configure window/root view controller
        window.setRootViewController(rootController, animated: false, completion: {
            self.window.makeKeyAndVisible()
            // Spin off auth coordinator

This creates a warning about unbalanced calls to the rootController which is not guaranteed to have finished displaying.

I'm proposing that we fix this one of two ways:

// Simply
        window.setRootViewController(rootController, animated: false, completion: {
            self.window.makeKeyAndVisible()
            DispatchQueue.main.async {
            // Spin off auth coordinator

or

// a more complex but "more correct" solution, something like:
struct LaunchBehavior: ViewControllerLifecycleBehavior {
    let onLaunch: VoidClosure
    func afterAppearing(_ viewController: UIViewController, animated: Bool) {
        onLaunch()
    }
}
    func start(animated: Bool, completion: VoidClosure?) {
        let onLaunch = LaunchBehavior() { [weak self] in
            // Spin off auth coordinator
        }
        rootController.addBehaviors([onLaunch])

        window.setRootViewController(rootController, animated: false, completion: {
            self.window.makeKeyAndVisible()
        })

ahtierney avatar Aug 03 '17 18:08 ahtierney

Addressed in part in #75

heyltsjay avatar Mar 26 '18 14:03 heyltsjay

This approach to presenting different coordinator flows also has a side effect of showing a "flash" of the main UI before the on-boarding or login flows appear. Another approach to fix both problems might be to manage the variable UI with a container VC, maybe a UINavigationController, that can be created with a "stack" of VCs, without having to show/present each one...

minimusic avatar Aug 05 '19 20:08 minimusic