Skip to content

Instantly share code, notes, and snippets.

@matteocollina
Created March 29, 2018 21:18
Show Gist options
  • Save matteocollina/538182f2a6f8c435819ace5b1efcdb89 to your computer and use it in GitHub Desktop.
Save matteocollina/538182f2a6f8c435819ace5b1efcdb89 to your computer and use it in GitHub Desktop.
Minimal ViewController that shows a react component
import Foundation
import React
class ViewController: UIViewController {
var reactRootView: RCTRootView!
var jsCodeLocation: URL!
override func viewDidLoad() {
super.viewDidLoad()
#if DEBUG
jsCodeLocation = URL(string: "http://localhost:8081/index.ios.bundle?platform=ios")
#else
jsCodeLocation = Bundle.main.url(forResource: "main", withExtension: "jsbundle")
#endif
reactRootView = RCTRootView(
bundleURL: jsCodeLocation,
moduleName: "StoryReactComponent",
initialProperties: nil,
launchOptions: nil)
self.view.addSubview(reactRootView)
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
reactRootView.frame = self.view.bounds
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment