diff --git a/docs/embeded-app.html b/docs/embeded-app.html index ad2d02cd8ac..8aed4b5bc85 100644 --- a/docs/embeded-app.html +++ b/docs/embeded-app.html @@ -1,9 +1,9 @@ -
CocoaPods is a package management tool for iOS/Mac development. We need to use it to download React Native. If you haven't install CocoaPods yet, checkout this tutorial.
When you are ready to work with CocoaPods, add the following line to Podfile. If you don't have one, then create it under the root directory of your project.
Since React makes no assumptions about the rest of your technology stack – it’s commonly noted as simply the V in MVC – it’s easily embeddable within an existing non-React Native app. In fact, it integrates with other best practice community tools like CocoaPods.
CocoaPods is a package management tool for iOS/Mac development. We need to use it to download React Native. If you haven't install CocoaPods yet, checkout this tutorial.
When you are ready to work with CocoaPods, add the following line to Podfile. If you don't have one, then create it under the root directory of your project.
Remember to install all subspecs you need. The <Text> element cannot be used without pod 'React/RCTText'.
Then install pods via shell
The installation process also requires Node.js.
First, enter React Native's pod root directory and create index.ios.js inside a directory ReactComponent.
Copy & paste following starter code for index.ios.js.
Remember to install all subspecs you need. The <Text> element cannot be used without pod 'React/RCTText'.
Then install your pods:
There are two pieces you’ll need to set up:
RCTRootView to display and manage your React Native componentsFirst, create a directory for your app’s React code and create a simple index.ios.js file:
Copy & paste following starter code for index.ios.js – it’s a barebones React Native app:
SimpleApp will be your module name, which will be used later on.
You should now add container view for React Native component. It can be any UIView in your app.

However, let's subclass UIView for the sake of clean code. Let's name it ReactView. Open up Yourproject.xcworkspace and create a new class ReactView (You can name it whatever you like :)).
SimpleApp will be your module name, which will be used later on.
You should now add a container view for the React Native component. It can be any UIView in your app.

However, let's subclass UIView for the sake of clean code. Let's name it ReactView. Open up Yourproject.xcworkspace and create a new class ReactView (You can name it whatever you like :)).
Don't forget to add an outlet for it.
In a view controller that wants to manage this view, go ahead and add an outlet and wire it up:
Here I disabled AutoLayout for simplicity. In real production world, you should turn on AutoLayout and setup constraints by yourself.
Ready for the most interesting part? Now we shall create the RCTRootView, where your React Native app lives in.
In ReactView.m, we need to first initiate RCTRootView with the URI of your index.ios.bundle. index.ios.bundle will be created by packager and served by React Native server, which will be discussed later on.
Here I disabled AutoLayout for simplicity. In real production world, you should turn on AutoLayout and setup constraints by yourself.
Ready for the most interesting part? Now we shall create the RCTRootView, where your React Native app lives in.
In ReactView.m, we need to first initiate RCTRootView with the URI of your index.ios.bundle. index.ios.bundle will be created by packager and served by React Native server, which will be discussed later on.
Then add it as a subview of the ReactView.
In root directory, we need to start React Native development server.
--root indicates the root of your React Native apps. Here we just have one index.ios.js. React Native development server will use packager to create a index.ios.bundle. Which can be access via http://localhost:8081/index.ios.bundle.
Now compile and run your app. You shall now see your React Native app running inside of the ReactView.

So under the hood, when RCTRootView is initialized, it will try to download, parse and run the bundle file from React Native development server. All you need to do is to implement your own container view, add RCTRootView as its subclass. And then serve the bundle using React Native development server. Then, bravo!
You can checkout full source code of sample application here.