diff --git a/.circleci/config.yml b/.circleci/config.yml index ac3cbfaa9a0..dd019ade62f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -64,7 +64,7 @@ jobs: - run: name: Check for missing index.html (build errors) command: | - if [ ! -f build/react-native/index.html ]; then + if [ ! -f build/index.html ]; then exit 1; fi # -------------------------------------------------- @@ -98,6 +98,7 @@ jobs: git config --global user.name "Website Deployment Script" echo "machine github.com login reactjs-bot password $GITHUB_TOKEN" > ~/.netrc echo "Deploying website..." + export NODE_OPTIONS=--max_old_space_size=4096 GIT_USER=reactjs-bot CIRCLE_PROJECT_REPONAME=react-native yarn run publish-gh-pages else echo "Skipping deploy." diff --git a/.gitignore b/.gitignore index 5d4acae64f8..e4401005a3f 100644 --- a/.gitignore +++ b/.gitignore @@ -13,5 +13,6 @@ website/i18n/* !website/i18n/en.json .nvmrc +.docusaurus website/scripts/sync-api-docs/generatedComponentApiDocs.js website/scripts/sync-api-docs/extracted.json diff --git a/docs/_getting-started-linux-android.md b/docs/_getting-started-linux-android.md new file mode 100644 index 00000000000..0386f23aef8 --- /dev/null +++ b/docs/_getting-started-linux-android.md @@ -0,0 +1,177 @@ +## Installing dependencies + +You will need Node, the React Native command line interface, a JDK, and Android Studio. + +While you can use any editor of your choice to develop your app, you will need to install Android Studio in order to set up the necessary tooling to build your React Native app for Android. + +

Node

