mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 17:54:48 +00:00
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:
parent
4807290442
commit
7d059a12f3
@ -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.
|
||||
|
||||
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user