Created
March 29, 2018 21:18
-
-
Save matteocollina/538182f2a6f8c435819ace5b1efcdb89 to your computer and use it in GitHub Desktop.
Minimal ViewController that shows a react component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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