Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "native" and what is not in a React Native project?

I'm still very confused on how React Native works. Maybe because I don't have a decent background on Mobile Development (I have tried native Android once or twice though).

If I'm not wrong, hybrid frameworks like Phonegap or Ionic will run the entire project (or most of it) in a 'WebView', am I wrong?

Whereas native frameworks such as React Native is meant to use native resources instead of purely web technology.

But we still write Javascript, and React Native does the job so quickly that it is probably still using the Javascript we just wrote (I mean, it's not parsing, translating to native code and recompiling).

The question that comes to my mind is, what exactly is a native resource and what is not in a React Native project? Where is the Javascript we write running if not in a 'webview'? There are native libraries that creates the interface of Javascript to Objective-C and Java for both platforms? In a web-solution it simply injects the entire code in the WebView?

Extra question : can we consider React Native an hybrid framework just because we write one code for many different platforms, or it is not the correct terminology?

like image 620
Victor Ferreira Avatar asked Jan 23 '17 19:01

Victor Ferreira


People also ask

What is the difference between React Native and native?

Comparing React Native vs Traditional Native AppsReact Native is written primarily with JavaScript and classified as a “hybrid” framework, meaning that it's platform-independent. This separates it from traditional apps written in native languages such as Java or Kotlin for Android, and Swift or Objective-C for Apple.

What does Native mean in React Native?

The term native refers to an app that is created for a specific operating system, platform or device. React Native was created out of Facebook's need to rely less on HTML and more on native code. It was born from a prototype that could generate UI elements from a background JavaScript thread.

Why React Native is not native?

It happens all the time, but it's optimize to a way, that application will run smoothly in 60fps. So to summarize React Native is not really a Native framework, but It's much closer to Native code, than hybrid apps. And now let's dive a bit deeper and understand how JavaScript gets converted into a Native code.

What is React Native?

React Native (also known as RN) is a popular JavaScript-based mobile app framework that allows you to build natively-rendered mobile apps for iOS and Android. The framework lets you create an application for various platforms by using the same codebase.


1 Answers

If I'm not wrong, hybrid frameworks like Phonegap or Ionic will run the entire project (or most of it) in a 'WebView', am I wrong?

Yes. Phonegap and Ionic, which uses PhoneGap (actually Cordova) as part of the framework make use of HTML, CSS and JavaScript to render the UI. The only connection (as far as I know) outside of that is the access that Cordova provides to the native APIs of the device (think sensors, for instance).

Whereas native frameworks such as React Native is meant to use native resources instead of purely web technology.

Yes, the approach of RN is to enable developers to use JavaScript and the React framework while retaining the benefits of native development (performance, feel-and-look, etc).

But we still write Javascript, and React Native does the job so quickly that it is probably still using the Javascript we just wrote (I mean, it's not parsing, translating to native code and recompiling).

Here is where I think your misunderstanding lies: you have to think of React Native as a 'bridge' between a native application that still relies on the iOS/Android/Windows native APIs and a JavaScript piece of code. The bridge grants JS access to such APIs, and cares about rendering the UI and other different native aspects, as well as providing data in the opposite direction (from Native to JS). The JS code is never 'converted' to say Java or Swift/Obj-C. It is executed in the same way you program it. However, you have the possibility of asking RN to use some native component from JavaScript (say, a <Text> will instantiate a UILabel in iOS)). The library then implements this approach with a handful of components, like layouts, views, controls and so on, but the essentials remain as described.

The question that comes to my mind is, what exactly is a native resource and what is not in a React Native project?

So... basically, anything that is written in JavaScript will not be native, but through its execution you get native components. Anything that you program using the native API directly (that is one of the strengths of RN, that you can still develop natively if you feel up to it or a certain native component is not implemented in the library) can be considered 'native'.

Where is the Javascript we write running if not in a 'webview'? There are native libraries that creates the interface of Javascript to Objective-C and Java for both platforms?

As explained before, the React Native is the interface between JS and Objective-C. The JavaScript is not rendered in a WebView at any time.

In a web-solution it simply injects the entire code in the WebView?

React Native is not meant for the web... unless you use this.

Extra question : can we consider React Native an hybrid framework just because we write one code for many different platforms, or it is not the correct terminology?

Well... I'd say that a hybrid framework is a tool that combines different development resources (say web technologies and native APIs). In that case, React Native would fall in the category. I would not call it hybrid just because it works in several platforms (that I would simply call multi-platform).

like image 74
martinarroyo Avatar answered Sep 19 '22 12:09

martinarroyo