React Native is a framework for building native apps using React made by Facebook. With React Native, you don’t build a “mobile web app”, an “HTML5 app”, or a “hybrid app”. You build a real mobile app that’s indistinguishable from an app built using Objective-C or Java. React Native uses the same fundamental UI building blocks as regular iOS and Android apps. You just put those building blocks together using JavaScript and React. – from

In the following lines we will take a short tour of React Native to help you familiarize with the platform and hopefully get you started in your React Native development career.

We will create a simple app called RandomNumbers that will pick some numbers from a pool, numbers that you can use later at anything you need (for example playing the lottery).

Install React Native

You will need to install Node, Watchman, the React Native command line interface, a JDK, and Xcode or Android Studio (or both). You can find details on how exactly do to this, depending on your platform, here: Select the “Building Projects with Native Code” tab and then follow the instructions.

When you’re done, create a new project with the react-native init RandomNumbers command then cd into the newly created RandomNumbers folder.

The above command created an empty React Native project that you can immediately run on your device using the react-native run-ios or react-native run-android commands (you need to have an Android emulator already started for the last command to work).

Make Your First Change

Open the RandomNumbers folder in an code editor of your choice. Here you will find some files and folders, the most important ones being the index.ios.js and files that contain our starting point of the app.

Edit one (or both) of the files above, depending on the platform you are testing, to the following:


Save the edited file, then, in the emulator, press Cmd+R to reload the app. It will refresh itself to reflect the changes, no recompiling needed. Isn’t this cool?

React Native Components

Just like in React, a React Native app is made up by several components that work together to achieve the ultimate goal of the app. To see the list of available components visit and scroll to the Components section in the left menu.

We will start by making the two React Native starting points (from the index.ios.js and files) to load a single component called App.

Create a new App.js file with the following content:

Now change the index.ios.js and to the following (both will have the same content):

We just removed everything from them and loaded the App component so we now have a common starting point for both platforms.

Generate a Random Number

Let’s add a Button that will trigger the number generator of our app. First import the Button component, then add the actual button to the render method (in App.js):

For this to work we need to define a new method generateRandomNumber:

Now if you click on the Generate! button, a random number between 0 and 100 will be generated and printed to the console.

To see the console output open the developer menu in your app by  pressing Cmd+D and select Debug JS Remotely. A new browser window will open and there you can check the console output like you normally do when developing for the web.

Output Data to the Screen

Now we have our generated random number, but how can we show it to the user? For this we will use the state concept of React. The are two fundamental concepts of React that you need to understand: the state and props.

There are two types of data that control a component: props and state. Props are set by the parent and they are fixed throughout the lifetime of a component. For data that is going to change, we have to use state.

You can read more about this topic here:

Start by creating a constructor for our App component that sets the initial state:

In the generateRandomNumber method, change the state to contain the newly generated number:

Finally add a new Text component in the render() method that will show the random number from the app’s state:

Now, every time you click the Generate! button a new random number will appear on the screen.

How Many Numbers?

What if you need more than one number, extracted from a pool of numbers?

To define the pool of numbers we will use a slider with values from 1 to 100. To define how many numbers do we need to be extracted from the pool, we will use a picker with values from 1 to 10. This way we can configure the app to do what we need at run-time.

Import the Slider component then add it to the app:

We need to show the current slider value to the user so we will add it to the state of our app:

When the slider moves, we have to update the state:

Add a new text component to show it to the user (and an informative label):

Now to select how many numbers we need, let’s try a picker:

For this we added amount to the state:

Now let’s change the generateRandomNumbers method to take in account the new settings:

What if you try to generate 10 numbers out of 5? Or something like this? We will have to tell the user that’s not possible using an alert.

That’s all we had to do for our app functionality. Try it!

… but, to be honest, it doesn’t look so good 🙁

Making the App Look Good

Let’s start by adding a nice background to our app. First download the image from here and save it to your project folder. Then replace the root <View> with an <Image> component (also be sure to include the Image component at the beginning of the file):

Update the container style to this:

Now, let’s take care of the button. We will remove the <Button> component because it’s not as customizable as we need and replace it with a <TouchableOpacity> (don’t forget to include this component too and remove the <Button> from the includes because we will not use it anymore). Also get the button background image from here.

Next we will use some styling for the rest of the components, here is all the render() code and styles:

You will also need the slider thumb images from here and here.

If you run the app now, you will find a much better interface:

The images used in this tutorial were downloaded from then edited using Photoshop:

Getting Your App Ready to Be Published

So our app is done, how do we publish it to the AppStore and Google Play Store?

First, let’s fix one small problem: if you rotate your emulator screen (Cmd+Left or Right Arrow) you will see that the app will go into landscape and it will not be usable anymore 🙁

Too lock the app to portrait we need to go “native”.

For iOS, open xCode then open the project found in the randomNumbers/ios folder. Select the project in the left pane then, under Deployment Info, uncheck Landscape Left and Landscape Right Device Orientation so we are only left with the Portrait orientation.

For Android, you can just open the android/app/src/AndroidManifest.xml and add android:screenOrientation="portrait" under the activity section:


Now, to see those changes, you have to relaunch the app again. Not just reload, relaunch with the react-native run-ios or react-native run-android commands and try to rotate the emulator. Everything should be fine this time.

Now back to our main task, getting the app ready to be published.


First let’s add the app’s icons. Open the xCode project and select Images.xcassets from the left panel. Then select the AppIcon item and drag each icon image to its corresponding placeholder. Download the icons from here.

When you’re done, select Product -> Archive from the menu to build the iOS package (it only works with a Generic iOS Device selected or a real device, no emulators).


To add app icons in Android, you have to put them in the android/app/src/main/res/mipmap* folders (overwrite the existing ic_launcher.png). You can get the icons from here.

Now you need to generate a signing key then a signed APK. I found the walkthrough from the React Native documentation to be pretty good so you just follow it:

Final Words

That’s it! You now have your first React Native application ready to be sent into the wild. I hope you had fun doing this, please let us know in the comments how it worked for you. Oh, and you can find the final code here.

Have a nice mobile developer life! 🙂