docs(Embedding iOS): Added swift code for embedding react-native in an app

Summary: Closes https://github.com/facebook/react-native/pull/4198

Differential Revision: D3075219

Pulled By: mkonicek

fb-gh-sync-id: c350a4074e4ee586804c48b9587135f3fce7b243
shipit-source-id: c350a4074e4ee586804c48b9587135f3fce7b243
This commit is contained in:
David Yahalomi 2016-03-20 18:18:08 -07:00 коммит произвёл Facebook Github Bot 4
Родитель 4807290442
Коммит 7d059a12f3
1 изменённых файлов: 29 добавлений и 0 удалений

Просмотреть файл

@ -118,6 +118,7 @@ In a view controller that wants to manage this view, go ahead and add an outlet
@property (weak, nonatomic) IBOutlet ReactView *reactView; @property (weak, nonatomic) IBOutlet ReactView *reactView;
@end @end
``` ```
__NOTE__ For Swift apps there is no need for that.
Here I disabled **AutoLayout** for simplicity. In real production world, you should turn on AutoLayout and setup constraints by yourself. Here I disabled **AutoLayout** for simplicity. In real production world, you should turn on AutoLayout and setup constraints by yourself.
@ -149,6 +150,34 @@ Then add it as a subview of the `ReactView`.
rootView.frame = self.bounds; rootView.frame = self.bounds;
``` ```
### Swift apps
Add the following to ReactView.swift file:
```
import UIKit
import React
class ReactView: UIView {
let rootView: RCTRootView = RCTRootView(bundleURL: NSURL(string: "http://localhost:8081/index.ios.bundle?platform=ios"),
moduleName: "SimpleApp", initialProperties: nil, launchOptions: nil)
override func layoutSubviews() {
super.layoutSubviews()
loadReact()
}
func loadReact () {
addSubview(rootView)
rootView.frame = self.bounds
}
}
```
And then make sure your view is added in a ViewContainer or story board file.
## Start Development Server ## Start Development Server
In root directory, we need to start React Native development server. In root directory, we need to start React Native development server.