+ +Follow the [installation instructions for your Linux distribution](https://nodejs.org/en/download/package-manager/) to install Node 10 or newer. + +

Java Development Kit

+ +React Native requires at least the version 8 of the Java SE Development Kit (JDK). You may download and install [OpenJDK](http://openjdk.java.net) from [AdoptOpenJDK](https://adoptopenjdk.net/) or your system packager. You may also [Download and install Oracle JDK 14](https://www.oracle.com/java/technologies/javase-jdk14-downloads.html) if desired. + +

Android development environment

+ +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. + +

1. Install Android Studio

+ +[Download and install Android Studio](https://developer.android.com/studio/index.html). While on Android Studio intallation wizard, make sure the boxes next to all of the following items are checked: + +- `Android SDK` +- `Android SDK Platform` +- `Android Virtual Device` + +Then, click "Next" to install all of these components. + +> If the checkboxes are grayed out, you will have a chance to install these components later on. + +Once setup has finalized and you're presented with the Welcome screen, proceed to the next step. + +

2. Install the Android SDK

+ +Android Studio installs the latest Android SDK by default. Building a React Native app with native code, however, requires the `Android 10 (Q)` SDK in particular. Additional Android SDKs can be installed through the SDK Manager in Android Studio. + +To do that, open Android Studio, click on "Configure" button and select "SDK Manager". + +> The SDK Manager can also be found within the Android Studio "Preferences" dialog, under **Appearance & Behavior** → **System Settings** → **Android SDK**. + +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 10 (Q)` entry, then make sure the following items are checked: + +- `Android SDK Platform 29` +- `Intel x86 Atom_64 System Image` or `Google APIs Intel x86 Atom System Image` + +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 `29.0.2` is selected. + +Finally, click "Apply" to download and install the Android SDK and related build tools. + +

3. Configure the ANDROID_HOME environment variable

+ +The React Native tools require some environment variables to be set up in order to build apps with native code. + +Add the following lines to your `$HOME/.bash_profile` or `$HOME/.bashrc` (if you are using `zsh` then `~/.zprofile` or `~/.zshrc`) config file: + +```shell +export ANDROID_HOME=$HOME/Android/Sdk +export PATH=$PATH:$ANDROID_HOME/emulator +export PATH=$PATH:$ANDROID_HOME/tools +export PATH=$PATH:$ANDROID_HOME/tools/bin +export PATH=$PATH:$ANDROID_HOME/platform-tools +``` + +> `.bash_profile` is specific to `bash`. If you're using another shell, you will need to edit the appropriate shell-specific config file. + +Type `source $HOME/.bash_profile` for `bash` or `source $HOME/.zprofile` to load the config into your current shell. Verify that ANDROID_HOME has been set by running `echo $ANDROID_HOME` and the appropriate directories have been added to your path by running `echo $PATH`. + +> Please make sure you use the correct Android SDK path. You can find the actual location of the SDK in the Android Studio "Preferences" dialog, under **Appearance & Behavior** → **System Settings** → **Android SDK**. + +

Watchman

+ +Follow the [Watchman installation guide](https://facebook.github.io/watchman/docs/install/#buildinstall) to compile and install Watchman from source. + +> [Watchman](https://facebook.github.io/watchman/docs/install/) is a tool by Facebook for watching changes in the filesystem. It is highly recommended you install it for better performance and increased compatibility in certain edge cases (translation: you may be able to get by without installing this, but your mileage may vary; installing this now may save you from a headache later). + +

React Native Command Line Interface

+ +React Native has a built-in command line interface. Rather than install and manage a specific version of the CLI globally, we recommend you access the current version at runtime using `npx`, which ships with Node.js. With `npx react-native `, the current stable version of the CLI will be downloaded and executed at the time the command is run. + +

Creating a new application

+ +> If you previously installed a global `react-native-cli` package, please remove it as it may cause unexpected issues. + +React Native has a built-in command line interface, which you can use to generate a new project. You can access it without installing anything globally using `npx`, which ships with Node.js. Let's create a new React Native project called "AwesomeProject": + +```shell +npx react-native init AwesomeProject +``` + +This is not necessary if you are integrating React Native into an existing application, if you "ejected" from Expo, or if you're adding Android support to an existing React Native project (see [Platform Specific Code](platform-specific-code.md)). You can also use a third-party CLI to init your React Native app, such as [Ignite CLI](https://github.com/infinitered/ignite). + +

[Optional] Using a specific version or template

+ +If you want to start a new project with a specific React Native version, you can use the `--version` argument: + +```shell +npx react-native init AwesomeProject --version X.XX.X +``` + +You can also start a project with a custom React Native template, like TypeScript, with `--template` argument: + +```shell +npx react-native init AwesomeTSProject --template react-native-template-typescript +``` + +

Preparing the Android device

+ +You will need an Android device to run your React Native Android app. This can be either a physical Android device, or more commonly, you can use an Android Virtual Device which allows you to emulate an Android device on your computer. + +Either way, you will need to prepare the device to run Android apps for development. + +

Using a physical device

+ +If you have a physical Android device, you can use it for development in place of an AVD by plugging it in to your computer using a USB cable and following the instructions [here](running-on-device.md). + +

Using a virtual device

+ +If you use Android Studio to open `./AwesomeProject/android`, you can see the list of available Android Virtual Devices (AVDs) by opening the "AVD Manager" from within Android Studio. Look for an icon that looks like this: + +![Android Studio AVD Manager](/docs/assets/GettingStartedAndroidStudioAVD.png) + +If you have recently installed Android Studio, you will likely need to [create a new AVD](https://developer.android.com/studio/run/managing-avds.html). Select "Create Virtual Device...", then pick any Phone from the list and click "Next", then select the **Q** API Level 29 image. + +> We recommend configuring [VM acceleration](https://developer.android.com/studio/run/emulator-acceleration.html#vm-linux) on your system to improve performance. Once you've followed those instructions, go back to the AVD Manager. + +Click "Next" then "Finish" to create your AVD. At this point you should be able to click on the green triangle button next to your AVD to launch it, then proceed to the next step. + +

Running your React Native application

+ +

Step 1: Start Metro

+ +First, you will need to start Metro, the JavaScript bundler that ships with React Native. Metro "takes in an entry file and various options, and returns a single JavaScript file that includes all your code and its dependencies."—[Metro Docs](https://facebook.github.io/metro/docs/concepts) + +To start Metro, run `npx react-native start` inside your React Native project folder: + +```shell +npx react-native start +``` + +`react-native start` starts Metro Bundler. + +> If you use the Yarn package manager, you can use `yarn` instead of `npx` when running React Native commands inside an existing project. + +> If you're familiar with web development, Metro is a lot like webpack—for React Native apps. Unlike Kotlin or Java, JavaScript isn't compiled—and neither is React Native. Bundling isn't the same as compiling, but it can help improve startup performance and translate some platform-specific JavaScript into more JavaScript. + +

Step 2: Start your application

+ +Let Metro Bundler run in its own terminal. Open a new terminal inside your React Native project folder. Run the following: + +```shell +npx react-native run-android +``` + +If everything is set up correctly, you should see your new app running in your Android emulator shortly. + +`npx react-native run-android` is one way to run your app - you can also run it directly from within Android Studio. + +> If you can't get this to work, see the [Troubleshooting](troubleshooting.md#content) page. + +

Modifying your app

+ +Now that you have successfully run the app, let's modify it. + +- Open `App.js` in your text editor of choice and edit some lines. +- Press the `R` key twice or select `Reload` from the Developer Menu (`Ctrl + M`) to see your changes! + +

That's it!

+ +Congratulations! You've successfully run and modified your first React Native app. + +
+ +

Now what?

+ +- If you want to add this new React Native code to an existing application, check out the [Integration guide](integration-with-existing-apps.md). + +If you're curious to learn more about React Native, check out the [Introduction to React Native](getting-started). diff --git a/docs/_getting-started-macos-android.md b/docs/_getting-started-macos-android.md new file mode 100644 index 00000000000..a30208553ab --- /dev/null +++ b/docs/_getting-started-macos-android.md @@ -0,0 +1,191 @@ +## Installing dependencies + +You will need Node, Watchman, the React Native command line interface, a JDK, and Android Studio. + +While you can use any editor of your choice to develop your app, you will need to install Android Studio in order to set up the necessary tooling to build your React Native app for Android. + +

Node & Watchman

+ +We recommend installing Node and Watchman using [Homebrew](http://brew.sh/). Run the following commands in a Terminal after installing Homebrew: + +```shell +brew install node +brew install watchman +``` + +If you have already installed Node on your system, make sure it is Node 10 or newer. + +[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. + +

Java Development Kit

+ +We recommend installing JDK using [Homebrew](http://brew.sh/). Run the following commands in a Terminal after installing Homebrew: + +```shell +brew cask install adoptopenjdk/openjdk/adoptopenjdk8 +``` + +If you have already installed JDK on your system, make sure it is JDK 8 or newer. + +

Android development environment

+ +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. + +

1. Install Android Studio

+ +[Download and install Android Studio](https://developer.android.com/studio/index.html). While on Android Studio intallation wizard, make sure the boxes next to all of the following items are checked: + +- `Android SDK` +- `Android SDK Platform` +- `Android Virtual Device` +- If you are not already using Hyper-V: `Performance (Intel ® HAXM)` ([See here for AMD or Hyper-V](https://android-developers.googleblog.com/2018/07/android-emulator-amd-processor-hyper-v.html)) + +Then, click "Next" to install all of these components. + +> If the checkboxes are grayed out, you will have a chance to install these components later on. + +Once setup has finalized and you're presented with the Welcome screen, proceed to the next step. + +

2. Install the Android SDK

+ +Android Studio installs the latest Android SDK by default. Building a React Native app with native code, however, requires the `Android 10 (Q)` SDK in particular. Additional Android SDKs can be installed through the SDK Manager in Android Studio. + +To do that, open Android Studio, click on "Configure" button and select "SDK Manager". + +![Android Studio Welcome](/docs/assets/GettingStartedAndroidStudioWelcomeMacOS.png) + +> The SDK Manager can also be found within the Android Studio "Preferences" dialog, under **Appearance & Behavior** → **System Settings** → **Android SDK**. + +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 10 (Q)` entry, then make sure the following items are checked: + +- `Android SDK Platform 29` +- `Intel x86 Atom_64 System Image` or `Google APIs Intel x86 Atom System Image` + +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 `29.0.2` is selected. + +Finally, click "Apply" to download and install the Android SDK and related build tools. + +

3. Configure the ANDROID_HOME environment variable

+ +The React Native tools require some environment variables to be set up in order to build apps with native code. + +Add the following lines to your `$HOME/.bash_profile` or `$HOME/.bashrc` (if you are using `zsh` then `~/.zprofile` or `~/.zshrc`) config file: + +```shell +export ANDROID_HOME=$HOME/Library/Android/sdk +export PATH=$PATH:$ANDROID_HOME/emulator +export PATH=$PATH:$ANDROID_HOME/tools +export PATH=$PATH:$ANDROID_HOME/tools/bin +export PATH=$PATH:$ANDROID_HOME/platform-tools +``` + +> `.bash_profile` is specific to `bash`. If you're using another shell, you will need to edit the appropriate shell-specific config file. + +Type `source $HOME/.bash_profile` for `bash` or `source $HOME/.zprofile` to load the config into your current shell. Verify that ANDROID_HOME has been set by running `echo $ANDROID_HOME` and the appropriate directories have been added to your path by running `echo $PATH`. + +> Please make sure you use the correct Android SDK path. You can find the actual location of the SDK in the Android Studio "Preferences" dialog, under **Appearance & Behavior** → **System Settings** → **Android SDK**. + +

React Native Command Line Interface

+ +React Native has a built-in command line interface. Rather than install and manage a specific version of the CLI globally, we recommend you access the current version at runtime using `npx`, which ships with Node.js. With `npx react-native `, the current stable version of the CLI will be downloaded and executed at the time the command is run. + +

Creating a new application

+ +> If you previously installed a global `react-native-cli` package, please remove it as it may cause unexpected issues. + +React Native has a built-in command line interface, which you can use to generate a new project. You can access it without installing anything globally using `npx`, which ships with Node.js. Let's create a new React Native project called "AwesomeProject": + +```shell +npx react-native init AwesomeProject +``` + +This is not necessary if you are integrating React Native into an existing application, if you "ejected" from Expo, or if you're adding Android support to an existing React Native project (see [Platform Specific Code](platform-specific-code.md)). You can also use a third-party CLI to init your React Native app, such as [Ignite CLI](https://github.com/infinitered/ignite). + +

[Optional] Using a specific version or template

+ +If you want to start a new project with a specific React Native version, you can use the `--version` argument: + +```shell +npx react-native init AwesomeProject --version X.XX.X +``` + +You can also start a project with a custom React Native template, like TypeScript, with `--template` argument: + +```shell +npx react-native init AwesomeTSProject --template react-native-template-typescript +``` + +

Preparing the Android device

+ +You will need an Android device to run your React Native Android app. This can be either a physical Android device, or more commonly, you can use an Android Virtual Device which allows you to emulate an Android device on your computer. + +Either way, you will need to prepare the device to run Android apps for development. + +

Using a physical device

+ +If you have a physical Android device, you can use it for development in place of an AVD by plugging it in to your computer using a USB cable and following the instructions [here](running-on-device.md). + +

Using a virtual device

+ +If you use Android Studio to open `./AwesomeProject/android`, you can see the list of available Android Virtual Devices (AVDs) by opening the "AVD Manager" from within Android Studio. Look for an icon that looks like this: + +![Android Studio AVD Manager](/docs/assets/GettingStartedAndroidStudioAVD.png) + +If you have recently installed Android Studio, you will likely need to [create a new AVD](https://developer.android.com/studio/run/managing-avds.html). Select "Create Virtual Device...", then pick any Phone from the list and click "Next", then select the **Q** API Level 29 image. + +> If you don't have HAXM installed, follow [these instructions](https://github.com/intel/haxm/wiki/Installation-Instructions-on-macOS) to set it up, then go back to the AVD Manager. + +Click "Next" then "Finish" to create your AVD. At this point you should be able to click on the green triangle button next to your AVD to launch it, then proceed to the next step. + +

Running your React Native application

+ +

Step 1: Start Metro

+ +First, you will need to start Metro, the JavaScript bundler that ships with React Native. Metro "takes in an entry file and various options, and returns a single JavaScript file that includes all your code and its dependencies."—[Metro Docs](https://facebook.github.io/metro/docs/concepts) + +To start Metro, run `npx react-native start` inside your React Native project folder: + +```shell +npx react-native start +``` + +`react-native start` starts Metro Bundler. + +> If you use the Yarn package manager, you can use `yarn` instead of `npx` when running React Native commands inside an existing project. + +> If you're familiar with web development, Metro is a lot like webpack—for React Native apps. Unlike Kotlin or Java, JavaScript isn't compiled—and neither is React Native. Bundling isn't the same as compiling, but it can help improve startup performance and translate some platform-specific JavaScript into more JavaScript. + +

Step 2: Start your application

+ +Let Metro Bundler run in its own terminal. Open a new terminal inside your React Native project folder. Run the following: + +```shell +npx react-native run-android +``` + +If everything is set up correctly, you should see your new app running in your Android emulator shortly. + +![AwesomeProject on Android](/docs/assets/GettingStartedAndroidSuccessMacOS.png) + +`npx react-native run-android` is one way to run your app - you can also run it directly from within Android Studio. + +> If you can't get this to work, see the [Troubleshooting](troubleshooting.md#content) page. + +

Modifying your app

+ +Now that you have successfully run the app, let's modify it. + +- Open `App.js` in your text editor of choice and edit some lines. +- Press the `R` key twice or select `Reload` from the Developer Menu (`⌘M`) to see your changes! + +

That's it!

+ +Congratulations! You've successfully run and modified your first React Native app. + +
+ +

Now what?

+ +- If you want to add this new React Native code to an existing application, check out the [Integration guide](integration-with-existing-apps.md). + +If you're curious to learn more about React Native, check out the [Introduction to React Native](getting-started). diff --git a/docs/_getting-started-macos-ios.md b/docs/_getting-started-macos-ios.md new file mode 100644 index 00000000000..eba4bed9c53 --- /dev/null +++ b/docs/_getting-started-macos-ios.md @@ -0,0 +1,135 @@ +## Installing dependencies + +You will need Node, Watchman, the React Native command line interface, and Xcode. + +While you can use any editor of your choice to develop your app, you will need to install Xcode in order to set up the necessary tooling to build your React Native app for iOS. + +### Node & Watchman + +We recommend installing Node and Watchman using [Homebrew](http://brew.sh/). Run the following commands in a Terminal after installing Homebrew: + +```shell +brew install node +brew install watchman +``` + +If you have already installed Node on your system, make sure it is Node 10 or newer. + +[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. + +### Xcode & CocoaPods + +The easiest way to install Xcode 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. + +If you have already installed Xcode on your system, make sure it is version 9.4 or newer. + +#### Command Line Tools + +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](/docs/assets/GettingStartedXcodeCommandLineTools.png) + +#### Installing an iOS Simulator in Xcode + +To install a simulator, open Xcode > Preferences... and select the Components tab. Select a simulator with the corresponding version of iOS you wish to use. + +#### CocoaPods + +[CocoaPods](https://cocoapods.org/) is built with Ruby and it will be installable with the default Ruby available on macOS. You can use a Ruby Version manager, however we recommend that you use the standard Ruby available on macOS unless you know what you're doing. + +Using the default Ruby install will require you to use `sudo` when installing gems. (This is only an issue for the duration of the gem installation, though.) + +```shell +sudo gem install cocoapods +``` + +For more information, please visit [CocoaPods Getting Started guide](https://guides.cocoapods.org/using/getting-started.html). + +### React Native Command Line Interface + +React Native has a built-in command line interface. Rather than install and manage a specific version of the CLI globally, we recommend you access the current version at runtime using `npx`, which ships with Node.js. With `npx react-native `, the current stable version of the CLI will be downloaded and executed at the time the command is run. + +## Creating a new application + +> If you previously installed a global `react-native-cli` package, please remove it as it may cause unexpected issues. + +You can use React Native's built-in command line interface to generate a new project. Let's create a new React Native project called "AwesomeProject": + +```shell +npx react-native init AwesomeProject +``` + +This is not necessary if you are integrating React Native into an existing application, if you "ejected" from Expo, or if you're adding iOS support to an existing React Native project (see [Platform Specific Code](platform-specific-code.md)). You can also use a third-party CLI to init your React Native app, such as [Ignite CLI](https://github.com/infinitered/ignite). + +### [Optional] Using a specific version or template + +If you want to start a new project with a specific React Native version, you can use the `--version` argument: + +```shell +npx react-native init AwesomeProject --version X.XX.X +``` + +You can also start a project with a custom React Native template, like TypeScript, with `--template` argument: + +```shell +npx react-native init AwesomeTSProject --template react-native-template-typescript +``` + +> **Note** If the above command is failing, you may have old version of `react-native` or `react-native-cli` installed globally on your pc. Try uninstalling the cli and run the cli using `npx`. + +## Running your React Native application + +### Step 1: Start Metro + +First, you will need to start Metro, the JavaScript bundler that ships with React Native. Metro "takes in an entry file and various options, and returns a single JavaScript file that includes all your code and its dependencies."—[Metro Docs](https://facebook.github.io/metro/docs/concepts) + +To start Metro, run `npx react-native start` inside your React Native project folder: + +```shell +npx react-native start +``` + +`react-native start` starts Metro Bundler. + +> If you use the Yarn package manager, you can use `yarn` instead of `npx` when running React Native commands inside an existing project. + +> If you're familiar with web development, Metro is a lot like webpack—for React Native apps. Unlike Kotlin or Java, JavaScript isn't compiled—and neither is React Native. Bundling isn't the same as compiling, but it can help improve startup performance and translate some platform-specific JavaScript into more JavaScript. + +### Step 2: Start your application + +Let Metro Bundler run in its own terminal. Open a new terminal inside your React Native project folder. Run the following: + +```shell +npx react-native run-ios +``` + +You should see your new app running in the iOS Simulator shortly. + +![AwesomeProject on iOS](/docs/assets/GettingStartediOSSuccess.png) + +`npx react-native run-ios` is one way to run your app. You can also run it directly from within Xcode. + +> If you can't get this to work, see the [Troubleshooting](troubleshooting.md#content) page. + +### Running on a device + +The above command will automatically run your app on the iOS Simulator by default. If you want to run the app on an actual physical iOS device, please follow the instructions [here](running-on-device.md). + +### Modifying your app + +Now that you have successfully run the app, let's modify it. + +- Open `App.js` in your text editor of choice and edit some lines. +- Hit `⌘R` in your iOS Simulator to reload the app and see your changes! + +### That's it! + +Congratulations! You've successfully run and modified your first React Native app. + +
+ +## Now what? + +- If you want to add this new React Native code to an existing application, check out the [Integration guide](integration-with-existing-apps.md). + +If you're curious to learn more about React Native, check out the [Introduction to React Native](getting-started). diff --git a/docs/_getting-started-windows-android.md b/docs/_getting-started-windows-android.md new file mode 100644 index 00000000000..9a4d64511f7 --- /dev/null +++ b/docs/_getting-started-windows-android.md @@ -0,0 +1,206 @@ +

Installing dependencies

+ +You will need Node, the React Native command line interface, Python2, a JDK, and Android Studio. + +While you can use any editor of your choice to develop your app, you will need to install Android Studio in order to set up the necessary tooling to build your React Native app for Android. + +

Node, Python2, JDK

+ +We recommend installing Node and Python2 via [Chocolatey](https://chocolatey.org), a popular package manager for Windows. + +React Native also requires [Java SE Development Kit (JDK)](https://openjdk.java.net/projects/jdk8/), as well as Python2. Both can be installed using Chocolatey. + +Open an Administrator Command Prompt (right click Command Prompt and select "Run as Administrator"), then run the following command: + +```powershell +choco install -y nodejs.install python2 openjdk8 +``` + +If you have already installed Node on your system, make sure it is Node 10 or newer. If you already have a JDK on your system, make sure it is version 8 or newer. + +> You can find additional installation options on [Node's Downloads page](https://nodejs.org/en/download/). + +> If you're using the latest version of Java Development Kit, you'll need to change the Gradle version of your project so it can recognize the JDK. You can do that by going to `{project root folder}\android\gradle\wrapper\gradle-wrapper.properties` and changing the `distributionUrl` value to upgrade the Gradle version. You can check out [here the lastest releases of Gradle](https://gradle.org/releases/). + +

Android development environment

+ +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. + +

1. Install Android Studio

+ +[Download and install Android Studio](https://developer.android.com/studio/index.html). While on Android Studio intallation wizard, make sure the boxes next to all of the following items are checked: + +- `Android SDK` +- `Android SDK Platform` +- `Android Virtual Device` +- If you are not already using Hyper-V: `Performance (Intel ® HAXM)` ([See here for AMD or Hyper-V](https://android-developers.googleblog.com/2018/07/android-emulator-amd-processor-hyper-v.html)) + +Then, click "Next" to install all of these components. + +> If the checkboxes are grayed out, you will have a chance to install these components later on. + +Once setup has finalized and you're presented with the Welcome screen, proceed to the next step. + +

2. Install the Android SDK

+ +Android Studio installs the latest Android SDK by default. Building a React Native app with native code, however, requires the `Android 10 (Q)` SDK in particular. Additional Android SDKs can be installed through the SDK Manager in Android Studio. + +To do that, open Android Studio, click on "Configure" button and select "SDK Manager". + +![Android Studio Welcome](/docs/assets/GettingStartedAndroidStudioWelcomeWindows.png) + +> The SDK Manager can also be found within the Android Studio "Preferences" dialog, under **Appearance & Behavior** → **System Settings** → **Android SDK**. + +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 10 (Q)` entry, then make sure the following items are checked: + +- `Android SDK Platform 29` +- `Intel x86 Atom_64 System Image` or `Google APIs Intel x86 Atom System Image` + +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 `29.0.2` is selected. + +Finally, click "Apply" to download and install the Android SDK and related build tools. + +

3. Configure the ANDROID_HOME environment variable

+ +The React Native tools require some environment variables to be set up in order to build apps with native code. + +1. Open the **Windows Control Panel.** +2. Click on **User Accounts,** then click **User Accounts** again +3. Click on **Change my environment variables** +4. Click on **New...** to create a new `ANDROID_HOME` user variable that points to the path to your Android SDK: + +![ANDROID_HOME Environment Variable](/docs/assets/GettingStartedAndroidEnvironmentVariableANDROID_HOME.png) + +The SDK is installed, by default, at the following location: + +```powershell +%LOCALAPPDATA%\Android\Sdk +``` + +You can find the actual location of the SDK in the Android Studio "Settings" dialog, under **Appearance & Behavior** → **System Settings** → **Android SDK**. + +Open a new Command Prompt window to ensure the new environment variable is loaded before proceeding to the next step. + +1. Open powershell +2. Copy and paste **Get-ChildItem -Path Env:\\** into powershell +3. Verify `ANDROID_HOME` has been added + +

4. Add platform-tools to Path

+ +1. Open the **Windows Control Panel.** +2. Click on **User Accounts,** then click **User Accounts** again +3. Click on **Change my environment variables** +4. Select the **Path** variable. +5. Click **Edit.** +6. Click **New** and add the path to platform-tools to the list. + +The default location for this folder is: + +```powershell +%LOCALAPPDATA%\Android\Sdk\platform-tools +``` + +

React Native Command Line Interface

+ +React Native has a built-in command line interface. Rather than install and manage a specific version of the CLI globally, we recommend you access the current version at runtime using `npx`, which ships with Node.js. With `npx react-native `, the current stable version of the CLI will be downloaded and executed at the time the command is run. + +

Creating a new application

+ +> If you previously installed a global `react-native-cli` package, please remove it as it may cause unexpected issues. + +React Native has a built-in command line interface, which you can use to generate a new project. You can access it without installing anything globally using `npx`, which ships with Node.js. Let's create a new React Native project called "AwesomeProject": + +```shell +npx react-native init AwesomeProject +``` + +This is not necessary if you are integrating React Native into an existing application, if you "ejected" from Expo, or if you're adding Android support to an existing React Native project (see [Platform Specific Code](platform-specific-code.md)). You can also use a third-party CLI to init your React Native app, such as [Ignite CLI](https://github.com/infinitered/ignite). + +

[Optional] Using a specific version or template

+ +If you want to start a new project with a specific React Native version, you can use the `--version` argument: + +```shell +npx react-native init AwesomeProject --version X.XX.X +``` + +You can also start a project with a custom React Native template, like TypeScript, with `--template` argument: + +```shell +npx react-native init AwesomeTSProject --template react-native-template-typescript +``` + +

Preparing the Android device

+ +You will need an Android device to run your React Native Android app. This can be either a physical Android device, or more commonly, you can use an Android Virtual Device which allows you to emulate an Android device on your computer. + +Either way, you will need to prepare the device to run Android apps for development. + +

Using a physical device

+ +If you have a physical Android device, you can use it for development in place of an AVD by plugging it in to your computer using a USB cable and following the instructions [here](running-on-device.md). + +

Using a virtual device

+ +If you use Android Studio to open `./AwesomeProject/android`, you can see the list of available Android Virtual Devices (AVDs) by opening the "AVD Manager" from within Android Studio. Look for an icon that looks like this: + +![Android Studio AVD Manager](/docs/assets/GettingStartedAndroidStudioAVD.png) + +If you have recently installed Android Studio, you will likely need to [create a new AVD](https://developer.android.com/studio/run/managing-avds.html). Select "Create Virtual Device...", then pick any Phone from the list and click "Next", then select the **Q** API Level 29 image. + +> If you don't have HAXM installed, click on "Install HAXM" or follow [these instructions](https://github.com/intel/haxm/wiki/Installation-Instructions-on-Windows) to set it up, then go back to the AVD Manager. + +Click "Next" then "Finish" to create your AVD. At this point you should be able to click on the green triangle button next to your AVD to launch it, then proceed to the next step. + +

Running your React Native application

+ +

Step 1: Start Metro

+ +First, you will need to start Metro, the JavaScript bundler that ships with React Native. Metro "takes in an entry file and various options, and returns a single JavaScript file that includes all your code and its dependencies."—[Metro Docs](https://facebook.github.io/metro/docs/concepts) + +To start Metro, run `npx react-native start` inside your React Native project folder: + +```shell +npx react-native start +``` + +`react-native start` starts Metro Bundler. + +> If you use the Yarn package manager, you can use `yarn` instead of `npx` when running React Native commands inside an existing project. + +> If you're familiar with web development, Metro is a lot like webpack—for React Native apps. Unlike Kotlin or Java, JavaScript isn't compiled—and neither is React Native. Bundling isn't the same as compiling, but it can help improve startup performance and translate some platform-specific JavaScript into more JavaScript. + +

Step 2: Start your application

+ +Let Metro Bundler run in its own terminal. Open a new terminal inside your React Native project folder. Run the following: + +```shell +npx react-native run-android +``` + +If everything is set up correctly, you should see your new app running in your Android emulator shortly. + +![AwesomeProject on Android](/docs/assets/GettingStartedAndroidSuccessWindows.png) + +`npx react-native run-android` is one way to run your app - you can also run it directly from within Android Studio. + +> If you can't get this to work, see the [Troubleshooting](troubleshooting.md#content) page. + +

Modifying your app

+ +Now that you have successfully run the app, let's modify it. + +- Open `App.js` in your text editor of choice and edit some lines. +- Press the `R` key twice or select `Reload` from the Developer Menu (`Ctrl + M`) to see your changes! + +

That's it!

+ +Congratulations! You've successfully run and modified your first React Native app. + +
+ +

Now what?

+ +- If you want to add this new React Native code to an existing application, check out the [Integration guide](integration-with-existing-apps.md). + +If you're curious to learn more about React Native, check out the [Introduction to React Native](getting-started). diff --git a/docs/_integration-with-exisiting-apps-java.md b/docs/_integration-with-exisiting-apps-java.md new file mode 100644 index 00000000000..32f08877423 --- /dev/null +++ b/docs/_integration-with-exisiting-apps-java.md @@ -0,0 +1,390 @@ +## Key Concepts + +The keys to integrating React Native components into your Android application are to: + +1. Set up React Native dependencies and directory structure. +2. Develop your React Native components in JavaScript. +3. Add a `ReactRootView` to your Android app. This view will serve as the container for your React Native component. +4. Start the React Native server and run your native application. +5. Verify that the React Native aspect of your application works as expected. + +## Prerequisites + +Follow the React Native CLI Quickstart in the [environment setup guide](environment-setup) to configure your development environment for building React Native apps for Android. + +### 1. Set up directory structure + +To ensure a smooth experience, create a new folder for your integrated React Native project, then copy your existing Android project to an `/android` subfolder. + +### 2. Install JavaScript dependencies + +Go to the root directory for your project and create a new `package.json` file with the following contents: + +``` +{ + "name": "MyReactNativeApp", + "version": "0.0.1", + "private": true, + "scripts": { + "start": "yarn react-native start" + } +} +``` + +Next, make sure you have [installed the yarn package manager](https://yarnpkg.com/lang/en/docs/install/). + +Install the `react` and `react-native` packages. Open a terminal or command prompt, then navigate to the directory with your `package.json` file and run: + +```shell +$ yarn add react-native +``` + +This will print a message similar to the following (scroll up in the yarn output to see it): + +> warning "react-native@0.52.2" has unmet peer dependency "react@16.2.0". + +This is OK, it means we also need to install React: + +```shell +$ yarn add react@version_printed_above +``` + +Yarn has created a new `/node_modules` folder. This folder stores all the JavaScript dependencies required to build your project. + +Add `node_modules/` to your `.gitignore` file. + +## Adding React Native to your app + +### Configuring maven + +Add the React Native and JSC dependency to your app's `build.gradle` file: + +```gradle +dependencies { + implementation "com.android.support:appcompat-v7:27.1.1" + ... + implementation "com.facebook.react:react-native:+" // From node_modules + implementation "org.webkit:android-jsc:+" +} +``` + +> If you want to ensure that you are always using a specific React Native version in your native build, replace `+` with an actual React Native version you've downloaded from `npm`. + +Add an entry for the local React Native and JSC maven directories to the top-level `build.gradle`. Be sure to add it to the “allprojects” block, above other maven repositories: + +```gradle +allprojects { + repositories { + maven { + // All of React Native (JS, Android binaries) is installed from npm + url "$rootDir/../node_modules/react-native/android" + } + maven { + // Android JSC is installed from npm + url("$rootDir/../node_modules/jsc-android/dist") + } + ... + } + ... +} +``` + +> Make sure that the path is correct! You shouldn’t run into any “Failed to resolve: com.facebook.react:react-native:0.x.x" errors after running Gradle sync in Android Studio. + +### Enable native modules autolinking + +To use the power of [autolinking](https://github.com/react-native-community/cli/blob/master/docs/autolinking.md), we have to apply it a few places. First add the following entry to `settings.gradle`: + +```gradle +apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) +``` + +Next add the following entry at the very bottom of the `app/build.gradle`: + +```gradle +apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) +``` + +### Configuring permissions + +Next, make sure you have the Internet permission in your `AndroidManifest.xml`: + + + +If you need to access to the `DevSettingsActivity` add to your `AndroidManifest.xml`: + + + +This is only used in dev mode when reloading JavaScript from the development server, so you can strip this in release builds if you need to. + +### Cleartext Traffic (API level 28+) + +> Starting with Android 9 (API level 28), cleartext traffic is disabled by default; this prevents your application from connecting to the [Metro bundler][metro]. The changes below allow cleartext traffic in debug builds. + +#### 1. Apply the `usesCleartextTraffic` option to your Debug `AndroidManifest.xml` + +```xml + + + + + +``` + +This is not required for Release builds. + +To learn more about Network Security Config and the cleartext traffic policy [see this link](https://developer.android.com/training/articles/security-config#CleartextTrafficPermitted). + +### Code integration + +Now we will actually modify the native Android application to integrate React Native. + +#### The React Native component + +The first bit of code we will write is the actual React Native code for the new "High Score" screen that will be integrated into our application. + +##### 1. Create a `index.js` file + +First, create an empty `index.js` file in the root of your React Native project. + +`index.js` is the starting point for React Native applications, and it is always required. It can be a small file that `require`s other file that are part of your React Native component or application, or it can contain all the code that is needed for it. In our case, we will put everything in `index.js`. + +##### 2. Add your React Native code + +In your `index.js`, create your component. In our sample here, we will add a `` component within a styled ``: + +```jsx +import React from 'react'; +import { + AppRegistry, + StyleSheet, + Text, + View +} from 'react-native'; + +class HelloWorld extends React.Component { + render() { + return ( + + Hello, World + + ); + } +} +var styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center' + }, + hello: { + fontSize: 20, + textAlign: 'center', + margin: 10 + } +}); + +AppRegistry.registerComponent( + 'MyReactNativeApp', + () => HelloWorld +); +``` + +##### 3. Configure permissions for development error overlay + +If your app is targeting the Android `API level 23` or greater, make sure you have the permission `android.permission.SYSTEM_ALERT_WINDOW` enabled for the development build. You can check this with `Settings.canDrawOverlays(this);`. This is required in dev builds because React Native development errors must be displayed above all the other windows. Due to the new permissions system introduced in the API level 23 (Android M), the user needs to approve it. This can be achieved by adding the following code to your Activity's in `onCreate()` method. + +```java +private final int OVERLAY_PERMISSION_REQ_CODE = 1; // Choose any value + +... + +if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (!Settings.canDrawOverlays(this)) { + Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, + Uri.parse("package:" + getPackageName())); + startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE); + } +} +``` + +Finally, the `onActivityResult()` method (as shown in the code below) has to be overridden to handle the permission Accepted or Denied cases for consistent UX. Also, for integrating Native Modules which use `startActivityForResult`, we need to pass the result to the `onActivityResult` method of our `ReactInstanceManager` instance. + +```java +@Override +protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == OVERLAY_PERMISSION_REQ_CODE) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (!Settings.canDrawOverlays(this)) { + // SYSTEM_ALERT_WINDOW permission not granted + } + } + } + mReactInstanceManager.onActivityResult( this, requestCode, resultCode, data ); +} +``` + +#### The Magic: `ReactRootView` + +Let's add some native code in order to start the React Native runtime and tell it to render our JS component. To do this, we're going to create an `Activity` that creates a `ReactRootView`, starts a React application inside it and sets it as the main content view. + +> If you are targeting Android version <5, use the `AppCompatActivity` class from the `com.android.support:appcompat` package instead of `Activity`. + +```java +public class MyReactActivity extends Activity implements DefaultHardwareBackBtnHandler { + private ReactRootView mReactRootView; + private ReactInstanceManager mReactInstanceManager; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + SoLoader.init(this, false); + + mReactRootView = new ReactRootView(this); + List packages = new PackageList(getApplication()).getPackages(); + // Packages that cannot be autolinked yet can be added manually here, for example: + // packages.add(new MyReactNativePackage()); + // Remember to include them in `settings.gradle` and `app/build.gradle` too. + + mReactInstanceManager = ReactInstanceManager.builder() + .setApplication(getApplication()) + .setCurrentActivity(this) + .setBundleAssetName("index.android.bundle") + .setJSMainModulePath("index") + .addPackages(packages) + .setUseDeveloperSupport(BuildConfig.DEBUG) + .setInitialLifecycleState(LifecycleState.RESUMED) + .build(); + // The string here (e.g. "MyReactNativeApp") has to match + // the string in AppRegistry.registerComponent() in index.js + mReactRootView.startReactApplication(mReactInstanceManager, "MyReactNativeApp", null); + + setContentView(mReactRootView); + } + + @Override + public void invokeDefaultOnBackPressed() { + super.onBackPressed(); + } +} +``` + +> If you are using a starter kit for React Native, replace the "HelloWorld" string with the one in your index.js file (it’s the first argument to the `AppRegistry.registerComponent()` method). + +Perform a “Sync Project files with Gradle” operation. + +If you are using Android Studio, use `Alt + Enter` to add all missing imports in your MyReactActivity class. Be careful to use your package’s `BuildConfig` and not the one from the `facebook` package. + +We need set the theme of `MyReactActivity` to `Theme.AppCompat.Light.NoActionBar` because some React Native UI components rely on this theme. + +```xml + + +``` + +> A `ReactInstanceManager` can be shared by multiple activities and/or fragments. You will want to make your own `ReactFragment` or `ReactActivity` and have a singleton _holder_ that holds a `ReactInstanceManager`. When you need the `ReactInstanceManager` (e.g., to hook up the `ReactInstanceManager` to the lifecycle of those Activities or Fragments) use the one provided by the singleton. + +Next, we need to pass some activity lifecycle callbacks to the `ReactInstanceManager` and `ReactRootView`: + +```java +@Override +protected void onPause() { + super.onPause(); + + if (mReactInstanceManager != null) { + mReactInstanceManager.onHostPause(this); + } +} + +@Override +protected void onResume() { + super.onResume(); + + if (mReactInstanceManager != null) { + mReactInstanceManager.onHostResume(this, this); + } +} + +@Override +protected void onDestroy() { + super.onDestroy(); + + if (mReactInstanceManager != null) { + mReactInstanceManager.onHostDestroy(this); + } + if (mReactRootView != null) { + mReactRootView.unmountReactApplication(); + } +} +``` + +We also need to pass back button events to React Native: + +```java +@Override + public void onBackPressed() { + if (mReactInstanceManager != null) { + mReactInstanceManager.onBackPressed(); + } else { + super.onBackPressed(); + } +} +``` + +This allows JavaScript to control what happens when the user presses the hardware back button (e.g. to implement navigation). When JavaScript doesn't handle the back button press, your `invokeDefaultOnBackPressed` method will be called. By default this finishes your `Activity`. + +Finally, we need to hook up the dev menu. By default, this is activated by (rage) shaking the device, but this is not very useful in emulators. So we make it show when you press the hardware menu button (use `Ctrl + M` if you're using Android Studio emulator): + +```java +@Override +public boolean onKeyUp(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_MENU && mReactInstanceManager != null) { + mReactInstanceManager.showDevOptionsDialog(); + return true; + } + return super.onKeyUp(keyCode, event); +} +``` + +Now your activity is ready to run some JavaScript code. + +### Test your integration + +You have now done all the basic steps to integrate React Native with your current application. Now we will start the [Metro bundler][metro] to build the `index.bundle` package and the server running on localhost to serve it. + +##### 1. Run the packager + +To run your app, you need to first start the development server. To do this, run the following command in the root directory of your React Native project: + +```shell +$ yarn start +``` + +##### 2. Run the app + +Now build and run your Android app as normal. + +Once you reach your React-powered activity inside the app, it should load the JavaScript code from the development server and display: + +![Screenshot](/docs/assets/EmbeddedAppAndroid.png) + +### Creating a release build in Android Studio + +You can use Android Studio to create your release builds too! It’s as quick as creating release builds of your previously-existing native Android app. There’s one additional step, which you’ll have to do before every release build. You need to execute the following to create a React Native bundle, which will be included with your native Android app: + +```shell +$ npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/com/your-company-name/app-package-name/src/main/assets/index.android.bundle --assets-dest android/com/your-company-name/app-package-name/src/main/res/ +``` + +> Don’t forget to replace the paths with correct ones and create the assets folder if it doesn’t exist. + +Now, create a release build of your native app from within Android Studio as usual and you should be good to go! + +### Now what? + +At this point you can continue developing your app as usual. Refer to our [debugging](debugging) and [deployment](running-on-device) docs to learn more about working with React Native. + +[metro]: https://facebook.github.io/metro/ diff --git a/docs/_integration-with-exisiting-apps-objc.md b/docs/_integration-with-exisiting-apps-objc.md new file mode 100644 index 00000000000..bc58ec92a7c --- /dev/null +++ b/docs/_integration-with-exisiting-apps-objc.md @@ -0,0 +1,361 @@ +## Key Concepts + +The keys to integrating React Native components into your iOS application are to: + +1. Set up React Native dependencies and directory structure. +2. Understand what React Native components you will use in your app. +3. Add these components as dependencies using CocoaPods. +4. Develop your React Native components in JavaScript. +5. Add a `RCTRootView` to your iOS app. This view will serve as the container for your React Native component. +6. Start the React Native server and run your native application. +7. Verify that the React Native aspect of your application works as expected. + +## Prerequisites + +Follow the React Native CLI Quickstart in the [environment setup guide](environment-setup) to configure your development environment for building React Native apps for iOS. + +### 1. Set up directory structure + +To ensure a smooth experience, create a new folder for your integrated React Native project, then copy your existing iOS project to a `/ios` subfolder. + +### 2. Install JavaScript dependencies + +Go to the root directory for your project and create a new `package.json` file with the following contents: + +``` +{ + "name": "MyReactNativeApp", + "version": "0.0.1", + "private": true, + "scripts": { + "start": "yarn react-native start" + } +} +``` + +Next, make sure you have [installed the yarn package manager](https://yarnpkg.com/lang/en/docs/install/). + +Install the `react` and `react-native` packages. Open a terminal or command prompt, then navigate to the directory with your `package.json` file and run: + +```shell +$ yarn add react-native +``` + +This will print a message similar to the following (scroll up in the yarn output to see it): + +> warning "react-native@0.52.2" has unmet peer dependency "react@16.2.0". + +This is OK, it means we also need to install React: + +```shell +$ yarn add react@version_printed_above +``` + +Yarn has created a new `/node_modules` folder. This folder stores all the JavaScript dependencies required to build your project. + +Add `node_modules/` to your `.gitignore` file. + +### 3. Install CocoaPods + +[CocoaPods](http://cocoapods.org) is a package management tool for iOS and macOS development. We use it to add the actual React Native framework code locally into your current project. + +We recommend installing CocoaPods using [Homebrew](http://brew.sh/). + +```shell +$ brew install cocoapods +``` + +> It is technically possible not to use CocoaPods, but that would require manual library and linker additions that would overly complicate this process. + +## Adding React Native to your app + +Assume the [app for integration](https://github.com/JoelMarcey/iOS-2048) is a [2048](https://en.wikipedia.org/wiki/2048_%28video_game%29) game. Here is what the main menu of the native application looks like without React Native. + +![Before RN Integration](/docs/assets/react-native-existing-app-integration-ios-before.png) + +### Command Line Tools for Xcode + +Install the Command Line Tools. Choose "Preferences..." in 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](/docs/assets/GettingStartedXcodeCommandLineTools.png) + +### Configuring CocoaPods dependencies + +Before you integrate React Native into your application, you will want to decide what parts of the React Native framework you would like to integrate. We will use CocoaPods to specify which of these "subspecs" your app will depend on. + +The list of supported `subspec`s is available in [`/node_modules/react-native/React.podspec`](https://github.com/facebook/react-native/blob/master/React.podspec). They are generally named by functionality. For example, you will generally always want the `Core` `subspec`. That will get you the `AppRegistry`, `StyleSheet`, `View` and other core React Native libraries. If you want to add the React Native `Text` library (e.g., for `` elements), then you will need the `RCTText` `subspec`. If you want the `Image` library (e.g., for `` elements), then you will need the `RCTImage` `subspec`. + +You can specify which `subspec`s your app will depend on in a `Podfile` file. The easiest way to create a `Podfile` is by running the CocoaPods `init` command in the `/ios` subfolder of your project: + +```shell +$ pod init +``` + +The `Podfile` will contain a boilerplate setup that you will tweak for your integration purposes. + +> The `Podfile` version changes depending on your version of `react-native`. Refer to https://react-native-community.github.io/upgrade-helper/ for the specific version of `Podfile` you should be using. + +Ultimately, your `Podfile` should look something similar to this: + +``` +# The target name is most likely the name of your project. +target 'NumberTileGame' do + + # Your 'node_modules' directory is probably in the root of your project, + # but if not, adjust the `:path` accordingly + pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector" + pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec" + pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired" + pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety" + pod 'React', :path => '../node_modules/react-native/' + pod 'React-Core', :path => '../node_modules/react-native/' + pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules' + pod 'React-Core/DevSupport', :path => '../node_modules/react-native/' + pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS' + pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation' + pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob' + pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image' + pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS' + pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network' + pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings' + pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text' + pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration' + pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/' + + pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact' + pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi' + pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor' + pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector' + pod 'ReactCommon/callinvoker', :path => "../node_modules/react-native/ReactCommon" + pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon" + pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga' + + pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec' + pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec' + pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec' + +end +``` + +After you have created your `Podfile`, you are ready to install the React Native pod. + +```shell +$ pod install +``` + +You should see output such as: + +``` +Analyzing dependencies +Fetching podspec for `React` from `../node_modules/react-native` +Downloading dependencies +Installing React (0.62.0) +Generating Pods project +Integrating client project +Sending stats +Pod installation complete! There are 3 dependencies from the Podfile and 1 total pod installed. +``` + +> If this fails with errors mentioning `xcrun`, make sure that in Xcode in **Preferences > Locations** the Command Line Tools are assigned. + +### Code integration + +Now we will actually modify the native iOS application to integrate React Native. For our 2048 sample app, we will add a "High Score" screen in React Native. + +#### The React Native component + +The first bit of code we will write is the actual React Native code for the new "High Score" screen that will be integrated into our application. + +##### 1. Create a `index.js` file + +First, create an empty `index.js` file in the root of your React Native project. + +`index.js` is the starting point for React Native applications, and it is always required. It can be a small file that `require`s other file that are part of your React Native component or application, or it can contain all the code that is needed for it. In our case, we will put everything in `index.js`. + +##### 2. Add your React Native code + +In your `index.js`, create your component. In our sample here, we will add a `` component within a styled `` + +```jsx +import React from 'react'; +import { + AppRegistry, + StyleSheet, + Text, + View +} from 'react-native'; + +class RNHighScores extends React.Component { + render() { + var contents = this.props['scores'].map((score) => ( + + {score.name}:{score.value} + {'\n'} + + )); + return ( + + + 2048 High Scores! + + {contents} + + ); + } +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center', + alignItems: 'center', + backgroundColor: '#FFFFFF' + }, + highScoresTitle: { + fontSize: 20, + textAlign: 'center', + margin: 10 + }, + scores: { + textAlign: 'center', + color: '#333333', + marginBottom: 5 + } +}); + +// Module name +AppRegistry.registerComponent('RNHighScores', () => RNHighScores); +``` + +> `RNHighScores` is the name of your module that will be used when you add a view to React Native from within your iOS application. + +#### The Magic: `RCTRootView` + +Now that your React Native component is created via `index.js`, you need to add that component to a new or existing `ViewController`. The easiest path to take is to optionally create an event path to your component and then add that component to an existing `ViewController`. + +We will tie our React Native component with a new native view in the `ViewController` that will actually contain it called `RCTRootView` . + +##### 1. Create an Event Path + +You can add a new link on the main game menu to go to the "High Score" React Native page. + +![Event Path](/docs/assets/react-native-add-react-native-integration-link.png) + +##### 2. Event Handler + +We will now add an event handler from the menu link. A method will be added to the main `ViewController` of your application. This is where `RCTRootView` comes into play. + +When you build a React Native application, you use the [Metro bundler][metro] to create an `index.bundle` that will be served by the React Native server. Inside `index.bundle` will be our `RNHighScore` module. So, we need to point our `RCTRootView` to the location of the `index.bundle` resource (via `NSURL`) and tie it to the module. + +We will, for debugging purposes, log that the event handler was invoked. Then, we will create a string with the location of our React Native code that exists inside the `index.bundle`. Finally, we will create the main `RCTRootView`. Notice how we provide `RNHighScores` as the `moduleName` that we created [above](#the-react-native-component) when writing the code for our React Native component. + +First `import` the `RCTRootView` header. + +```objectivec +#import +``` + +> The `initialProperties` are here for illustration purposes so we have some data for our high score screen. In our React Native component, we will use `this.props` to get access to that data. + +```objectivec +- (IBAction)highScoreButtonPressed:(id)sender { + NSLog(@"High Score Button Pressed"); + NSURL *jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.bundle?platform=ios"]; + + RCTRootView *rootView = + [[RCTRootView alloc] initWithBundleURL: jsCodeLocation + moduleName: @"RNHighScores" + initialProperties: + @{ + @"scores" : @[ + @{ + @"name" : @"Alex", + @"value": @"42" + }, + @{ + @"name" : @"Joel", + @"value": @"10" + } + ] + } + launchOptions: nil]; + UIViewController *vc = [[UIViewController alloc] init]; + vc.view = rootView; + [self presentViewController:vc animated:YES completion:nil]; +} +``` + +> Note that `RCTRootView initWithURL` starts up a new JSC VM. To save resources and simplify the communication between RN views in different parts of your native app, you can have multiple views powered by React Native that are associated with a single JS runtime. To do that, instead of using `[RCTRootView alloc] initWithURL`, use [`RCTBridge initWithBundleURL`](https://github.com/facebook/react-native/blob/master/React/Base/RCTBridge.h#L93) to create a bridge and then use `RCTRootView initWithBridge`. + +> When moving your app to production, the `NSURL` can point to a pre-bundled file on disk via something like `[[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];`. You can use the `react-native-xcode.sh` script in `node_modules/react-native/scripts/` to generate that pre-bundled file. + +##### 3. Wire Up + +Wire up the new link in the main menu to the newly added event handler method. + +![Event Path](/docs/assets/react-native-add-react-native-integration-wire-up.png) + +> One of the easier ways to do this is to open the view in the storyboard and right click on the new link. Select something such as the `Touch Up Inside` event, drag that to the storyboard and then select the created method from the list provided. + +### Test your integration + +You have now done all the basic steps to integrate React Native with your current application. Now we will start the [Metro bundler][metro] to build the `index.bundle` package and the server running on `localhost` to serve it. + +##### 1. Add App Transport Security exception + +Apple has blocked implicit cleartext HTTP resource loading. So we need to add the following our project's `Info.plist` (or equivalent) file. + +```xml +NSAppTransportSecurity + + NSExceptionDomains + + localhost + + NSTemporaryExceptionAllowsInsecureHTTPLoads + + + + +``` + +> App Transport Security is good for your users. Make sure to re-enable it prior to releasing your app for production. + +##### 2. Run the packager + +To run your app, you need to first start the development server. To do this, run the following command in the root directory of your React Native project: + +```shell +$ npm start +``` + +##### 3. Run the app + +If you are using Xcode or your favorite editor, build and run your native iOS application as normal. Alternatively, you can run the app from the command line using: + +``` +# From the root of your project +$ npx react-native run-ios +``` + +In our sample application, you should see the link to the "High Scores" and then when you click on that you will see the rendering of your React Native component. + +Here is the _native_ application home screen: + +![Home Screen](/docs/assets/react-native-add-react-native-integration-example-home-screen.png) + +Here is the _React Native_ high score screen: + +![High Scores](/docs/assets/react-native-add-react-native-integration-example-high-scores.png) + +> If you are getting module resolution issues when running your application please see [this GitHub issue](https://github.com/facebook/react-native/issues/4968) for information and possible resolution. [This comment](https://github.com/facebook/react-native/issues/4968#issuecomment-220941717) seemed to be the latest possible resolution. + +### See the Code + +You can examine the code that added the React Native screen to our sample app on [GitHub](https://github.com/JoelMarcey/iOS-2048/commit/9ae70c7cdd53eb59f5f7c7daab382b0300ed3585). + +### Now what? + +At this point you can continue developing your app as usual. Refer to our [debugging](debugging) and [deployment](running-on-device) docs to learn more about working with React Native. + +[metro]: https://facebook.github.io/metro/ diff --git a/docs/_integration-with-exisiting-apps-swift.md b/docs/_integration-with-exisiting-apps-swift.md new file mode 100644 index 00000000000..3262f14dca5 --- /dev/null +++ b/docs/_integration-with-exisiting-apps-swift.md @@ -0,0 +1,350 @@ +## Key Concepts + +The keys to integrating React Native components into your iOS application are to: + +1. Set up React Native dependencies and directory structure. +2. Understand what React Native components you will use in your app. +3. Add these components as dependencies using CocoaPods. +4. Develop your React Native components in JavaScript. +5. Add a `RCTRootView` to your iOS app. This view will serve as the container for your React Native component. +6. Start the React Native server and run your native application. +7. Verify that the React Native aspect of your application works as expected. + +## Prerequisites + +Follow the React Native CLI Quickstart in the [environment setup guide](environment-setup) to configure your development environment for building React Native apps for iOS. + +### 1. Set up directory structure + +To ensure a smooth experience, create a new folder for your integrated React Native project, then copy your existing iOS project to a `/ios` subfolder. + +### 2. Install JavaScript dependencies + +Go to the root directory for your project and create a new `package.json` file with the following contents: + +``` +{ + "name": "MyReactNativeApp", + "version": "0.0.1", + "private": true, + "scripts": { + "start": "yarn react-native start" + } +} +``` + +Next, make sure you have [installed the yarn package manager](https://yarnpkg.com/lang/en/docs/install/). + +Install the `react` and `react-native` packages. Open a terminal or command prompt, then navigate to the directory with your `package.json` file and run: + +```shell +$ yarn add react-native +``` + +This will print a message similar to the following (scroll up in the yarn output to see it): + +> warning "react-native@0.52.2" has unmet peer dependency "react@16.2.0". + +This is OK, it means we also need to install React: + +```shell +$ yarn add react@version_printed_above +``` + +Yarn has created a new `/node_modules` folder. This folder stores all the JavaScript dependencies required to build your project. + +Add `node_modules/` to your `.gitignore` file. + +### 3. Install CocoaPods + +[CocoaPods](http://cocoapods.org) is a package management tool for iOS and macOS development. We use it to add the actual React Native framework code locally into your current project. + +We recommend installing CocoaPods using [Homebrew](http://brew.sh/). + +```shell +$ brew install cocoapods +``` + +> It is technically possible not to use CocoaPods, but that would require manual library and linker additions that would overly complicate this process. + +## Adding React Native to your app + +Assume the [app for integration](https://github.com/JoelMarcey/swift-2048) is a [2048](https://en.wikipedia.org/wiki/2048_%28video_game%29) game. Here is what the main menu of the native application looks like without React Native. + +![Before RN Integration](/docs/assets/react-native-existing-app-integration-ios-before.png) + +### Command Line Tools for Xcode + +Install the Command Line Tools. Choose "Preferences..." in 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](/docs/assets/GettingStartedXcodeCommandLineTools.png) + +### Configuring CocoaPods dependencies + +Before you integrate React Native into your application, you will want to decide what parts of the React Native framework you would like to integrate. We will use CocoaPods to specify which of these "subspecs" your app will depend on. + +The list of supported `subspec`s is available in [`/node_modules/react-native/React.podspec`](https://github.com/facebook/react-native/blob/master/React.podspec). They are generally named by functionality. For example, you will generally always want the `Core` `subspec`. That will get you the `AppRegistry`, `StyleSheet`, `View` and other core React Native libraries. If you want to add the React Native `Text` library (e.g., for `` elements), then you will need the `RCTText` `subspec`. If you want the `Image` library (e.g., for `` elements), then you will need the `RCTImage` `subspec`. + +You can specify which `subspec`s your app will depend on in a `Podfile` file. The easiest way to create a `Podfile` is by running the CocoaPods `init` command in the `/ios` subfolder of your project: + +```shell +$ pod init +``` + +The `Podfile` will contain a boilerplate setup that you will tweak for your integration purposes. + +> The `Podfile` version changes depending on your version of `react-native`. Refer to https://react-native-community.github.io/upgrade-helper/ for the specific version of `Podfile` you should be using. + +Ultimately, your `Podfile` should look something similar to this: + +``` +source 'https://github.com/CocoaPods/Specs.git' + +# Required for Swift apps +platform :ios, '8.0' +use_frameworks! + +# The target name is most likely the name of your project. +target 'swift-2048' do + + # Your 'node_modules' directory is probably in the root of your project, + # but if not, adjust the `:path` accordingly + pod 'React', :path => '../node_modules/react-native', :subspecs => [ + 'Core', + 'CxxBridge', # Include this for RN >= 0.47 + 'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43 + 'RCTText', + 'RCTNetwork', + 'RCTWebSocket', # needed for debugging + # Add any other subspecs you want to use in your project + ] + # Explicitly include Yoga if you are using RN >= 0.42.0 + pod "Yoga", :path => "../node_modules/react-native/ReactCommon/yoga" + + # Third party deps podspec link + pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec' + pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec' + pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec' + +end +``` + +After you have created your `Podfile`, you are ready to install the React Native pod. + +```shell +$ pod install +``` + +You should see output such as: + +``` +Analyzing dependencies +Fetching podspec for `React` from `../node_modules/react-native` +Downloading dependencies +Installing React (0.62.0) +Generating Pods project +Integrating client project +Sending stats +Pod installation complete! There are 3 dependencies from the Podfile and 1 total pod installed. +``` + +> If this fails with errors mentioning `xcrun`, make sure that in Xcode in **Preferences > Locations** the Command Line Tools are assigned. + +> If you get a warning such as "_The `swift-2048 [Debug]` target overrides the `FRAMEWORK_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-swift-2048/Pods-swift-2048.debug.xcconfig`. This can lead to problems with the CocoaPods installation_", then make sure the `Framework Search Paths` in `Build Settings` for both `Debug` and `Release` only contain `$(inherited)`. + +### Code integration + +Now we will actually modify the native iOS application to integrate React Native. For our 2048 sample app, we will add a "High Score" screen in React Native. + +#### The React Native component + +The first bit of code we will write is the actual React Native code for the new "High Score" screen that will be integrated into our application. + +##### 1. Create a `index.js` file + +First, create an empty `index.js` file in the root of your React Native project. + +`index.js` is the starting point for React Native applications, and it is always required. It can be a small file that `require`s other file that are part of your React Native component or application, or it can contain all the code that is needed for it. In our case, we will put everything in `index.js`. + +##### 2. Add your React Native code + +In your `index.js`, create your component. In our sample here, we will add a `` component within a styled `` + +```jsx +import React from 'react'; +import { + AppRegistry, + StyleSheet, + Text, + View +} from 'react-native'; + +class RNHighScores extends React.Component { + render() { + var contents = this.props['scores'].map((score) => ( + + {score.name}:{score.value} + {'\n'} + + )); + return ( + + + 2048 High Scores! + + {contents} + + ); + } +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center', + alignItems: 'center', + backgroundColor: '#FFFFFF' + }, + highScoresTitle: { + fontSize: 20, + textAlign: 'center', + margin: 10 + }, + scores: { + textAlign: 'center', + color: '#333333', + marginBottom: 5 + } +}); + +// Module name +AppRegistry.registerComponent('RNHighScores', () => RNHighScores); +``` + +> `RNHighScores` is the name of your module that will be used when you add a view to React Native from within your iOS application. + +#### The Magic: `RCTRootView` + +Now that your React Native component is created via `index.js`, you need to add that component to a new or existing `ViewController`. The easiest path to take is to optionally create an event path to your component and then add that component to an existing `ViewController`. + +We will tie our React Native component with a new native view in the `ViewController` that will actually contain it called `RCTRootView` . + +##### 1. Create an Event Path + +You can add a new link on the main game menu to go to the "High Score" React Native page. + +![Event Path](/docs/assets/react-native-add-react-native-integration-link.png) + +##### 2. Event Handler + +We will now add an event handler from the menu link. A method will be added to the main `ViewController` of your application. This is where `RCTRootView` comes into play. + +When you build a React Native application, you use the [Metro bundler][metro] to create an `index.bundle` that will be served by the React Native server. Inside `index.bundle` will be our `RNHighScore` module. So, we need to point our `RCTRootView` to the location of the `index.bundle` resource (via `NSURL`) and tie it to the module. + +We will, for debugging purposes, log that the event handler was invoked. Then, we will create a string with the location of our React Native code that exists inside the `index.bundle`. Finally, we will create the main `RCTRootView`. Notice how we provide `RNHighScores` as the `moduleName` that we created [above](#the-react-native-component) when writing the code for our React Native component. + +First `import` the `React` library. + +```jsx +import React +``` + +> The `initialProperties` are here for illustration purposes so we have some data for our high score screen. In our React Native component, we will use `this.props` to get access to that data. + +```swift +@IBAction func highScoreButtonTapped(sender : UIButton) { + NSLog("Hello") + let jsCodeLocation = URL(string: "http://localhost:8081/index.bundle?platform=ios") + let mockData:NSDictionary = ["scores": + [ + ["name":"Alex", "value":"42"], + ["name":"Joel", "value":"10"] + ] + ] + + let rootView = RCTRootView( + bundleURL: jsCodeLocation, + moduleName: "RNHighScores", + initialProperties: mockData as [NSObject : AnyObject], + launchOptions: nil + ) + let vc = UIViewController() + vc.view = rootView + self.present(vc, animated: true, completion: nil) +} +``` + +> Note that `RCTRootView bundleURL` starts up a new JSC VM. To save resources and simplify the communication between RN views in different parts of your native app, you can have multiple views powered by React Native that are associated with a single JS runtime. To do that, instead of using `RCTRootView bundleURL`, use [`RCTBridge initWithBundleURL`](https://github.com/facebook/react-native/blob/master/React/Base/RCTBridge.h#L89) to create a bridge and then use `RCTRootView initWithBridge`. + +> When moving your app to production, the `NSURL` can point to a pre-bundled file on disk via something like `let mainBundle = NSBundle(URLForResource: "main" withExtension:"jsbundle")`. You can use the `react-native-xcode.sh` script in `node_modules/react-native/scripts/` to generate that pre-bundled file. + +##### 3. Wire Up + +Wire up the new link in the main menu to the newly added event handler method. + +![Event Path](/docs/assets/react-native-add-react-native-integration-wire-up.png) + +> One of the easier ways to do this is to open the view in the storyboard and right click on the new link. Select something such as the `Touch Up Inside` event, drag that to the storyboard and then select the created method from the list provided. + +### Test your integration + +You have now done all the basic steps to integrate React Native with your current application. Now we will start the [Metro bundler][metro] to build the `index.bundle` package and the server running on `localhost` to serve it. + +##### 1. Add App Transport Security exception + +Apple has blocked implicit cleartext HTTP resource loading. So we need to add the following our project's `Info.plist` (or equivalent) file. + +```xml +NSAppTransportSecurity + + NSExceptionDomains + + localhost + + NSTemporaryExceptionAllowsInsecureHTTPLoads + + + + +``` + +> App Transport Security is good for your users. Make sure to re-enable it prior to releasing your app for production. + +##### 2. Run the packager + +To run your app, you need to first start the development server. To do this, run the following command in the root directory of your React Native project: + +```shell +$ npm start +``` + +##### 3. Run the app + +If you are using Xcode or your favorite editor, build and run your native iOS application as normal. Alternatively, you can run the app from the command line using: + +``` +# From the root of your project +$ npx react-native run-ios +``` + +In our sample application, you should see the link to the "High Scores" and then when you click on that you will see the rendering of your React Native component. + +Here is the _native_ application home screen: + +![Home Screen](/docs/assets/react-native-add-react-native-integration-example-home-screen.png) + +Here is the _React Native_ high score screen: + +![High Scores](/docs/assets/react-native-add-react-native-integration-example-high-scores.png) + +> If you are getting module resolution issues when running your application please see [this GitHub issue](https://github.com/facebook/react-native/issues/4968) for information and possible resolution. [This comment](https://github.com/facebook/react-native/issues/4968#issuecomment-220941717) seemed to be the latest possible resolution. + +### See the Code + +You can examine the code that added the React Native screen to our sample app on [GitHub](https://github.com/JoelMarcey/swift-2048/commit/13272a31ee6dd46dc68b1dcf4eaf16c1a10f5229). + +### Now what? + +At this point you can continue developing your app as usual. Refer to our [debugging](debugging) and [deployment](running-on-device) docs to learn more about working with React Native. + +[metro]: https://facebook.github.io/metro/ diff --git a/docs/accessibility.md b/docs/accessibility.md index 20acbd5f28b..7d2e133bbe3 100644 --- a/docs/accessibility.md +++ b/docs/accessibility.md @@ -290,7 +290,7 @@ To use the volume key shortcut, press both volume keys for 3 seconds to start an Additionally, if you prefer, you can toggle TalkBack via command line with: -```sh +```shell # disable adb shell settings put secure enabled_accessibility_services com.android.talkback/com.google.android.marvin.talkback.TalkBackService diff --git a/docs/accessibilityinfo.md b/docs/accessibilityinfo.md index d7af5228b20..8983b7e8b89 100644 --- a/docs/accessibilityinfo.md +++ b/docs/accessibilityinfo.md @@ -3,22 +3,14 @@ id: accessibilityinfo title: AccessibilityInfo --- +import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import constants from '@site/core/TabsConstants'; + Sometimes it's useful to know whether or not the device has a screen reader that is currently active. The `AccessibilityInfo` API is designed for this purpose. You can use it to query the current state of the screen reader as well as to register to be notified when the state of the screen reader changes. ## Example -
-
    - - -
-
- - + + ```SnackPlayer name=AccessibilityInfo%20Function%20Component%20Example&supportedPlatforms=android,ios import React, { useState, useEffect } from "react"; @@ -95,7 +87,8 @@ const styles = StyleSheet.create({ export default App; ``` - + + ```SnackPlayer name=AccessibilityInfo%20Class%20Component%20Example&supportedPlatforms=android,ios import React, { Component } from 'react'; @@ -175,7 +168,8 @@ class AccessibilityStatusExample extends Component { export default AccessibilityStatusExample; ``` - + + --- diff --git a/docs/activityindicator.md b/docs/activityindicator.md index 60bf224adb6..ded7fc5041f 100644 --- a/docs/activityindicator.md +++ b/docs/activityindicator.md @@ -3,22 +3,14 @@ id: activityindicator title: ActivityIndicator --- +import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import constants from '@site/core/TabsConstants'; + Displays a circular loading indicator. ## Example -
-
    - - -
-
- - + + ```SnackPlayer name=ActivityIndicator%20Function%20Component%20Example import React from "react"; @@ -48,7 +40,8 @@ const styles = StyleSheet.create({ export default App; ``` - + + ```SnackPlayer name=ActivityIndicator%20Class%20Component%20Example import React, { Component } from "react"; @@ -82,7 +75,8 @@ const styles = StyleSheet.create({ export default App; ``` - + + # Reference @@ -108,9 +102,9 @@ Whether to show the indicator (`true`) or hide it (`false`). The foreground color of the spinner. -| Type | Default | -| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [color](colors) | `null` (system accent default color)
Android

`'#999999'`
iOS
| +| Type | Default | +| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [color](colors) | `null` (system accent default color)
Android

`'#999999'`
iOS
| --- diff --git a/docs/alert.md b/docs/alert.md index 9c4e51e2fa2..6f6e2870a2a 100644 --- a/docs/alert.md +++ b/docs/alert.md @@ -3,6 +3,8 @@ id: alert title: Alert --- +import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import constants from '@site/core/TabsConstants'; + Launches an alert dialog with the specified title and message. Optionally provide a list of buttons. Tapping any button will fire the respective onPress callback and dismiss the alert. By default, the only button will be an 'OK' button. @@ -11,18 +13,8 @@ This is an API that works both on Android and iOS and can show static alerts. To ### Example -
-
    - - -
-
- - + + ```SnackPlayer name=Alert%20Function%20Component%20Example&supportedPlatforms=ios,android import React, { useState } from "react"; @@ -64,7 +56,6 @@ const App = () => { return ( - - - - +#### Developer notes + + - + > The `Appearance` API is inspired by the [Media Queries draft](https://drafts.csswg.org/mediaqueries-5/) from the W3C. The color scheme preference is modeled after the [`prefers-color-scheme` CSS media feature](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme). - + + > The color scheme preference will map to the user's Light or [Dark theme](https://developer.android.com/guide/topics/ui/look-and-feel/darktheme) preference on Android 10 (API level 29) devices and higher. - + + > The color scheme preference will map to the user's Light or [Dark Mode](https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/dark-mode/) preference on iOS 13 devices and higher. - + + ## Example @@ -59,17 +59,13 @@ Indicates the current user preferred color scheme. The value may be updated late Supported color schemes: -| Value | Description | -| --------- | --------------------------------------------------- | -| `"light"` | The user prefers a light color theme. | -| `"dark"` | The user prefers a dark color theme. | -| `null` | The user has not indicated a preferred color theme. | - -> **Note:** `getColorScheme()` will always return `"light"` when debugging with browser. +- `light`: The user prefers a light color theme. +- `dark`: The user prefers a dark color theme. +- null: The user has not indicated a preferred color theme. -See also: [`useColorScheme`](usecolorscheme) hook. +See also: `useColorScheme` hook. ---- +> Note: `getColorScheme()` will always return `light` when debugging with Chrome. ### `addChangeListener()` @@ -79,8 +75,6 @@ static addChangeListener(listener) Add an event handler that is fired when appearance preferences change. ---- - ### `removeChangeListener()` ```jsx diff --git a/docs/appregistry.md b/docs/appregistry.md index 1732520b6d8..05c33c3495c 100644 --- a/docs/appregistry.md +++ b/docs/appregistry.md @@ -3,7 +3,7 @@ id: appregistry title: AppRegistry --- -