img

How does react native work?

15 Dec 2020

Cre­at­ed by Face­book, react native is a mobile app frame­work based on Java-script that was released in 2015 and soon became one of the most promi­nent plat­forms for mobile devel­op­ment. React derives from facebook’s Javascript library for build­ing user inter­faces but does not tar­get the brows­er. It uses an alter­nate approach of tar­get­ing the mobile plat­form. Devel­op­ers who are experts in Javascript will find immense sup­port with react native as they don’t need to learn specif­i­cal­ly Swift for ios or Java for Android.

One of the rea­sons for its suc­cess is its ver­sa­til­i­ty – the apps can run on ios and android with the same code, and the devel­op­er only needs to code once. React Native has com­po­nents of both ios and android, and since it has coun­ter­part rights, Com­po­nents can be used and reused across both plat­forms. As it can serve both ios and android simul­ta­ne­ous­ly, react-native has found great pop­u­lar­i­ty among major com­pa­nies like Face­book, Insta­gram, Wal­mart, Tes­la, Bloomberg, and Airbnb along with many oth­er major play­ers across indus­tries. Addi­tion­al­ly, the choice is no longer lim­it­ed to the tar­get­ing of either ios users (which give more prof­it but are few­er in num­bers) or android  (which has a wider user base than Ios)

How React Native per­forms Vs Flutter:

Flut­ter was intro­duced by google where­as react-native was a face­books cre­ation. React Native uses JavaScript, web development’s most pop­u­lar lan­guage. This makes the build­ing of mobile apps rel­a­tive­ly eas­i­er espe­cial­ly for some­one famil­iar with JavaScript. Flut­ter on the oth­er hand uses Dart which is rarely used out­side Google. This dis­ad­van­tage is mit­i­gat­ed by the fact that Dart is very sim­i­lar to JavaScript which makes it eas­i­er for some­one who knows JS to adapt to Dart.

Under­stand­ably, the mania or craze for using React Native is ris­ing every day, and under­stand­ing how it works under the roof is quite inter­est­ing. Let’s first take a quick tour of What React Native is?

What is React- how it functions?

React Native is the sim­plest extract from the  JavaScript library for cre­at­ing user inter­faces. A key ele­ment when we talk about React is that of a com­po­nent. What is a Com­po­nent? One of the spe­cif­ic parts of the user inter­face, such as the input field in apps.

What does a UI com­po­nent code look like?

ren­der() {

return <WriteCom­ment />;

}

You may use the com­po­nents used in React repeat­ed­ly as they are com­pos­able in nature. Note: A com­po­nent is made of sim­i­lar com­po­nents and prim­i­tives –since we are refer­ring to chiefly web components,lets explain it bet­ter using HTML ele­ments {div /span}

ren­der() {

return (

<div>

<Pro­filePic­ture />

<Com­mentIn­put />

</div>

);

}

React is an intel­li­gent dis­cov­ery, it iden­ti­fied the com­po­nents that are required to be reworked, and ren­dered tru­ly on the var­i­ous changes in data –this prop­er­ty makes it quick­er while respond­ing and hence the pre­ferred option for app devel­op­ment on the web.

React native app devel­op­ers must note that React is not restrict­ed to the DOM [Doc­u­ment object mod­el ] You are free to build any oth­er type of user inter­face such as the mobile apps using React.

Work­ing on React Native;

If you ask the Top React Native app devel­op­er you will be able to under­stand what runs behind are the two key threads in each React Native appli­ca­tion, the first one is the pri­ma­ry thread, that runs in each stan­dard native app and man­ages the dis­play of ele­ments of the user-inter­face and the process­es user’s actions.

The next one is one that is relat­ed to React Native and its task to ini­tial­ize the JavaScript codes in a seclud­ed JavaScript engine. This script then deals with the busi­ness log­ic of the appli­ca­tion used, and smart­ly defines the over­all struc­ture and func­tion­al­i­ties of the user. These two threads men­tioned above nev­er obstruct each oth­er nor com­mu­ni­cates directly.

Under­stand­ing the inter­ac­tion of threads

A bridge that of course is the core of React Native is enabled to keep the two threads intact, so they do not block each other.

The bridge has three char­ac­ter­is­tics, and they are list­ed below in ran­dom sequence:

Seri­al­ize – Both the threads are cre­at­ed in a way that they do not func­tion or oper­ate with the same data, their task is to seri­al­ize messages.

Batched – As the name sug­gests, this helps trans­fer the mes­sage from one thread to anoth­er in an orga­nized and opti­mized manner.

Asyn­chro­nous – This pro­vides asyn­chro­nous com­mu­ni­ca­tion between the first and the sec­ond thread with the pur­pose of nev­er block­ing each other.

The React Native architecture

A glimpse of the Devel­op­ment process

After read­ing and re-read­ing the basics of React Native struc­ture, it is inter­est­ing to take a quick glimpse of the devel­op­ment process.

Open the edi­tor, and check with the first com­po­nent eg. Greet­ing, which will appear as Hel­lo or Hi.

A glimpse of the Development process

One of the most basic React Native component

most basic React Native component

To start the iOS appli­ca­tion, first and fore­most exe­cute by start­ing react-native run-Android from the com­mand text. React Native app devel­op­ers build an app that will com­mence on a dum­my sim­u­la­tor or you may also check it on a real device, in case you have one con­nect­ed to the computer.

Read also about How many types of nav­i­ga­tion in react native

Sim­ple Android app

In case you would like to say Hi’ and not Hel­lo, all you need to do is open the edi­tor and edit the text from Hel­lo to Hi. Post that press com­mand +R on the sim­u­la­tor, and same as we refresh a page, the changes or amend­ments will fea­ture on the screen.

This oth­er­wise takes a long time, but our React native app devel­op­ers can cre­ate this with­in min­utes and offer an express experience.

Simple Android app

When we work with Android apps, we exe­cute run- native  run0 Android – the greet­ing ele­ment in the form of the com­po­nent may be used again as the code if free of and bind­ing plat­form-spe­cif­ic tools or codes.

Most of the time React Native will offer Android Textview in place of iOS UIv­iew, the pro­vi­sion for reusing code is the most per­ti­nent side of this smart tech­nol­o­gy. Most the Android app, which uti­lizes the same Greet­ing” com­po­nent enjoys sim­i­lar benefits.

The most engag­ing fea­ture of React Native is the way one can debug our appli­ca­tion, right from the device’s menu-one can opt to’ Debug JavaScript exter­nal­ly using remote service”.One can access Google Chrome and run JS and avoid run­ning it on the device. You will be sur­prised to see React Native set­ting up with a web sock­et that links the device with the brows­er. You will real­ize React  Native devel­op­ers find debug­ging easy – try it for yourself.

Frequently Asked Questions

Share this post :