2015-02-12 04:26:43 +00:00
---
2016-05-18 01:14:16 +00:00
id: quick-start-getting-started
2015-02-12 04:26:43 +00:00
title: Getting Started
layout: docs
2016-06-22 21:19:25 +00:00
category: The Basics
2015-02-12 04:26:43 +00:00
permalink: docs/getting-started.html
2016-06-26 19:30:58 +00:00
next: tutorial
2015-02-12 04:26:43 +00:00
---
2016-06-26 19:30:58 +00:00
Welcome to React Native! This page will help you install React Native on
your system, so that you can build apps with it right away. If you already
have React Native installed, you can skip ahead to the
2017-01-31 20:07:15 +00:00
[Tutorial ](docs/tutorial.html ).
2016-06-26 19:30:58 +00:00
The instructions are a bit different depending on your development operating system, and whether you want to start developing for iOS or Android. If you
want to develop for both iOS and Android, that's fine - you just have to pick
one to start with, since the setup is a bit different.
2015-02-12 04:26:43 +00:00
2016-05-06 03:25:25 +00:00
< div class = "toggler" >
2016-11-07 05:03:16 +00:00
< style >
.toggler a {
display: inline-block;
padding: 10px 5px;
margin: 2px;
border: 1px solid #05A5D1 ;
border-radius: 3px;
text-decoration: none !important;
}
.display-os-mac .toggler .button-mac,
.display-os-linux .toggler .button-linux,
.display-os-windows .toggler .button-windows,
.display-platform-ios .toggler .button-ios,
.display-platform-android .toggler .button-android {
background-color: #05A5D1 ;
color: white;
}
block { display: none; }
.display-platform-ios.display-os-mac .ios.mac,
.display-platform-ios.display-os-linux .ios.linux,
.display-platform-ios.display-os-windows .ios.windows,
.display-platform-android.display-os-mac .android.mac,
.display-platform-android.display-os-linux .android.linux,
.display-platform-android.display-os-windows .android.windows {
display: block;
}
< / style >
< span > Mobile OS:< / span >
< a href = "javascript:void(0);" class = "button-ios" onclick = "display('platform', 'ios')" > iOS< / a >
< a href = "javascript:void(0);" class = "button-android" onclick = "display('platform', 'android')" > Android< / a >
< span > Development OS:< / span >
< a href = "javascript:void(0);" class = "button-mac" onclick = "display('os', 'mac')" > macOS< / a >
< a href = "javascript:void(0);" class = "button-linux" onclick = "display('os', 'linux')" > Linux< / a >
< a href = "javascript:void(0);" class = "button-windows" onclick = "display('os', 'windows')" > Windows< / a >
2016-05-06 03:25:25 +00:00
< / div >
2015-02-12 04:26:43 +00:00
2016-05-06 03:25:25 +00:00
< block class = "linux windows ios" / >
2015-09-14 14:35:58 +00:00
2016-05-06 03:25:25 +00:00
## Unsupported
2015-09-14 14:35:58 +00:00
2016-06-22 21:19:25 +00:00
< div > Unfortunately, Apple only lets you develop for iOS on a Mac. If you want to build an iOS app but you don't have a Mac yet, you can try starting with the < a href = "" onclick = "display('platform', 'android')" > Android< / a > instructions instead.< / div >
2015-09-14 14:35:58 +00:00
2016-05-10 18:16:23 +00:00
< center > < img src = "img/react-native-sorry-not-supported.png" width = "150" > < / img > < / center >
2015-09-14 14:35:58 +00:00
2016-11-03 14:40:21 +00:00
< block class = "mac ios" / >
2016-09-19 19:13:23 +00:00
## Installing Dependencies
2015-02-12 04:26:43 +00:00
2016-09-19 19:13:23 +00:00
You will need Node.js, Watchman, the React Native command line interface, and Xcode.
2016-02-14 18:35:41 +00:00
2016-06-08 20:17:19 +00:00
< block class = "mac android" / >
2016-02-14 18:35:41 +00:00
2016-11-03 14:40:21 +00:00
## Installing Dependencies
2016-09-19 19:13:23 +00:00
You will need Node.js, Watchman, the React Native command line interface, and Android Studio.
2015-02-12 04:26:43 +00:00
2016-11-03 14:40:21 +00:00
< block class = "windows linux android" / >
## Installing Dependencies
You will need Node.js, the React Native command line interface, and Android Studio.
2016-06-08 20:17:19 +00:00
< block class = "mac ios android" / >
2015-02-12 04:26:43 +00:00
2016-09-19 19:13:23 +00:00
### Node, Watchman
We recommend installing Node and Watchman using [Homebrew ](http://brew.sh/ ). Run the following commands in a Terminal after installing Homebrew:
2016-05-06 03:25:25 +00:00
```
brew install node
2016-06-22 21:19:25 +00:00
brew install watchman
2016-05-06 03:25:25 +00:00
```
2016-09-19 19:13:23 +00:00
> [Watchman](https://facebook.github.io/watchman) is a tool by Facebook for watching
changes in the filesystem. It is highly recommended you install it for better performance.
2016-11-03 14:40:21 +00:00
< block class = "linux android" / >
2016-05-06 03:25:25 +00:00
2016-11-03 14:40:21 +00:00
### Node
2016-05-06 03:25:25 +00:00
2016-11-03 14:40:21 +00:00
Follow the [installation instructions for your Linux distribution ](https://nodejs.org/en/download/package-manager/ ) to install Node.js 4 or newer.
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
< block class = 'windows android' / >
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
### Node
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
We recommend installing Node.js and Python2 via [Chocolatey ](https://chocolatey.org ), a popular package manager for Windows. Open a Command Prompt as Administrator, then run:
2016-05-06 03:25:25 +00:00
2016-11-03 14:40:21 +00:00
```
choco install nodejs.install
choco install python2
```
2016-05-06 03:25:25 +00:00
2016-11-03 14:40:21 +00:00
> You can find additional installation options on [Node.js's Downloads page](https://nodejs.org/en/download/).
2016-05-06 03:25:25 +00:00
2016-11-03 14:40:21 +00:00
< block class = "mac ios android" / >
2016-05-06 03:25:25 +00:00
2016-11-03 14:40:21 +00:00
### The React Native CLI
2016-05-06 03:25:25 +00:00
2016-11-03 14:40:21 +00:00
Node.js comes with npm, which lets you install the React Native command line interface.
2016-06-26 19:30:58 +00:00
2016-11-28 11:01:46 +00:00
Run the following command in a Terminal:
```
npm install -g react-native-cli
```
2017-01-27 07:37:22 +00:00
> If you get an error like `Cannot find module 'npmlog'`, try installing npm directly: `curl -0 -L https://npmjs.org/install.sh | sudo sh`.
2016-12-02 04:10:13 +00:00
2016-11-03 14:40:21 +00:00
< block class = "windows linux android" / >
2016-06-26 19:30:58 +00:00
2016-11-03 14:40:21 +00:00
### The React Native CLI
2016-06-26 19:30:58 +00:00
2016-11-03 14:40:21 +00:00
Node.js comes with npm, which lets you install the React Native command line interface.
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
Run the following command in a Terminal:
2016-05-06 03:25:25 +00:00
2016-09-19 19:13:23 +00:00
```
2016-11-03 14:40:21 +00:00
npm install -g react-native-cli
2016-09-19 19:13:23 +00:00
```
2017-01-27 07:37:22 +00:00
> If you get an error like `Cannot find module 'npmlog'`, try installing npm directly: `curl -0 -L https://npmjs.org/install.sh | sudo sh`.
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
< block class = "mac ios" / >
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
### Xcode
2016-09-19 19:13:23 +00:00
2017-03-08 23:58:06 +00:00
The easiest way to install Xcode 8 is via the [Mac App Store ](https://itunes.apple.com/us/app/xcode/id497799835?mt=12 ). Installing Xcode will also install the iOS Simulator and all the necessary tools to build your iOS app.
2016-09-19 19:13:23 +00:00
2017-03-02 03:16:06 +00:00
You will also need to install the Xcode Command Line Tools. Open Xcode, then choose "Preferences..." from the Xcode menu. Go to the Locations panel and install the tools by selecting the most recent version in the Command Line Tools dropdown.
![Xcode Command Line Tools ](img/XcodeCommandLineTools.png )
2016-11-03 14:40:21 +00:00
< block class = "mac linux windows android" / >
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
### Android Development Environment
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
Setting up your development environment can be somewhat tedious if you're new to Android development. If you're already familiar with Android development, there are a few things you may need to configure. In either case, please make sure to carefully follow the next few steps.
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
#### 1. Download and install Android Studio
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
[Android Studio ](https://developer.android.com/studio/install.html ) provides the Android SDK and AVD (emulator) required to run and test your React Native apps.
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
< block class = "mac android" / >
2016-09-19 19:13:23 +00:00
2017-03-02 03:16:06 +00:00
> Android Studio requires a recent version of the [Java SE Development Kit (JDK)](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html).
2016-05-06 03:25:25 +00:00
2016-11-03 14:40:21 +00:00
< block class = "mac windows android" / >
2016-05-06 03:25:25 +00:00
2016-11-03 14:40:21 +00:00
#### 2. Install the AVD and HAXM
2016-09-19 19:13:23 +00:00
2017-03-02 03:16:06 +00:00
Android Virtual Devices allow you to run Android apps on your computer without the need for an actual Android phone or tablet. Choose `Custom` installation when running Android Studio for the first time. Make sure the boxes next to all of the following are checked:
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
- `Android SDK`
- `Android SDK Platform`
- `Performance (Intel ® HAXM)`
- `Android Virtual Device`
2016-05-06 03:25:25 +00:00
2016-11-03 14:40:21 +00:00
Then, click "Next" to install all of these components.
2016-05-06 03:25:25 +00:00
2016-11-03 14:40:21 +00:00
> If you've already installed Android Studio before, you can still [install HAXM](https://software.intel.com/en-us/android/articles/installation-instructions-for-intel-hardware-accelerated-execution-manager-windows) without performing a custom installation.
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
< block class = "linux android" / >
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
#### 2. Install the AVD and configure VM acceleration
2016-05-06 03:25:25 +00:00
2017-03-02 03:16:06 +00:00
Android Virtual Devices allow you to run Android apps on your computer without the need for an actual Android phone or tablet. Choose `Custom` installation when running Android Studio for the first time. Make sure the boxes next to all of the following are checked:
2016-05-06 03:25:25 +00:00
2016-11-03 14:40:21 +00:00
- `Android SDK`
- `Android SDK Platform`
- `Android Virtual Device`
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
Click "Next" to install all of these components, then [configure VM acceleration ](https://developer.android.com/studio/run/emulator-acceleration.html#vm-linux ) on your system.
2016-05-06 03:25:25 +00:00
2016-11-03 14:40:21 +00:00
< block class = "mac linux windows android" / >
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
#### 3. Install the Android 6.0 (Marshmallow) SDK
2016-05-06 03:25:25 +00:00
2017-02-16 03:45:57 +00:00
Android Studio installs the most recent Android SDK by default. React Native, however, requires the `Android 6.0 (Marshmallow)` SDK. To install it, launch the SDK Manager, click on "Configure" > "SDK Manager" in the "Welcome to Android Studio" screen.
2016-05-06 03:25:25 +00:00
2016-11-03 14:40:21 +00:00
> The SDK Manager can also be found within the Android Studio "Preferences" menu, under **Appearance & Behavior** → **System Settings** → **Android SDK**.
2016-09-19 19:13:23 +00:00
2017-02-16 03:45:57 +00:00
Select the "SDK Platforms" tab from within the SDK Manager, then check the box next to "Show Package Details" in the bottom right corner. Look for and expand the `Android 6.0 (Marshmallow)` entry, then make sure the following items are all checked:
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
- `Google APIs`
2017-01-25 22:26:30 +00:00
- `Android SDK Platform 23`
2016-11-03 14:40:21 +00:00
- `Intel x86 Atom_64 System Image`
- `Google APIs Intel x86 Atom_64 System Image`
2016-05-06 03:25:25 +00:00
2017-03-02 03:16:06 +00:00
![Android SDK Manager ](img/AndroidSDKManager.png )
2017-02-16 03:45:57 +00:00
Next, select the "SDK Tools" tab and check the box next to "Show Package Details" here as well. Look for and expand the "Android SDK Build Tools" entry, then make sure that `Android SDK Build-Tools 23.0.1` is selected.
2016-05-06 03:25:25 +00:00
2016-11-03 14:40:21 +00:00
Finally, click "Apply" to download and install the Android SDK and related build tools.
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
< block class = "mac windows linux android" / >
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
#### 4. Set up the ANDROID_HOME environment variable
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
The React Native command line interface requires the `ANDROID_HOME` environment variable to be set up.
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
< block class = "mac android" / >
2016-09-19 19:13:23 +00:00
2017-03-02 03:16:06 +00:00
Add the following lines to your `~/.profile` (or equivalent) config file:
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
```
2016-12-14 23:25:00 +00:00
export ANDROID_HOME=${HOME}/Library/Android/sdk
2016-11-03 14:40:21 +00:00
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
```
2016-09-19 19:13:23 +00:00
2017-03-02 03:16:06 +00:00
Type `source ~/.profile` to load the config into your current shell.
2016-11-03 14:40:21 +00:00
> Please make sure you export the correct path for `ANDROID_HOME`. If you installed the Android SDK using Homebrew, it would be located at `/usr/local/opt/android-sdk`.
2016-09-19 19:13:23 +00:00
2016-05-06 03:25:25 +00:00
< block class = "linux android" / >
2017-03-02 03:16:06 +00:00
Add the following lines to your `~/.profile` (or equivalent) config file:
2016-05-06 03:25:25 +00:00
2016-09-19 19:13:23 +00:00
```
2016-12-14 23:25:00 +00:00
export ANDROID_HOME=${HOME}/Android/Sdk
2016-09-19 19:13:23 +00:00
export PATH=${PATH}:${ANDROID_HOME}/tools
2016-11-03 14:40:21 +00:00
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
2016-09-19 19:13:23 +00:00
```
2017-03-02 03:16:06 +00:00
Type `source ~/.profile` to load the config into your current shell.
2016-09-19 19:13:23 +00:00
> Please make sure you export the correct path for `ANDROID_HOME` if you did not install the Android SDK using Android Studio.
< block class = "windows android" / >
2016-05-06 03:25:25 +00:00
2016-11-03 14:40:21 +00:00
Go to **Control Panel** → **System and Security** → **System** → **Change settings** →
**Advanced System Settings** → **Environment variables** → **New** , then enter the path to your Android SDK.
2016-09-19 19:13:23 +00:00
![env variable ](img/react-native-android-sdk-environment-variable-windows.png )
Restart the Command Prompt to apply the new environment variable.
2016-11-03 14:40:21 +00:00
> Please make sure you export the correct path for `ANDROID_HOME` if you did not install the Android SDK using Android Studio.
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
< block class = "linux android" / >
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
### Watchman (optional)
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
Follow the [Watchman installation guide ](https://facebook.github.io/watchman/docs/install.html#build-install ) to compile and install Watchman from source.
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
> [Watchman](https://facebook.github.io/watchman/docs/install.html) is a tool by Facebook for watching
changes in the filesystem. It is highly recommended you install it for better performance, but it's alright to skip this if you find the process to be tedious.
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
< block class = "mac windows linux android" / >
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
## Starting the Android Virtual Device
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
![Android Studio AVD Manager ](img/react-native-tools-avd.png )
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
You can see the list of available AVDs by opening the "AVD Manager" from within Android Studio. You can also run the following command in a terminal:
2016-09-19 19:13:23 +00:00
2016-11-03 14:40:21 +00:00
```
android avd
```
2016-09-19 19:13:23 +00:00
2017-03-02 03:16:06 +00:00
Once in the "AVD Manager", select your AVD and click "Edit...". Choose "Android 6.0 - API Level 23" under Device, and "Intel Atom (x86_64)" under CPU/ABI. Click OK, then select your new AVD and click "Start...", and finally, "Launch".
2016-11-03 14:40:21 +00:00
2017-03-02 03:16:06 +00:00
![Android AVD Configuration ](img/AndroidAVDConfiguration.png )
> It is very common to run into an issue where Android Studio fails to create a default AVD. You may follow the [Android Studio User Guide](https://developer.android.com/studio/run/managing-avds.html) to create a new AVD manually if needed.
### Using a real device
If you have a physical Android device, you can use it for development in place of an AVD. Plug it in to your computer using a USB cable and [enable USB debugging ](https://developer.android.com/training/basics/firstapp/running-app.html ) before proceeding to the next step.
2016-05-06 03:25:25 +00:00
< block class = "mac ios android" / >
2016-06-08 20:17:19 +00:00
## Testing your React Native Installation
2016-05-06 03:25:25 +00:00
< block class = "mac ios" / >
2016-09-19 19:13:23 +00:00
Use the React Native command line interface to generate a new React Native project called "AwesomeProject", then run `react-native run-ios` inside the newly created folder.
2016-06-08 20:17:19 +00:00
2016-05-06 03:25:25 +00:00
```
react-native init AwesomeProject
cd AwesomeProject
react-native run-ios
```
2016-09-19 19:13:23 +00:00
You should see your new app running in the iOS Simulator shortly.
2017-03-02 03:16:06 +00:00
![AwesomeProject on iOS ](img/iOSSuccess.png )
2016-11-03 14:40:21 +00:00
`react-native run-ios` is just one way to run your app. You can also run it directly from within Xcode or [Nuclide ](https://nuclide.io/ ).
2016-05-06 03:25:25 +00:00
< block class = "mac android" / >
2016-11-03 14:40:21 +00:00
Use the React Native command line interface to generate a new React Native project called "AwesomeProject", then run `react-native run-android` inside the newly created folder:
2016-06-08 20:17:19 +00:00
2016-05-06 03:25:25 +00:00
```
react-native init AwesomeProject
cd AwesomeProject
react-native run-android
```
2017-03-02 03:16:06 +00:00
If everything is set up correctly, you should see your new app running in your Android emulator shortly.
![AwesomeProject on Android ](img/AndroidSuccess.png )
2016-11-03 14:40:21 +00:00
`react-native run-android` is just one way to run your app - you can also run it directly from within Android Studio or [Nuclide ](https://nuclide.io/ ).
2016-05-06 03:25:25 +00:00
< block class = "mac ios android" / >
2016-06-08 20:17:19 +00:00
### Modifying your app
2016-05-06 03:25:25 +00:00
2016-06-08 20:17:19 +00:00
Now that you have successfully run the app, let's modify it.
2016-05-06 03:25:25 +00:00
< block class = "mac ios" / >
2016-06-08 20:17:19 +00:00
- Open `index.ios.js` in your text editor of choice and edit some lines.
- Hit `Command⌘ + R` in your iOS Simulator to reload the app and see your change!
2015-09-14 14:35:58 +00:00
2016-05-06 03:25:25 +00:00
< block class = "mac android" / >
2016-06-08 20:17:19 +00:00
- Open `index.android.js` in your text editor of choice and edit some lines.
- Press the `R` key twice or select `Reload` from the Developer Menu to see your change!
2016-05-06 03:25:25 +00:00
< block class = "mac ios android" / >
2016-06-08 20:17:19 +00:00
### That's it!
2016-05-06 03:25:25 +00:00
Congratulations! You've successfully run and modified your first React Native app.
2016-05-10 18:16:23 +00:00
< center > < img src = "img/react-native-congratulations.png" width = "150" > < / img > < / center >
2016-05-06 03:25:25 +00:00
2016-11-07 05:03:16 +00:00
< block class = "windows android" / >
## Testing your React Native Installation
Use the React Native command line interface to generate a new React Native project called "AwesomeProject", then run `react-native start` inside the newly created folder to start the packager.
```
react-native init AwesomeProject
cd AwesomeProject
react-native start
```
2017-03-02 03:16:06 +00:00
Open a new command prompt and run `react-native run-android` inside the same folder to launch the app on your Android emulator.
2016-11-07 05:03:16 +00:00
```
react-native run-android
```
< block class = "linux android" / >
2016-05-06 03:25:25 +00:00
2016-06-08 20:17:19 +00:00
## Testing your React Native Installation
2016-09-19 19:13:23 +00:00
Use the React Native command line interface to generate a new React Native project called "AwesomeProject", then run `react-native run-android` inside the newly created folder.
2016-05-06 03:25:25 +00:00
```
react-native init AwesomeProject
cd AwesomeProject
react-native run-android
```
2016-11-07 05:03:16 +00:00
< block class = "windows linux android" / >
2016-05-06 03:25:25 +00:00
2016-11-07 05:03:16 +00:00
If everything is set up correctly, you should see your new app running in your Android emulator shortly.
2016-05-06 03:25:25 +00:00
2017-03-02 03:16:06 +00:00
![AwesomeProject on Android ](img/AndroidSuccess.png )
2016-11-15 20:54:12 +00:00
2016-05-09 16:57:21 +00:00
< block class = "windows linux android" / >
2016-06-08 20:17:19 +00:00
### Modifying your app
2016-05-06 03:25:25 +00:00
2016-06-08 20:17:19 +00:00
Now that you have successfully run the app, let's modify it.
2016-05-06 03:25:25 +00:00
2016-06-08 20:17:19 +00:00
- Open `index.android.js` in your text editor of choice and edit some lines.
- Press the `R` key twice or select `Reload` from the Developer Menu to see your change!
2015-09-14 14:35:58 +00:00
2016-06-08 20:17:19 +00:00
### That's it!
2015-09-15 22:09:32 +00:00
2016-06-22 21:19:25 +00:00
Congratulations! You've successfully run and modified a React Native app.
2015-02-12 04:26:43 +00:00
2016-05-10 18:16:23 +00:00
< center > < img src = "img/react-native-congratulations.png" width = "150" > < / img > < / center >
2016-05-06 03:25:25 +00:00
2016-11-03 14:40:21 +00:00
< block class = "mac ios" / >
## Now What?
- If you want to add this new React Native code to an existing application, check out the [Integration guide ](docs/integration-with-existing-apps.html ).
- If you can't get this to work, see the [Troubleshooting ](docs/troubleshooting.html#content ) page.
- If you're curious to learn more about React Native, continue on
to the [Tutorial ](docs/tutorial.html ).
< block class = "windows linux mac android" / >
2015-09-14 14:35:58 +00:00
2016-06-26 19:30:58 +00:00
## Now What?
- If you want to add this new React Native code to an existing application, check out the [Integration guide ](docs/integration-with-existing-apps.html ).
2016-06-20 22:20:16 +00:00
2016-06-26 19:30:58 +00:00
- If you can't get this to work, see the [Troubleshooting ](docs/troubleshooting.html#content ) page.
2015-09-14 14:35:58 +00:00
2016-06-26 19:30:58 +00:00
- If you're curious to learn more about React Native, continue on
to the [Tutorial ](docs/tutorial.html ).
2015-09-14 14:35:58 +00:00
2016-05-06 03:25:25 +00:00
< script >
// Convert < div > ...< span > < block / > < / span > ...< / div >
// Into < div > ...< block / > ...< / div >
var blocks = document.getElementsByTagName('block');
for (var i = 0; i < blocks.length ; + + i ) {
var block = blocks[i];
var span = blocks[i].parentNode;
var container = span.parentNode;
container.insertBefore(block, span);
container.removeChild(span);
}
// Convert < div > ...< block / > content< block / > ...< / div >
// Into < div > ...< block > content< / block > < block / > ...< / div >
blocks = document.getElementsByTagName('block');
for (var i = 0; i < blocks.length ; + + i ) {
var block = blocks[i];
while (block.nextSibling & & block.nextSibling.tagName !== 'BLOCK') {
block.appendChild(block.nextSibling);
}
}
function display(type, value) {
var container = document.getElementsByTagName('block')[0].parentNode;
container.className = 'display-' + type + '-' + value + ' ' +
container.className.replace(RegExp('display-' + type + '-[a-z]+ ?'), '');
}
2016-05-18 16:10:30 +00:00
// If we are coming to the page with a hash in it (i.e. from a search, for example), try to get
// us as close as possible to the correct platform and dev os using the hashtag and block walk up.
var foundHash = false;
if (window.location.hash !== '' & & window.location.hash !== 'content') { // content is default
var hashLinks = document.querySelectorAll('a.hash-link');
for (var i = 0; i < hashLinks.length & & ! foundHash ; + + i ) {
if (hashLinks[i].hash === window.location.hash) {
var parent = hashLinks[i].parentElement;
while (parent) {
if (parent.tagName === 'BLOCK') {
var devOS = null;
var targetPlatform = null;
// Could be more than one target os and dev platform, but just choose some sort of order
// of priority here.
// Dev OS
if (parent.className.indexOf('mac') > -1) {
devOS = 'mac';
} else if (parent.className.indexOf('linux') > -1) {
devOS = 'linux';
} else if (parent.className.indexOf('windows') > -1) {
devOS = 'windows';
} else {
break; // assume we don't have anything.
}
// Target Platform
if (parent.className.indexOf('ios') > -1) {
targetPlatform = 'ios';
} else if (parent.className.indexOf('android') > -1) {
targetPlatform = 'android';
} else {
break; // assume we don't have anything.
}
// We would have broken out if both targetPlatform and devOS hadn't been filled.
display('os', devOS);
2016-11-17 04:11:48 +00:00
display('platform', targetPlatform);
2016-05-18 16:10:30 +00:00
foundHash = true;
break;
}
parent = parent.parentElement;
}
}
}
}
// Do the default if there is no matching hash
if (!foundHash) {
var isMac = navigator.platform === 'MacIntel';
var isWindows = navigator.platform === 'Win32';
display('os', isMac ? 'mac' : (isWindows ? 'windows' : 'linux'));
display('platform', isMac ? 'ios' : 'android');
}
2016-05-06 03:25:25 +00:00
< / script >