Category Archives: React native Tutorial

React native Tutorial

React Native Hello World Application

React Native Hello World Application

We will start learning React Native by creating a simple “Hello world!” application. The “Hello world!” application is a simple yet complete example for beginners that illustrates the basics of React native. The “Hello world!” application will also gives you a way to test systems and development environment. This tutorial will guide you through writing a simple “Hello World!” application in React Native.

In order to start with this tutorial, you must have React Native and React Native CLI installed, so if you don’t have it installed, follow React Native Installation to have it installed.

Installing React Native CLI

To start quickly, you must have installed the React Native CLI utility which lets you setup your project quickly. Let’s open the terminal and use the following command to get React Native CLI installed.

Create Hello World Project with React Native

Step 1:- Start your Android Emulator and make it live to view the output.

Step 2:- Let’s open the terminal and switch to the project folder and type the following command to initialize a HelloWorld application.

Step 3:- Now, switch to the newly created project directory and run the following command to start the server and launch application on your preferred device/emulator. Since I want to launch it on an Android Device I will use the following command.

If you are on a Mac device and you can use following command.

Since you are running any of the above command for the first time, it takes some time for the app show up in an emulator. If everything runs successfully, you will see the following out in your emulator.

Output 1:-

react-native-hello-world-application-1

Step 4:- Now, when you go to the project folder you will see the following directory structure.

react-native-project-directory-structure

Step 5:- Lets open App.js file in editor of your choice, you will see following lines of code in it.

Step 6:- Now, replace the lines of code in App.js file with following lines of code.

Now, save the file and on reload of application you will see following output –

Output 2:-

react-native-hello-world-application-2

Step 7:- Now, we will add some styling to text. Replace the lines of code in App.js file we just updated with following lines of code.

Now, save the file and on reload of application you will see following output –

Output 3:-

react-native-hello-world-application-3

Lets understand the App.js code line by line –

import React, {Component} from ‘react’:- This is an import statement that imports required component module from the react library and then assign it to React variable.

const instruction: sets to display the platform-specific message.

export default class App extends Component: It defines the default App class that extend the React Component.

render(): It is a function that returns a React element.

return(): This returns the result of layout and UI components.

View: It is the root element container that is used for building the UI.

Text: React element used for displaying text.

style: This is used define a stylesheet or styling classes for components.

styles: It is used to for styling an individual components.

{styles.instructions}>{instructions}:

const styles = StyleSheet.create({}): The StyleSheet class creates the style object that controls the layout and styling of components.

React Native Features

React Native Features

Building a cross platform mobile applications using React native comes several features. Some of them are listed below –

JavaScript :- React Native lets you build fully native mobile application using JavaScript.

Cross-Platform :- React Native lets you write cross-platform native applications using JavaScript in a single codebase for both Android and iOS, later then Javascript is compiled to native code.

Community :- React Native is backed with a large community of React and React Native developers. So it is easy to find help if you stuck at some point while developing an application.

Development Time :- It saves development time required in building mobile applications for multiple platforms.

Cost Effective :- It reduces the cost to build mobile apps for multiple platforms.

Hot Reloading :- One of the biggest frustrations as mobile application developer you have probably faced is constant recompiling of project. Whenever you make a small change you need to recompile the project completely to check your changes in effect. React Native fixed this problem by taking the advantage of Hot Reload feature that allows developers to view changes live as they make them.

Single Codebase :- This is one of the most appealing feature of React Native which lets you write a cross-platform mobile application using JavaScript in a single codebase for both Android and iOS. React Native provides a virtual DOM that renders platform specific components behind the scenes.

Simple User Interface :- React Native offers much more simplified responsive User Interface and reduces the loading time as well.

Stable Apps :- In React Native, the process of data binding is simplified and child components does not have any dependencies on the parent data which makes application more stable and increased level of reliability. In React Native, only permitted components are allowed to be updated when any modification or update is made in application.

Modular Architecture :- React Native follows the modular programming, which allows us to split the application into independent reusable components/module. Module is simply an independent, fully functional and reusable piece of code which usually contains Javascript code.

Third-Party Plugin Support :- React Native offers the support for third-party plugins including native modules and JavaScript modules that is not part of core React Native framework.

React Native History

React Native History

2013 :- In Summer 2013, React Native is started as facebook’s Internal Hackathon Project.

2015 :- In January 2015 at React.js con React native had its first public preview later in March 2015, Facebook announced React Native as open-source and available on GitHub.

2016 :- In September 2016, Facebook launched it’s open-source UI toolkit for React Native.

Initially React Native was developed for the iOS application but later it also added the support for Android operating system.

React Native Introduction

React Native Introduction

React Native is a cross-platform mobile application development framework that lets you build native iOS and Android mobile applications. It is basically a JavaScript framework used to build a mobile application. React Native is similar to React, but it uses native component instead of using web components as it’s building blocks.

How React Native Is Different ?

There are already hybrid and cross-platform mobile application development framework available such as Ionic, Phone Gap, Titanium and Xamarin etc. All of these framework lets you create applications using web technologies and the application runs over a WebView component.

In React Native, you build the real mobile applications that is not different in any way from the application you created using native programming languages such as Objective C and Java. React Native lets you write native applications using JavaScript in a single codebase for both Android and iOS, later then Javascript is compiled to native code. It uses the same platform specific fundamental UI components such as sliders, switches, labels, and tab bars that gives users seamless experience.

React Native Advantages

Building a mobile applications using React native comes several advantages. Some of them are listed below –

JavaScript :- React Native lets you build fully native mobile application using JavaScript.

Cross-Platform :- React Native lets you write cross-platform native applications using JavaScript in a single codebase for both Android and iOS, later then Javascript is compiled to native code.

Community :- React Native is backed with a large community of React and React Native developers. So it is easy to find help if you stuck at some point while developing an application.

Development Time :- It saves development time required in building mobile applications for multiple platforms.

Cost Effective :- It reduces the cost to build mobile apps for multiple platforms.