Creating a React Native Project with Forcereact
- Specify the type of application you want, along with basic configuration
data.
OR
- Use an existing Mobile SDK app as a template. You still provide the basic configuration data.
In Mobile SDK 9.0, forcereact adds an app type option to support TypeScript: react_native_typescript. This type becomes the default for the forcereact create command. To instead use standard JavaScript, you specify the react_native app type.
You can use forcereact in interactive mode with command-line prompts, or in scripted mode with the parameterized command-line version.
Using Forcereact Interactively
To enter application options interactively at a command prompt, type forcereact create. The forcereact utility then prompts you for each configuration option.
Using Forcereact with Command-Line Options
If you prefer, you can specify forcereact parameters directly at the command line. To see usage information, type forcereact without arguments. The list of available options displays:
Specifying a Template
forcereact createWithTemplate is identical to forcereact create except that it also asks for a template repo URI. You set this path to point to any repo directory that contains a Mobile SDK app that can be used as a template. Your template app can be any supported Mobile SDK app type—react_native or react_native_typescript. The force script changes the template’s identifiers and configuration to match the values you provide for the other parameters.
Build and Run Your App with Android Studio
For React Native, Mobile SDK supports both npm and yarn for package management. When you see both options, the choice is yours.
- In a Terminal window or at Windows command prompt, change to your project’s root
directory.
- Run the following command:
-
npm start
OR
- yarn start
-
npm start
- Open your project in Android Studio.
-
From the Welcome screen, click Import Project (Eclipse ADT, Gradle, etc.).
OR
-
From the File menu, click .
-
- Browse to your <project_ root>/android/ directory
and click OK.
Android Studio automatically builds your workspace. This process can take several minutes. When the status bar reports “Gradle build successful”, you’re ready to run the project.
- Click Run 'app', or press
SHIFT+F10.
Android Studio launches your app in the emulator or on your connected Android device.
Build and Run Your App in Xcode
- In a Terminal window, change to your project’s root
directory.
- Type npm start, then press Return.
- In Xcode, open <project_ root>/ios/<project_name>.xcworkspace.
- Click Run.
Xcode launches your app in the simulator or on your connected iOS device.
How the Forcereact Script Generates New Apps
- The script downloads templates at runtime from a GitHub repo. For the forcereact create command, the script uses the default templates in the SalesforceMobileSDK-Templates GitHub repo.
- The script uses npm to download React Native dependencies.
- The script uses git (Android) or CocoaPods (iOS) to download Mobile SDK libraries.