Skip to content
This repository has been archived by the owner on Feb 18, 2019. It is now read-only.

Commit

Permalink
docs(Embedding iOS): Added swift code for embedding react-native in a…
Browse files Browse the repository at this point in the history
…n app

Summary: Closes facebook#4198

Differential Revision: D3075219

Pulled By: mkonicek

fb-gh-sync-id: c350a4074e4ee586804c48b9587135f3fce7b243
shipit-source-id: c350a4074e4ee586804c48b9587135f3fce7b243
  • Loading branch information
davidyaha authored and Facebook Github Bot 4 committed Mar 21, 2016
1 parent 4807290 commit 7d059a1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions docs/EmbeddedAppIOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
@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.

Expand Down Expand Up @@ -149,6 +150,34 @@ Then add it as a subview of the `ReactView`.
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

In root directory, we need to start React Native development server.
Expand Down

0 comments on commit 7d059a1

Please sign in to comment.