Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does React Native use to allow JavaScript to be executed on iOS and Android natively?

What does React Native use under the covers to interface with iOS and Android? Cordova uses a WebView to effectively display a webpage inside of a native container; Does React Native use the same approach? If not, What approach does it use?

like image 723
kharandziuk Avatar asked Nov 02 '15 13:11

kharandziuk


People also ask

How does React Native work on iOS and Android?

With React Native, developers can write real, natively rendering mobile applications for iOS and Android. It helps build apps on two platforms at once, while maintaining the look, feel, and productivity of an app built on the specific iOS or Android platform.

What JavaScript engine does React Native use on Android?

JavaScript Runtime​ When using React Native, you're going to be running your JavaScript code in two environments: In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari.

Is React Native used for both Android and iOS?

React Native combines the best parts of native development with React, a best-in-class JavaScript library for building user interfaces. Use a little—or a lot. You can use React Native today in your existing Android and iOS projects or you can create a whole new app from scratch.

Can you React Native to combine native codes of Android and iOS?

Yes, we can combine Android or iOS code in react native. React Native helps to smoothly combines the components written in Java, Objective-C or Swift.


2 Answers

As you noticed React Native is not based on Cordova. It is not a website which looks like an app shoveled into a WebView.

React Native uses a JavaScript runtime, but the UI is not HTML and it doesn't use a WebView. You use JSX and React Native specific components to define the UI.

It provides a native-level performance and look and feel but some UI parts have to be configured separately for iOS and Android. For example Toolbars are completely different, but TextInput can be the same for both Operating Systems.

like image 198
AMilassin Avatar answered Oct 04 '22 16:10

AMilassin


For new update refer @f4z3k4s answer.

React Native app comprises two parts: Native part and Javascript part.

To run Javascript

React Native uses JavaScriptCore (JavaScript engine in Safari) on Android/ iOS simulators and devices.

In case of Android, React Native bundles the JavaScriptCore along with the application.

In case of iOS, React Native uses the JavaScriptCore provided by the iOS platform.

To communicate Javascript with Native part

React Native bridge is used. It is a layer that is responsible for communication between the Native and Javascript thread. It is written in C++/Java.

Steps Involved

After developer runs react-native run-ios or react-native run-android

  1. React Native CLI spawns a node packager/bundler (metro) that would bundle the javascript code into a single main.bundle.js file.
  2. React Native CLI launches React Native app and at first loads the native entry point of the app.
  3. The Native thread spawns the JavascriptCore thread.
  4. The Native thread now sends messages via the RN Bridge to start the Javascript app.
  5. Javascript thread starts issuing instructions to the Native thread via the RN Bridge. The instructions include what views to load, what information is to be retrieved from the hardware, etc.
  6. The Native thread will perform these operations and send the result back to the Javascript thread assuring that the operations have been performed.

Source

like image 27
Sahil Raj Thapa Avatar answered Oct 04 '22 15:10

Sahil Raj Thapa