Ribs: [iOS] LaunchRouter should not come with ViewController

Created on 11 Oct 2018  路  8Comments  路  Source: uber/RIBs

In other way, should LaunchRouter come with UIWindow only. When it attaches child RIBs, child's ViewController will be set as rootViewController?

This will remove unused RootViewController and give it's child flexibility.

What do you think? I'm willing to make a PR.

Most helpful comment

You could just do:

// This property holds the UIWindow object in the windows array that is most recently sent the makeKeyAndVisible() message.
private var window: UIWindow? {
    return UIApplication.shared.keyWindow
}

func routeToOnboarding() {
    window?.rootViewController = OnboardingViewController
}

func routeToHomeTabbar() {
    window?.rootViewController = HomeTabbarViewController
}

func routeToLoggedOut() {
    window?.rootViewController = LoggedOutNavigationViewController
}

All 8 comments

Can you give an example of when a RootViewController is unused? In the case of having an app that has a logged in state its useful to have a RootViewController that can embed the logged in or logged out controller.

@sbarow We want to attach many types of ViewControleller like UITabbarViewController/UINavigationController... and we want make it as window.rootViewController. So when you in logged in state, you can embed LoggedInViewController as rootViewController of UIWindow.

And you can't do this from the RootViewController?

@sbarow At the moment, LaunchRouter will have RootViewController and never be detached, always be window.rootViewController. So we can only present/push child ViewController from root. We want something like this:

RootRouter:

func routeToOnboarding() {
    window.rootViewController = OnboardingViewController
}

func routeToHomeTabbar() {
    window.rootViewController = HomeTabbarViewController
}

func routeToLoggedOut() {
    window.rootViewController = LoggedOutNavigationViewController
}

If there are other way to do this, please tell me?

You could just do:

// This property holds the UIWindow object in the windows array that is most recently sent the makeKeyAndVisible() message.
private var window: UIWindow? {
    return UIApplication.shared.keyWindow
}

func routeToOnboarding() {
    window?.rootViewController = OnboardingViewController
}

func routeToHomeTabbar() {
    window?.rootViewController = HomeTabbarViewController
}

func routeToLoggedOut() {
    window?.rootViewController = LoggedOutNavigationViewController
}

@sbarow Thanks, but I didn't find a place to put this code. RIB should know their child but not the parent? So they should not change the view hierarchy from the root. I prefer to introduce a Router that will hold a UIWindow reference let developers decide how to use it.

I don't understand what you mean by

I didn't find a place to put this code

Regardless of if you have a Router that has a reference to the UIWindow or not you are going to have to be able to call the methods needed to replace the window.

The above code should work for you, it should live in your "Root" router, your children would communicate to its parent that they want to transition to one of the routes through the listener interface.

Hey, I end up by creating WindowRouter for internal use. Thanks for supporting @sbarow

Was this page helpful?
0 / 5 - 0 ratings