Wednesday, June 19, 2019

Ways to create React Native hybrid project

Option 1:
The most basic way to create React Native project is using react native cli. React Native CLI can be installed with below command
npm i -g react-native-cli
you can also check the version of installed React Native CLI with below command
react-native -v 

You can create a react native project with the below command
react-native init myReactNativeProj

Once the command is finished, you can see the generated React Native project includes the subfolders containing xcode project and android studio project, so the xcode and android studio projects will be used to run and test the project on device in the same way as ordinary native projects. That is way the React Native project created by react-native command requires the native developing environment installed on your local box.

Option 2:
The second option to create React Native project is using create-react-native-app tool. When using this tool, it is assumed that the project will be implemented with pure javascript without the need to link to any custom native libraries. So there is no need to install xcode or android studio on your development box to developing the react native project. In order to run and test the project,  the device must install a client side application Expo. The javascript code will be sent to Expo, and Expo will load and parse the javascript code and translate them into native UI controls as well as the related logic. Create-react-native-app tool is the result of the joint effort between React Native and Expo teams


The create-react-native-app tool can be installed with the below command
npm i -g create-react-native-app

You can check the installed create-react-native-app version with the below command

create-react-native-app --version

You can create a react native with this option using the below command. The command may ask you to install Expo CLI, when asked, select Yes to install id.
create-react-native-app mySecondApp

After the project is created, you can see the project root directory only contains javascript code, and does not contain the ios or android subfolders as option 1 does.

The advantage of this option is, you do not need to install platform specific development environment in your local box for developing and testing react native project on real device. But the limitation is, you cannot link any native libraries into the project. Note, the local development environment is still needed if you want to test the app on simulator.

You can test the project by running the below command from project's root folder. This will show a QR code and related instruction on both console window and a new browser window.
npm start

To run the app on real device, first install Expo client app on device. Then, for iOS, open camera app to scan the QR code.  For android, open Expo app to scan the QR code. The QR code contains the custom scheme of Expo app as below sample
exp://192.168.2.20/19000

To run the app on simulator, you will need have xcode or android studio from the desktop browser, click the related link, it will automatically start the simulator and install Expo client app.

Actually, as an extension of option 2, Expo SDK can also be used to create react native app.  Expo Framework provides addition mobile features to React Native, so these features can be easily integrated in React Native projects. 


Debug javascript code on real device
In order to debug the javascript code on real device, just shake the device to bring in the debug menu on device, and then clicks "Debug Remote JS" menu item. You can also click "Toggle Element Inspect" to check element information on device.  However, to check the element information, it is better to install react dev tool with below command
npm install -g react-devtools

After installing, run the below command will start a React's Electron debugger.

4 comments:

  1. Hey! This is my first visit to your blog! We are
    a collection of volunteers and starting
    a new project in a community in the same niche. Your blog provided us beneficial information to work on. You have done a marvellous job!

    React Native Development Company
    Reactjs Development Company Texas

    ReplyDelete
  2. In this present era of digitalization, a mobile application is one of the primary necessities for today’s modern-age businesses to stand-out in the industry, including even the top Indian app developers of the market are swapping towards mobile applications rather than the ordinary websites. The applications developed through cross-platform are apparently becoming more prevalent in the market, and React Native is one of the most preferred cross-platform development solutions by the developers as it allows them to preserves native platform compatibilities through react development.

    ReplyDelete
  3. Are you looking for React Native Development Service or want to grow your existing team of experts to create multi-platform User Interfaces for both iOS & Android? React-Native is the most preferred JavaScript framework for building cross-platform application development. To Hire React Native Developer who will deliver the most value to your app development team, you should be prepared to recognize whether they maintain the needed skills, both professional and interpersonal.

    Full Stack Developer has the extensive understanding and experience necessary to create full-fledged applications for your business. Get the best Full Stack services at affordable rates summing up with all your ideas. Hire Full Stack Programmers who are well-versed with a broad range of services including PHP, MEAN Stack, Node, Angular, Ruby on Rails, ReactJS, Laravel, VueJS, and others.

    ReplyDelete
  4. Best Web Design Company in Lebanon delivers stunning and functional websites that resonate with the people interacting with them. They will discover the tiered content support levels by following the process and including it in the website design. Their motive is the global growth in the web development domain by rendering effective services and solutions.

    ReplyDelete