Quickly develop ReactNative scaffolding using DVA + NativeBase + EXPO

Preview

This project was bootstrapped with Create React Native App.

Below you’ll find information about performing common tasks. The most recent version of this guide is available here.

Table of Contents

Updating to New Releases

You should only need to update the global installation of create-react-native-app very rarely, ideally never.

Updating the react-native-scripts dependency of your app should be as simple as bumping the version number in package.json and reinstalling your project’s dependencies.

Upgrading to a new version of React Native requires updating the react-native, react, and expo package versions, and setting the correct sdkVersion in app.json. See the versioning guide for up-to-date information about package version compatibility.

Available Scripts

If Yarn was installed when the project was initialized, then dependencies will have been installed via Yarn, and you should probably use it to run these commands as well. Unlike dependency installation, command running syntax is identical for Yarn and NPM at the time of this writing.

npm test

Runs the jest test runner on your tests.

npm run ios

Like npm start, but also attempts to open your app in the iOS Simulator if you’re on a Mac and have it installed.

Using Android Studio’s adb
  1. Make sure that you can run adb from your terminal.
  2. Open Genymotion and navigate to Settings -> ADBSelect “Use custom Android SDK Tools” and update with yourAndroid SDK directory.
Using Genymotion’s adb
  1. Find Genymotion’s copy of adb. On macOS for example, this is normally /Applications/Genymotion.app/Contents/MacOS/tools/.
  2. Add the Genymotion tools directory to your path (instructions for Mac, Linux, and Windows).
  3. Make sure that you can run adb from your terminal.

npm run eject

This will start the process of “ejecting” from Create React Native App’s build scripts. You’ll be asked a couple of questions about how you’d like to build your project.

Warning: Running eject is a permanent action (aside from whatever version control system you use). An ejected app will require you to have an Xcode and/or Android Studio environment set up.

Customizing App Display Name and Icon

You can edit app.json to include configuration keys under the expo key.

To change your app’s display name, set the expo.name key in app.json to an appropriate string.

To set an app icon, set the expo.icon key in app.json to be either a local path or a URL. It’s recommended that you use a 512×512 png file with transparency.

Writing and Running Tests

This project is set up to use jest for tests. You can configure whatever testing strategy you like, but jest works out of the box. Create test files in directories called __tests__ to have the files loaded by jest. See the the template project for an example test. The jest documentation is also a wonderful resource, as is the React Native testing tutorial.

Environment Variables

You can configure some of Create React Native App’s behavior using environment variables.

Adding Flow

Flow is a static type checker that helps you write code with fewer bugs. Check out this introduction to using static types in JavaScript if you are new to this concept.

React Native works with Flow out of the box, as long as your Flow version matches the one used in the version of React Native.

To add a local dependency to the correct Flow version to a Create React Native App project, follow these steps:

  1. Find the Flow [version] at the bottom of the included .flowconfig
  2. Run npm install --save-dev [email protected] (or yarn add --dev [email protected]), where x.y.z is the .flowconfig version number.
  3. Add "flow": "flow" to the scripts section of your package.json.
  4. Add // @flow to any files you want to type check (for example, to App.js).

Now you can run npm run flow (or yarn flow) to check the files for type errors. You can optionally use a plugin for your IDE or editor for a better integrated experience.

To learn more about Flow, check out its documentation.

Sharing and Deployment

Create React Native App does a lot of work to make app setup and development simple and straightforward, but it’s very difficult to do the same for deploying to Apple’s App Store or Google’s Play Store without relying on a hosted service.

Building an Expo “standalone” app

You can also use a service like Expo’s standalone builds if you want to get an IPA/APK for distribution without having to build the native code yourself.

Ejecting from Create React Native App

If you want to build and deploy your app yourself, you’ll need to eject from CRNA and use Xcode and Android Studio.

This is usually as simple as running npm run eject in your project, which will walk you through the process. Make sure to install react-native-cli and follow the native code getting started guide for React Native.

Should I Use ExpoKit?

If you have made use of Expo APIs while working on your project, then those API calls will stop working if you eject to a regular React Native project. If you want to continue using those APIs, you can eject to “React Native + ExpoKit” which will still allow you to build your own native code and continue using the Expo APIs. See the ejecting guide for more details about this option.

Troubleshooting

iOS Simulator won’t open

If you’re on a Mac, there are a few errors that users sometimes see when attempting to npm run ios:

  • “non-zero exit code: 107”
  • “You may need to install Xcode” but it is already installed
  • and others

There are a few steps you may want to take to troubleshoot these kinds of errors:

  1. Make sure Xcode is installed and open it to accept the license agreement if it prompts you. You can install it from the Mac App Store.
  2. Open Xcode’s Preferences, the Locations tab, and make sure that the Command Line Toolsmenu option is set to something. Sometimes when the CLI tools are first installed by Homebrew this option is left blank, which can prevent Apple utilities from finding the simulator. Make sure to re-runnpm/yarn run ios after doing so.
  3. If that doesn’t work, open the Simulator, and under the app menu select Reset Contents and Settings.... After that has finished, quit the Simulator, and re-run npm/yarn run ios.