Friday, November 23, 2018

REACT NATIVE OVERVIEW

REACT NATIVE OVERVIEW
Image result for OVERVIEW
Image result for OVERVIEW ANIMATED ICON 

For better understanding of React Native concepts, we will borrow a few lines from the official documentation −
React Native lets you build mobile apps using only JavaScript. It uses the same design as React, letting you compose a rich mobile UI from declarative components. 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.

React Native Features



Following are the features of React Native −
  • React − This is a Framework for building web and mobile apps using JavaScript.
  • Native − You can use native components controlled by JavaScript.
  • Platforms − React Native supports IOS and Android platform.

React Native Advantages

Follow are the advantages of React Native −
  • JavaScript − You can use the existing JavaScript knowledge to build native mobile apps.
  • Code sharing − You can share most of your code on different platforms.
  • Community − The community around React and React Native is large, and you will be able to find any answer you need.

React Native Limitations

Following are the limitations of React Native −
  • Native Components − If you want to create native functionality which is not created yet, you will need to write some platform specific code.

Continue reading

REACT NATIVE ENVIRONMENT SETUP

REACT NATIVE ENVIRONMENT SETUP
Image result for ENVIRONMENT SETUP

There are a couple of things you need to install to set up the environment for React Native. We will use OSX as our building platform.
Sr.No.SoftwareDescription
1NodeJS and NPMYou can follow our NodeJS Environment Setup tutorial to install NodeJS.

Step 1: Install create-react-native-app

After installing NodeJS and NPM successfully in your system you can proceed with installation of create-react-native-app (globally as shown below).
C:\Users\Tutorialspoint> npm install -g create-react-native-app

Step 2: Create project

Browse through required folder and create a new react native project as shown below.
C:\Users\Tutorialspoint>cd Desktop
C:\Users\Tutorialspoint\Desktop>create-react-native-app MyReactNative
After executing the above command, a folder with specifies name is created with the following contents.
Environment Project

Step 3: NodeJS Python Jdk8

Make sure you have Python NodeJS and jdk8 installed in your system if not, install them. In addition to these it is recommended to install latest version of yarn to avoid certain issues.

Step 4: Install React Native CLI

You can install react native command line interface on npm, using the install -g react-native-cli command as shown below.
npm install -g react-native-cli
Environment Commandline

Step 5: Start react native

To verify the installation browse through the project folder and try starting the project using the start command.
C:\Users\Tutorialspoint\Desktop>cd MyReactNative
C:\Users\Tutorialspoint\Desktop\MyReactNative>npm start
If everything went well you will get a QR code as shown below.
Environment Package installer
As instructed, one way to run react native apps on your android devise is to using expo. Install expo client in your android devise and scan the above obtained QR code.

Step 6: Eject the project

If you want to run android emulator using android studio, come out of the current command line by pressing ctrl+c.
Then, execute run eject command as
npm run eject
This prompts you options to eject, select the first one using arrows and press enter.
Environment Eject Command
Then, you should suggest the name of the app on home screen and project name of the Android studio and Xcode projects.
Environment Eject Command Questions
Though your project ejected successfully, you may get an error as −
Environment Eject Error
Ignore this error and run react native for android using the following command −
react-native run-android
But, before that you need to install android studio.

Step 7: Installing Android Studio

Visit the web page https://developer.android.com/studio/ and download android studio.
Environment Android Studio
After downloading the installation file of it, double click on it and proceed with the installation.
Environment Android Studio3

Step 8: Configuring AVD Manager

To configure the AVD Manager click on the respective icon in the menu bar.
Configuring AVD Manager

Step 9: Configuring AVD Manager

Choose a device definition, Nexus 5X is suggestable.
Choose Device Definition
Click on the Next button you will see a System Image window. Select the x86 Images tab.
System Image
Then, select Marshmallow and click on next.
Select System Image
Finally, click on the Finish button to finish the AVD configuration.
Verify Configuration
After configuring your virtual device click on the play button under the Actions column to start your android emulator.
Your Virtual Devices

Step 10: Running android

Open command prompt, browse through your project folder and, execute the react-native run-android command.
Running Android
Then, your app execution begins in another prompt you can see its status.
Execution Status
In your android emulator you can see the execution of the default app as −
React Native Default App

Step 11: local.properties

Open the android folder in your project folder SampleReactNative/android(in this case). Create a file with named local.properties and add the following path in it.
sdk.dir = /C:\\Users\\Tutorialspoint\\AppData\\Local\\Android\\Sdk
here, replace Tutorialspoint with your user name.

Step 12: Hot Reloading

And to build application modify the App.js and the changes will be automatically updated on the android emulator.
If not, click on the android emulator press ctrl+m then, select Enable Hot Reloading option.
Environment Hot Reloading

Continue reading

REACT NATIVE APP

REACT NATIVE APP
If you open the default app you can observe that the app.js file looks like
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default class App extends React.Component {
   render() {
      return (
         <View style = {styles.container}>
            <Text>Open up App.js to start working on your app!</Text>
            <Text>Changes you make will automatically reload.</Text>
            <Text>Shake your phone to open the developer menu.</Text>
         </View>
      );
   }
}

const styles = StyleSheet.create({
   container: {
      flex: 1,
      backgroundColor: '#fff',
      alignItems: 'center',
      justifyContent: 'center',
   },
});

Output

Working on App

Hello world

To display a simple message saying “Welcome to Tutorialspoint” remove the CSS part and insert the message to be printed wrapped by the <text></text> tags inside <view></view> as shown below.
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default class App extends React.Component {
   render() {
      return (
         <View>
            <Text>Welcome to Tutorialspoint</Text>
         </View>
      );
   }
}
Hello World

Continue reading

STATES

STATES
Image result for REACT NATIVE STATE


The data inside React Components is managed by state and props. In this chapter, we will talk about state.

Difference between State and Props

The state is mutable while props are immutable. This means that state can be updated in the future while props cannot be updated.

Using State

This is our root component. We are just importing Home which will be used in most of the chapters.
App.js
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default class App extends React.Component {
   state = {
      myState: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, used do eiusmod
      tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
      nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
      Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
      fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
      culpa qui officia deserunt mollit anim id est laborum.'
   }
   render() {
      return (
      <View>
         <Text> {this.state.myState} </Text>
      </View>
      );
   }
}
We can see in emulator text from the state as in the following screenshot.
React Native State

Updating State

Since state is mutable, we can update it by creating the deleteState function and call it using the onPress = {this.deleteText} event.
Home.js
import React, { Component } from 'react'
import { Text, View } from 'react-native'

class Home extends Component {
   state = {
      myState: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed 
         do eiusmod tempor incididunt ut labore et dolore magna aliqua.
         Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
         ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit 
         in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
         Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
         deserunt mollit anim id est laborum.'
   }
   updateState = ()  this.setState({ myState: 'The state is updated' })
   render() {
      return (
         <View>
            <Text onPress = {this.updateState}>
               {this.state.myState}
            </Text>
         </View>
      );
   }
}
export default Home;
NOTES − In all chapters, we will use the class syntax for stateful (container) components and function syntax for stateless (presentational) components. We will learn more about components in the next chapter.
We will also learn how to use the arrow function syntax for updateState. You should keep in mind that this syntax uses the lexical scope, and this keyword will be bound to the environment object (Class). This will sometimes lead to unexpected behavior.
The other way to define methods is to use the EC5 functions but in that case we will need to bind this manually in the constructor. Consider the following example to understand this.
class Home extends Component {
   constructor() {
      super()
      this.updateState = this.updateState.bind(this)
   }
   updateState() {
      //
   }
   render() {
      //
   }
Continue reading