The downside to this is that it takes a second or two to load the bundle before the app itself actually loads. Unless you have some fancy Objective-C or Swift ‘Loading’ animation, it’s just going to show a white screen. I don’t have any experience with iOS programming, so I decided to do the next best thing — load the bundle from the device locally. I was able to piece together most of what to do from this guide, but some of it I had to figure out on my own.
At work we recently shipped our first React Native components inside an app, and I’ve been mulling how (and if…medium.com React Native gives you the option to have the JS bundle stored in the application bundle, which gives you almost instant load times. I could use that mechanism to do what I wanted.
First, I needed to check to see if there was a downloaded JS bundle or if I needed to use the app’s bundle:
If you just throw this into your AppDelegate.m file, it will load the application bundle every time, since it isn’t downloading anything to the documents folder.
This is going to download the bundle and save it to the file path, but only after the application has already loaded.
Finally, use the boilerplate React Native code to insert the React Native view into the Objective-C app.
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@”***Name of your module***” initialProperties:nil launchOptions:launchOptions];