├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .travis.yml ├── README.md ├── examples ├── .gitkeep ├── complex-react-nav-with-guest-access │ ├── .babelrc │ ├── .gitignore │ ├── .watchmanconfig │ ├── App.js │ ├── App.test.js │ ├── README.md │ ├── app.json │ ├── package.json │ ├── src │ │ ├── api │ │ │ └── auth.js │ │ ├── components │ │ │ ├── Button.js │ │ │ └── Input.js │ │ ├── index.js │ │ ├── router.js │ │ └── screens │ │ │ ├── Feed.js │ │ │ ├── Loading.js │ │ │ ├── Profile.js │ │ │ ├── SignIn.js │ │ │ └── SignUp.js │ └── yarn.lock └── rotating-local-images │ ├── .babelrc │ ├── .gitignore │ ├── .watchmanconfig │ ├── App.js │ ├── app.json │ ├── assets │ ├── icon.png │ └── splash.png │ ├── package.json │ └── src │ ├── images │ ├── 1.jpg │ ├── 2.jpg │ └── 3.jpg │ └── index.js ├── package.json ├── tutorials ├── complex-react-nav-with-guest-access │ └── .expo │ │ └── packager-info.json ├── detect-multiple-touches-with-gesture-responder-system │ ├── App.js │ ├── app.json │ └── package.json ├── flexbox-basics │ ├── .babelrc │ ├── .gitignore │ ├── .watchmanconfig │ ├── App.js │ ├── app.json │ ├── assets │ │ ├── icon.png │ │ └── splash.png │ └── package.json ├── global-alerts │ ├── .babelrc │ ├── .gitignore │ ├── .watchmanconfig │ ├── App.js │ ├── GlobalAlerts.js │ ├── app.json │ ├── assets │ │ ├── close.png │ │ ├── close@2x.png │ │ ├── close@3x.png │ │ ├── icon.png │ │ └── splash.png │ ├── package.json │ └── yarn.lock ├── image-basics │ ├── .babelrc │ ├── .gitignore │ ├── .watchmanconfig │ ├── App.js │ ├── app.json │ ├── assets │ │ ├── icon.png │ │ ├── rn-school-logo.png │ │ ├── rn-school-logo@2x.png │ │ ├── rn-school-logo@3x.png │ │ └── splash.png │ └── package.json ├── instagram-style-animated-image-overlay │ ├── .babelrc │ ├── .gitignore │ ├── .watchmanconfig │ ├── App.js │ ├── App.test.js │ ├── README.md │ ├── Tutorial.md │ ├── app.json │ ├── package.json │ ├── src │ │ ├── DoubleTap.js │ │ ├── images │ │ │ ├── heart-outline.png │ │ │ ├── heart-outline@2x.png │ │ │ ├── heart-outline@3x.png │ │ │ ├── heart.png │ │ │ ├── heart@2x.png │ │ │ └── heart@3x.png │ │ └── index.js │ ├── tutorial-assets │ │ ├── 01.png │ │ ├── 02.png │ │ ├── 03.gif │ │ └── src.zip │ └── yarn.lock ├── instagram-style-double-tap │ ├── .babelrc │ ├── .gitignore │ ├── .watchmanconfig │ ├── App.js │ ├── App.test.js │ ├── README.md │ ├── Tutorial.md │ ├── app.json │ ├── package.json │ ├── src │ │ ├── DoubleTap.js │ │ ├── images │ │ │ ├── heart-outline.png │ │ │ ├── heart-outline@2x.png │ │ │ ├── heart-outline@3x.png │ │ │ ├── heart.png │ │ │ ├── heart@2x.png │ │ │ └── heart@3x.png │ │ └── index.js │ ├── tutorial-assets │ │ └── demo.gif │ └── yarn.lock ├── long-press-with-gesture-responder-system │ ├── App.js │ ├── app.json │ └── package.json ├── multi-theme-button │ ├── .babelrc │ ├── .gitignore │ ├── .watchmanconfig │ ├── App.js │ ├── App.test.js │ ├── Button.js │ ├── README.md │ ├── app.json │ ├── package.json │ └── yarn.lock ├── progressive-image-loading │ ├── .babelrc │ ├── .gitignore │ ├── .watchmanconfig │ ├── App.js │ ├── App.test.js │ ├── ProgressiveImage.js │ ├── README.md │ ├── Tutorial.md │ ├── app.json │ ├── package.json │ ├── tutorial-assets │ │ ├── 01.png │ │ ├── 02.gif │ │ ├── 03.gif │ │ ├── 04.gif │ │ ├── 05.gif │ │ ├── 06.png │ │ ├── 07.png │ │ └── 08.gif │ └── yarn.lock └── section-list-basics │ ├── .babelrc │ ├── .gitignore │ ├── .watchmanconfig │ ├── App.js │ ├── app.json │ ├── assets │ ├── icon.png │ └── splash.png │ └── package.json └── yarn.lock /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "extends": "airbnb", 3 | "parser": "babel-eslint", 4 | "env": { 5 | "browser": true, 6 | "jest": true 7 | }, 8 | "rules": { 9 | "react/jsx-filename-extension": 0, 10 | "react/prop-types": 0, 11 | "react/destructuring-assignment": 0, 12 | "global-require": 0, 13 | "import/no-unresolved": 0, 14 | "react/prefer-stateless-function": 0, 15 | "prefer-destructuring": 0, 16 | "import/prefer-default-export": 0, 17 | "no-underscore-dangle": 0, 18 | "react/no-multi-comp": 0, 19 | "no-alert": 0 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "8" 4 | install: 5 | - yarn install 6 | script: 7 | - yarn run lint 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Native Examples and Tutorials 2 | 3 | A single place to find all of the React Native tutorials created at Handlebar Labs. 4 | 5 | **Looking for more in-depth content? Check out any of [Handlebar Labs' courses](https://learn.handlebarlabs.com/courses)!** 6 | 7 | * [Tutorials](#tutorials) 8 | * [Examples](#examples) 9 | * [Courses](#courses) 10 | 11 | ## Tutorials 12 | 13 | * Layout with Flexbox - React Native Basics (November 7, 2018) - [video](https://www.youtube.com/watch?v=qBFMnFXVw2c), [code](https://github.com/HandlebarLabs/react-native-examples-and-tutorials/tree/master/tutorials/flexbox-basics) 14 | 15 | * How to use the Image Component - React Native Basics (November 7, 2018) - [video](https://www.youtube.com/watch?v=v-3sNvMNosY), [code](https://github.com/HandlebarLabs/react-native-examples-and-tutorials/tree/master/tutorials/image-basics) 16 | 17 | * Building a Global Alert System in React Native (November 5, 2018) - [video series](https://www.youtube.com/watch?v=NsAQTbAV2zE&list=PLG02JlJZbKbtNnOx2vlUqF_HBve5HVlH1), [code](https://github.com/HandlebarLabs/react-native-examples-and-tutorials/tree/master/tutorials/global-alerts) 18 | 19 | * How to Use the SectionList Component - React Native Basics (October 24, 2018) - [video tutorial](https://www.youtube.com/watch?v=I-6oheM6cz0&feature=youtu.be), [code](https://github.com/HandlebarLabs/react-native-examples-and-tutorials/tree/master/tutorials/section-list-basics) 20 | 21 | * Implement a Long Press Button with React Native's Gesture Responder System (October 17, 2018) - [video tutorial](https://www.youtube.com/watch?v=zYIvl9rEEK8), [code](https://github.com/HandlebarLabs/react-native-examples-and-tutorials/tree/master/tutorials/long-press-with-gesture-responder-system) 22 | 23 | * Detect Multiple Touches in React Native with the Gesture Responder System (October 17, 2018) - [video tutorial](https://www.youtube.com/watch?v=j7LK96nRXP4), [code](https://github.com/HandlebarLabs/react-native-examples-and-tutorials/tree/master/tutorials/detect-multiple-touches-with-gesture-responder-system) 24 | 25 | * Fix Broken React Native Projects in Xcode 10 (October 9, 2018) - [video tutorial](https://www.youtube.com/watch?v=sLMCmXT4i9A) 26 | 27 | * Progressive Image Loading (September 26, 2018) - [tutorial](https://medium.com/react-native-training/progressive-image-loading-in-react-native-e7a01827feb7), [code](https://github.com/HandlebarLabs/react-native-examples-and-tutorials/tree/master/tutorials/progressive-image-loading) 28 | 29 | * Building a React Native Multi-Theme Button (September 19, 2018) - [video tutorial](https://youtu.be/UUcaqUUeHWE), [code](https://github.com/HandlebarLabs/react-native-examples-and-tutorials/tree/master/tutorials/multi-theme-button) 30 | 31 | * Animated Image Overlay in React Native (September 12, 2018) - [written tutorial](https://medium.com/@spencer_carli/animated-image-overlay-in-react-native-9b8dd22a9c6e), [code](https://github.com/HandlebarLabs/react-native-examples-and-tutorials/tree/master/tutorials/instagram-style-animated-image-overlays) 32 | 33 | * Instagram Style Double Tap with React Native (September 6, 2018) - [written tutorial](https://medium.com/handlebar-labs/instagram-style-double-tap-with-react-native-49e757f68de), [code](https://github.com/HandlebarLabs/react-native-examples-and-tutorials/tree/master/tutorials/instagram-style-double-tap) 34 | 35 | * Install React Native Firebase Core [iOS] (August 16, 2018) - [video tutorial](https://www.youtube.com/watch?v=qiOGMcX6Xtw) 36 | 37 | * Install React Native Firebase Core [Android] (August 16, 2018) - [video tutorial](https://www.youtube.com/watch?v=_7iKm233n_M) 38 | 39 | * Intro to Gestures in React Native (July 24, 2018) - [written tutorial](https://medium.com/handlebar-labs/intro-to-gestures-in-react-native-e9b63dd3305), [code](https://snack.expo.io/@spencercarli/basic-javascript-navigator-example) 40 | 41 | * Build A JavaScript Navigator for React Native (July 24, 2018) - [written tutorial](https://www.fullstackreact.com/articles/build-your-own-javascript-navigator-for-react-native/) 42 | 43 | * How to Search a React Native FlatList (May 23, 2018) - [video tutorial](https://www.youtube.com/watch?v=b5P6LIjQZEU), [code](https://github.com/spencercarli/searchable-react-native-flatlist/tree/finished) 44 | 45 | * React Native Animated Answer Bar [Playlist - 7 Videos] (May 21, 2018) - [playlist](https://www.youtube.com/watch?v=LPieikcEMN0&list=PLG02JlJZbKbvWvjVhbjTq1IRg7Q3A1667), [code](https://github.com/HandlebarLabs/react-native-animated-answer-bar) 46 | 47 | * Enable Scroll in a React Native ScrollView Based on the Content Size (April 26, 2018) - [written tutorial](https://medium.com/@spencer_carli/enable-scroll-in-a-react-native-scrollview-based-on-the-content-size-87430ccf319b), [video tutorial](https://www.youtube.com/watch?v=riWf6CtFkUA), [code](https://github.com/spencercarli/react-native-dynamic-scrollview) 48 | 49 | * Use the SwitchNavigator in React Navigation for an Authentication Flow (React Native) (March 27, 2018) - [video tutorial](https://www.youtube.com/watch?v=L0ZsVjh2zBo), [code](https://github.com/spencercarli/react-navigation-auth-flow/tree/finished-code) 50 | 51 | * 4 Questions to Ask When Choosing a Push Notification Provider for a React Native App (March 21, 2018) - [written tutorial](https://medium.com/handlebar-labs/4-questions-to-ask-when-choosing-a-push-notification-provider-for-a-react-native-app-fc0949eebc40) 52 | 53 | * Migrating from the Old to New React Context API (March 13, 2018) - [video tutorial](https://www.youtube.com/watch?v=pfHk-k0R48A), [code](https://github.com/HandlebarLabs/currency-converter-starter/compare/dfd226dee89d2aa723470b567fab3a957e294822...6c51edf0d2984002f89585482aa15bdba826a59d) 54 | 55 | * Migrating from Redux to the New React Context API (March 13, 2018) - [video tutorial](https://www.youtube.com/watch?v=ISgz8F9z0aM), [code](https://github.com/HandlebarLabs/currency-converter-starter/compare/e96b8b31529291029ce56d9cd1dab352a4a09102...dfd226dee89d2aa723470b567fab3a957e294822) 56 | 57 | * React Native FlatList Grid (March 13, 2018) - [video tutorial](https://www.youtube.com/watch?v=8wv0kjsirso), [code](https://snack.expo.io/@spencercarli/react-native-flatlist-grid) 58 | 59 | * Fade in an Image with React Native with the Animated API (March 13, 2018) - [video tutorial](https://www.youtube.com/watch?v=vzPmI0GCDPM), [code](https://snack.expo.io/@spencercarli/fade-in-an-image-with-react-native-with-the-animated-api) 60 | 61 | * iPhoneX Compatibility in React Native with SafeAreaView (March 13, 2018) - [video tutorial](https://www.youtube.com/watch?v=C5gMteV-4-Y), [code](https://snack.expo.io/@spencercarli/iphonex-compatibility-in-react-native-with-safeareaview) 62 | 63 | * Dismiss the Keyboard in React Native from Anywhere (March 13, 2018) - [video tutorial](https://www.youtube.com/watch?v=z_FVCeWloig), [code](https://snack.expo.io/@spencercarli/dismiss-the-keyboard-in-react-native-from-anywhere) 64 | 65 | * How 💩 dad jokes helped me better understand immutable data (March 7, 2018) - [written tutorial](https://medium.com/handlebar-labs/how-dad-jokes-helped-me-better-understand-immutable-data-d4256a0d4eea), [code](https://snack.expo.io/B1N7JqT_G) 66 | 67 | * Perfect React Native Splash Screen (Android) (February 27, 2018) - [written tutorial](https://medium.com/handlebar-labs/how-to-add-a-splash-screen-to-a-react-native-app-ios-and-android-30a3cec835ae), [video tutorial](https://www.youtube.com/watch?v=yFrx8HZlNtI), [code](https://github.com/spencercarli/react-native-splash-screen-demo) 68 | 69 | * Perfect React Native Splash Screen (iOS) (February 27, 2018) - [written tutorial](https://medium.com/handlebar-labs/how-to-add-a-splash-screen-to-a-react-native-app-ios-and-android-30a3cec835ae), [video tutorial](https://www.youtube.com/watch?v=H0CC1UsvjDQ), [code](https://github.com/spencercarli/react-native-splash-screen-demo) 70 | 71 | * Configure Visual Studio Code for React Native Development (February 21, 2018) - [video tutorial](https://www.youtube.com/watch?v=_srHOd6EFQ0&t=20s) 72 | 73 | * How to Become a React Native Developer in 2018 (January 26, 2018) - [written tutorial](https://hackernoon.com/how-to-become-a-react-native-developer-in-2018-d9bc85e1d91f) 74 | 75 | * Setup Continuous Integration with React Native (November 16, 2017) - [written tutorial](https://medium.com/react-native-training/setup-continuous-integration-with-react-native-50ad2f6145f4) 76 | 77 | ## Examples 78 | 79 | * Complex React Navigation with Guest Access - [code](https://github.com/HandlebarLabs/react-native-examples-and-tutorials/tree/master/examples/complex-react-nav-with-guest-access) 80 | 81 | ## Courses 82 | 83 | * [**React Native Basics: Build a Currency Converter** - Learn to Use Navigation, Setup Redux, Design Components, Work with a Remote API, and More](https://learn.handlebarlabs.com/p/react-native-basics-build-a-currency-converter) (FREE) 84 | 85 | * [**Production Ready React Native** - Learn Best Practices, Follow a Focused Curriculum, and Write Code You’re Proud Of](https://learn.handlebarlabs.com/p/learn-to-send-react-native-apps-to-production) (PREMIUM) 86 | 87 | * [**Master Push Notifications in React Native** - The Most Effective and Efficient Way to Add Push Notifications to Your App](https://learn.handlebarlabs.com/p/master-push-notifications-in-react-native) (PREMIUM) 88 | 89 | * [**React Native Exercises** - Ten Exercises to Make You a Better React Native Developer](https://learn.handlebarlabs.com/p/react-native-exercises ) (PREMIUM) 90 | 91 | * [**How to Set up a New React Native Project** - Tips, Tricks, and Tools to Optimize Your React Native Development Workflow](https://learn.handlebarlabs.com/p/react-native-exercises ) (FREE) 92 | 93 | * [**Learn React Native + Meteor** - A Premium Course on Building Real-World iOS and Android Apps with React Native and Meteor](https://learn.handlebarlabs.com/p/react-native-meteor) (PREMIUM) 94 | -------------------------------------------------------------------------------- /examples/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HandlebarLabs/react-native-examples-and-tutorials/7dba1c1946728566ea6b08b3415dcc09b8f2f303/examples/.gitkeep -------------------------------------------------------------------------------- /examples/complex-react-nav-with-guest-access/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["babel-preset-expo"], 3 | "env": { 4 | "development": { 5 | "plugins": ["transform-react-jsx-source"] 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/complex-react-nav-with-guest-access/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # expo 4 | .expo/ 5 | 6 | # dependencies 7 | /node_modules 8 | 9 | # misc 10 | .env.local 11 | .env.development.local 12 | .env.test.local 13 | .env.production.local 14 | 15 | npm-debug.log* 16 | yarn-debug.log* 17 | yarn-error.log* 18 | -------------------------------------------------------------------------------- /examples/complex-react-nav-with-guest-access/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /examples/complex-react-nav-with-guest-access/App.js: -------------------------------------------------------------------------------- 1 | import App from './src'; 2 | 3 | export default App; 4 | -------------------------------------------------------------------------------- /examples/complex-react-nav-with-guest-access/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import renderer from 'react-test-renderer'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const rendered = renderer.create().toJSON(); 7 | expect(rendered).toBeTruthy(); 8 | }); 9 | -------------------------------------------------------------------------------- /examples/complex-react-nav-with-guest-access/README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React Native App](https://github.com/react-community/create-react-native-app). 2 | 3 | Below you'll find information about performing common tasks. The most recent version of this guide is available [here](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/README.md). 4 | 5 | ## Table of Contents 6 | 7 | * [Updating to New Releases](#updating-to-new-releases) 8 | * [Available Scripts](#available-scripts) 9 | * [npm start](#npm-start) 10 | * [npm test](#npm-test) 11 | * [npm run ios](#npm-run-ios) 12 | * [npm run android](#npm-run-android) 13 | * [npm run eject](#npm-run-eject) 14 | * [Writing and Running Tests](#writing-and-running-tests) 15 | * [Environment Variables](#environment-variables) 16 | * [Configuring Packager IP Address](#configuring-packager-ip-address) 17 | * [Customizing App Display Name and Icon](#customizing-app-display-name-and-icon) 18 | * [Sharing and Deployment](#sharing-and-deployment) 19 | * [Publishing to Expo's React Native Community](#publishing-to-expos-react-native-community) 20 | * [Building an Expo "standalone" app](#building-an-expo-standalone-app) 21 | * [Ejecting from Create React Native App](#ejecting-from-create-react-native-app) 22 | * [Build Dependencies (Xcode & Android Studio)](#build-dependencies-xcode-android-studio) 23 | * [Should I Use ExpoKit?](#should-i-use-expokit) 24 | * [Troubleshooting](#troubleshooting) 25 | * [Networking](#networking) 26 | * [iOS Simulator won't open](#ios-simulator-wont-open) 27 | * [QR Code does not scan](#qr-code-does-not-scan) 28 | 29 | ## Updating to New Releases 30 | 31 | You should only need to update the global installation of `create-react-native-app` very rarely, ideally never. 32 | 33 | 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. 34 | 35 | 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](https://github.com/react-community/create-react-native-app/blob/master/VERSIONS.md) for up-to-date information about package version compatibility. 36 | 37 | ## Available Scripts 38 | 39 | 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. 40 | 41 | ### `npm start` 42 | 43 | Runs your app in development mode. 44 | 45 | Open it in the [Expo app](https://expo.io) on your phone to view it. It will reload if you save edits to your files, and you will see build errors and logs in the terminal. 46 | 47 | Sometimes you may need to reset or clear the React Native packager's cache. To do so, you can pass the `--reset-cache` flag to the start script: 48 | 49 | ``` 50 | npm start --reset-cache 51 | # or 52 | yarn start --reset-cache 53 | ``` 54 | 55 | #### `npm test` 56 | 57 | Runs the [jest](https://github.com/facebook/jest) test runner on your tests. 58 | 59 | #### `npm run ios` 60 | 61 | Like `npm start`, but also attempts to open your app in the iOS Simulator if you're on a Mac and have it installed. 62 | 63 | #### `npm run android` 64 | 65 | Like `npm start`, but also attempts to open your app on a connected Android device or emulator. Requires an installation of Android build tools (see [React Native docs](https://facebook.github.io/react-native/docs/getting-started.html) for detailed setup). We also recommend installing Genymotion as your Android emulator. Once you've finished setting up the native build environment, there are two options for making the right copy of `adb` available to Create React Native App: 66 | 67 | ##### Using Android Studio's `adb` 68 | 69 | 1. Make sure that you can run adb from your terminal. 70 | 2. Open Genymotion and navigate to `Settings -> ADB`. Select “Use custom Android SDK tools” and update with your [Android SDK directory](https://stackoverflow.com/questions/25176594/android-sdk-location). 71 | 72 | ##### Using Genymotion's `adb` 73 | 74 | 1. Find Genymotion’s copy of adb. On macOS for example, this is normally `/Applications/Genymotion.app/Contents/MacOS/tools/`. 75 | 2. Add the Genymotion tools directory to your path (instructions for [Mac](http://osxdaily.com/2014/08/14/add-new-path-to-path-command-line/), [Linux](http://www.computerhope.com/issues/ch001647.htm), and [Windows](https://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/)). 76 | 3. Make sure that you can run adb from your terminal. 77 | 78 | #### `npm run eject` 79 | 80 | 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. 81 | 82 | **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](https://facebook.github.io/react-native/docs/getting-started.html) set up. 83 | 84 | ## Customizing App Display Name and Icon 85 | 86 | You can edit `app.json` to include [configuration keys](https://docs.expo.io/versions/latest/guides/configuration.html) under the `expo` key. 87 | 88 | To change your app's display name, set the `expo.name` key in `app.json` to an appropriate string. 89 | 90 | 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 512x512 png file with transparency. 91 | 92 | ## Writing and Running Tests 93 | 94 | This project is set up to use [jest](https://facebook.github.io/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__` or with the `.test` extension to have the files loaded by jest. See the [the template project](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/App.test.js) for an example test. The [jest documentation](https://facebook.github.io/jest/docs/en/getting-started.html) is also a wonderful resource, as is the [React Native testing tutorial](https://facebook.github.io/jest/docs/en/tutorial-react-native.html). 95 | 96 | ## Environment Variables 97 | 98 | You can configure some of Create React Native App's behavior using environment variables. 99 | 100 | ### Configuring Packager IP Address 101 | 102 | When starting your project, you'll see something like this for your project URL: 103 | 104 | ``` 105 | exp://192.168.0.2:19000 106 | ``` 107 | 108 | The "manifest" at that URL tells the Expo app how to retrieve and load your app's JavaScript bundle, so even if you load it in the app via a URL like `exp://localhost:19000`, the Expo client app will still try to retrieve your app at the IP address that the start script provides. 109 | 110 | In some cases, this is less than ideal. This might be the case if you need to run your project inside of a virtual machine and you have to access the packager via a different IP address than the one which prints by default. In order to override the IP address or hostname that is detected by Create React Native App, you can specify your own hostname via the `REACT_NATIVE_PACKAGER_HOSTNAME` environment variable: 111 | 112 | Mac and Linux: 113 | 114 | ``` 115 | REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname' npm start 116 | ``` 117 | 118 | Windows: 119 | ``` 120 | set REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname' 121 | npm start 122 | ``` 123 | 124 | The above example would cause the development server to listen on `exp://my-custom-ip-address-or-hostname:19000`. 125 | 126 | ## Sharing and Deployment 127 | 128 | 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. 129 | 130 | ### Publishing to Expo's React Native Community 131 | 132 | Expo provides free hosting for the JS-only apps created by CRNA, allowing you to share your app through the Expo client app. This requires registration for an Expo account. 133 | 134 | Install the `exp` command-line tool, and run the publish command: 135 | 136 | ``` 137 | $ npm i -g exp 138 | $ exp publish 139 | ``` 140 | 141 | ### Building an Expo "standalone" app 142 | 143 | You can also use a service like [Expo's standalone builds](https://docs.expo.io/versions/latest/guides/building-standalone-apps.html) if you want to get an IPA/APK for distribution without having to build the native code yourself. 144 | 145 | ### Ejecting from Create React Native App 146 | 147 | If you want to build and deploy your app yourself, you'll need to eject from CRNA and use Xcode and Android Studio. 148 | 149 | 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](https://facebook.github.io/react-native/docs/getting-started.html). 150 | 151 | #### Should I Use ExpoKit? 152 | 153 | 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](https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md) for more details about this option. 154 | 155 | ## Troubleshooting 156 | 157 | ### Networking 158 | 159 | If you're unable to load your app on your phone due to a network timeout or a refused connection, a good first step is to verify that your phone and computer are on the same network and that they can reach each other. Create React Native App needs access to ports 19000 and 19001 so ensure that your network and firewall settings allow access from your device to your computer on both of these ports. 160 | 161 | Try opening a web browser on your phone and opening the URL that the packager script prints, replacing `exp://` with `http://`. So, for example, if underneath the QR code in your terminal you see: 162 | 163 | ``` 164 | exp://192.168.0.1:19000 165 | ``` 166 | 167 | Try opening Safari or Chrome on your phone and loading 168 | 169 | ``` 170 | http://192.168.0.1:19000 171 | ``` 172 | 173 | and 174 | 175 | ``` 176 | http://192.168.0.1:19001 177 | ``` 178 | 179 | If this works, but you're still unable to load your app by scanning the QR code, please open an issue on the [Create React Native App repository](https://github.com/react-community/create-react-native-app) with details about these steps and any other error messages you may have received. 180 | 181 | If you're not able to load the `http` URL in your phone's web browser, try using the tethering/mobile hotspot feature on your phone (beware of data usage, though), connecting your computer to that WiFi network, and restarting the packager. If you are using a VPN you may need to disable it. 182 | 183 | ### iOS Simulator won't open 184 | 185 | If you're on a Mac, there are a few errors that users sometimes see when attempting to `npm run ios`: 186 | 187 | * "non-zero exit code: 107" 188 | * "You may need to install Xcode" but it is already installed 189 | * and others 190 | 191 | There are a few steps you may want to take to troubleshoot these kinds of errors: 192 | 193 | 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. 194 | 2. Open Xcode's Preferences, the Locations tab, and make sure that the `Command Line Tools` menu 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-run `npm/yarn run ios` after doing so. 195 | 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`. 196 | 197 | ### QR Code does not scan 198 | 199 | If you're not able to scan the QR code, make sure your phone's camera is focusing correctly, and also make sure that the contrast on the two colors in your terminal is high enough. For example, WebStorm's default themes may [not have enough contrast](https://github.com/react-community/create-react-native-app/issues/49) for terminal QR codes to be scannable with the system barcode scanners that the Expo app uses. 200 | 201 | If this causes problems for you, you may want to try changing your terminal's color theme to have more contrast, or running Create React Native App from a different terminal. You can also manually enter the URL printed by the packager script in the Expo app's search bar to load it manually. 202 | -------------------------------------------------------------------------------- /examples/complex-react-nav-with-guest-access/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "expo": { 3 | "sdkVersion": "27.0.0" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /examples/complex-react-nav-with-guest-access/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ComplexReactNavWithGuestAccess", 3 | "version": "0.1.0", 4 | "private": true, 5 | "devDependencies": { 6 | "jest-expo": "~27.0.0", 7 | "react-native-scripts": "1.14.0", 8 | "react-test-renderer": "16.3.1" 9 | }, 10 | "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js", 11 | "scripts": { 12 | "start": "react-native-scripts start", 13 | "eject": "react-native-scripts eject", 14 | "android": "react-native-scripts android", 15 | "ios": "react-native-scripts ios", 16 | "test": "jest" 17 | }, 18 | "jest": { 19 | "preset": "jest-expo" 20 | }, 21 | "dependencies": { 22 | "expo": "^27.0.1", 23 | "react": "16.3.1", 24 | "react-native": "~0.55.2", 25 | "react-navigation": "^2.14.0" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/complex-react-nav-with-guest-access/src/api/auth.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { AsyncStorage } from 'react-native'; 3 | 4 | const defaultState = { 5 | checkedAuth: false, 6 | isLoggedIn: false, 7 | }; 8 | 9 | export const AUTH_KEY = 'auth-demo-key'; 10 | 11 | const AuthContext = React.createContext(defaultState); 12 | 13 | export const Consumer = AuthContext.Consumer; 14 | 15 | export class Provider extends React.Component { 16 | state = defaultState; 17 | 18 | componentDidMount() { 19 | AsyncStorage.getItem('authData') 20 | .then((state) => { 21 | this.setState({ 22 | ...JSON.parse(state), 23 | checkedAuth: true, 24 | }); 25 | }); 26 | } 27 | 28 | componentDidUpdate() { 29 | AsyncStorage.setItem('authData', JSON.stringify({ ...this.state, checkedAuth: false })); 30 | } 31 | 32 | createAccount = () => { 33 | this.setState({ isLoggedIn: true, checkedAuth: true }); 34 | }; 35 | 36 | logIn = () => { 37 | this.setState({ isLoggedIn: true, checkedAuth: true }); 38 | } 39 | 40 | logOut = () => { 41 | this.setState({ ...defaultState, checkedAuth: true }); 42 | } 43 | 44 | render() { 45 | return ( 46 | 54 | {this.props.children} 55 | 56 | ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /examples/complex-react-nav-with-guest-access/src/components/Button.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { StyleSheet, TouchableOpacity, Text } from 'react-native'; 3 | 4 | const styles = StyleSheet.create({ 5 | container: { 6 | backgroundColor: '#007991', 7 | marginVertical: 10, 8 | marginHorizontal: 15, 9 | borderRadius: 3, 10 | }, 11 | containerClear: { 12 | backgroundColor: 'transparent', 13 | marginVertical: 5, 14 | }, 15 | text: { 16 | textAlign: 'center', 17 | color: 'rgba(255, 255, 255, 0.9)', 18 | fontWeight: '600', 19 | fontSize: 16, 20 | padding: 15, 21 | }, 22 | textClear: { 23 | color: '#007991', 24 | paddingVertical: 5, 25 | }, 26 | }); 27 | 28 | class Btn extends React.Component { 29 | static defaultProps = { 30 | theme: 'default', 31 | }; 32 | 33 | render() { 34 | const { onPress, text, theme } = this.props; 35 | const containerStyles = [styles.container]; 36 | const textStyles = [styles.text]; 37 | 38 | if (theme === 'clear') { 39 | containerStyles.push(styles.containerClear); 40 | textStyles.push(styles.textClear); 41 | } 42 | 43 | return ( 44 | 45 | {text} 46 | 47 | ); 48 | } 49 | } 50 | 51 | export default Btn; 52 | -------------------------------------------------------------------------------- /examples/complex-react-nav-with-guest-access/src/components/Input.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | Text, 4 | View, 5 | TextInput, 6 | StyleSheet, 7 | } from 'react-native'; 8 | 9 | const styles = StyleSheet.create({ 10 | label: { 11 | color: '#98989d', 12 | paddingHorizontal: 20, 13 | marginBottom: 5, 14 | marginTop: 10, 15 | fontSize: 16, 16 | }, 17 | inputContainer: { 18 | backgroundColor: '#fff', 19 | paddingHorizontal: 20, 20 | }, 21 | input: { 22 | fontSize: 16, 23 | paddingVertical: 10, 24 | }, 25 | }); 26 | 27 | class Input extends React.Component { 28 | render() { 29 | const { label, ...props } = this.props; 30 | return ( 31 | 32 | {label} 33 | 34 | 38 | 39 | 40 | ); 41 | } 42 | } 43 | 44 | export default Input; 45 | -------------------------------------------------------------------------------- /examples/complex-react-nav-with-guest-access/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Router from './router'; 3 | import * as Auth from './api/auth'; 4 | 5 | class App extends React.Component { 6 | render() { 7 | return ( 8 | 9 | 10 | 11 | ); 12 | } 13 | } 14 | 15 | export default App; 16 | -------------------------------------------------------------------------------- /examples/complex-react-nav-with-guest-access/src/router.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | createBottomTabNavigator, 4 | createSwitchNavigator, 5 | createStackNavigator, 6 | } from 'react-navigation'; 7 | 8 | import Feed from './screens/Feed'; 9 | import Loading from './screens/Loading'; 10 | import Profile from './screens/Profile'; 11 | import SignIn from './screens/SignIn'; 12 | import SignUp from './screens/SignUp'; 13 | 14 | // Logged In 15 | const FeedStack = createStackNavigator({ 16 | Feed: { 17 | screen: Feed, 18 | navigationOptions: { 19 | headerTitle: 'Feed', 20 | }, 21 | }, 22 | }); 23 | 24 | const ProfileStack = createStackNavigator({ 25 | Profile: { 26 | screen: Profile, 27 | navigationOptions: { 28 | headerTitle: 'Profile', 29 | }, 30 | }, 31 | }); 32 | 33 | const AppTabs = createBottomTabNavigator({ 34 | Feed: { 35 | screen: FeedStack, 36 | }, 37 | Profile: { 38 | screen: ProfileStack, 39 | }, 40 | }); 41 | 42 | const InAppAuthStack = createStackNavigator({ 43 | SignIn: { 44 | screen: props => , 45 | navigationOptions: { 46 | headerTitle: 'Sign In', 47 | }, 48 | }, 49 | SignUp: { 50 | screen: props => , 51 | navigationOptions: { 52 | headerTitle: 'Sign Up', 53 | }, 54 | }, 55 | }); 56 | 57 | const AppStack = createStackNavigator({ 58 | Tabs: { 59 | screen: AppTabs, 60 | }, 61 | InAppAuth: { 62 | screen: InAppAuthStack, 63 | }, 64 | }, { 65 | headerMode: 'none', 66 | mode: 'modal', 67 | }); 68 | 69 | // Logged Out 70 | const AuthStack = createStackNavigator({ 71 | SignIn: { 72 | screen: SignIn, 73 | navigationOptions: { 74 | headerTitle: 'Sign In', 75 | }, 76 | }, 77 | SignUp: { 78 | screen: SignUp, 79 | navigationOptions: { 80 | headerTitle: 'Sign Up', 81 | }, 82 | }, 83 | }); 84 | 85 | // Main Navigator 86 | const AppNavigator = createSwitchNavigator({ 87 | Loading: { 88 | screen: Loading, 89 | }, 90 | LoggedOut: { 91 | screen: AuthStack, 92 | }, 93 | App: { 94 | screen: AppStack, 95 | }, 96 | }); 97 | 98 | export default AppNavigator; 99 | -------------------------------------------------------------------------------- /examples/complex-react-nav-with-guest-access/src/screens/Feed.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { View } from 'react-native'; 3 | 4 | import * as Auth from '../api/auth'; 5 | import Button from '../components/Button'; 6 | 7 | class Feed extends React.Component { 8 | handleProtectedAction = () => { 9 | const { isLoggedIn } = this.props; 10 | 11 | if (isLoggedIn) { 12 | alert('Authorized! Doing a protected thing.'); 13 | } else { 14 | this.props.navigation.navigate('InAppAuth'); 15 | } 16 | } 17 | 18 | render() { 19 | return ( 20 | 21 |