Reputation: 752
I am working on react native iOS app(demo). And new to the react native. I want to know about the RCTRootView
i.e how it is work. And I have a doubt i.e. in the app delegate
the root view is created default. If I added another root view in my view controller
what happens? And it set which one will be the root view.Can anyone help me on this? And what happens if I create it with the new module name?
Thanks in advance...
Upvotes: 1
Views: 2577
Reputation: 707
When you create a new Xcode project, it'll specify a storyboard (Main.storyboard) to be your "Main Interface". You can see this in the "General" settings tab of your target. In that storyboard you will find the Storyboard Entry Point, an arrow on the left side of the View Controller. This indicates that the View Controller (which by default is of class ViewController
) will be your root view controller. If you remove the "Main Interface" setting (so that it's empty), you will not have a root view controller automatically; you will have to set it up manually.
Take a look at the examples that are available for ReactNative. You will see that the general approach is that in application: didFinishLaunchingWithOptions:
a UIWindow
is instantiated, followed by a plain UIViewController
. At some point before or after that, the RCTRootView
is instantiated (either using an RCTBridge
or the BundleURL: moduleName:...
initializer). This is a subclass of UIView
so it doesn't have a UIViewController
yet. Therefore it is then set as the view of the earlier mentioned plain UIViewController
, which is then set as the rootViewController
of the UIWindow
, which is made "key and visible", after which we're ready.
I have been working with ReactNative for only two days now, but seeing the above pattern repeatedly, I see myself today building something like an RCTRootViewController
to encapsulate it, passing the RCTRootView
in the loadView
method of the UIViewController
. The view controller can have initialisers that match the ones of the RCTRootView
.
Upvotes: 1