
Not so long ago, a
conference on React.js was held
in Kalyfroniya (reports from this conference have already been posted
on the facebook channel of developers on youtube ). The reports, as it is not difficult to guess, were about the various features of React.js and their application in real life, but two reports presented only a new technology, the beta version of which is currently available only to developers who attended the event. If you have already watched the reports, you understand that this is React Native. In this article, I want to make a brief overview of what awaits us in the future with this technology and how our idea of creating mobile applications using JavaScript will change.
What is React Native?
So let's see what React Native is and for what purpose, facebook engineers invented this technology. But before that, I want to ask you, what do you think about Apache Cordova? Slow? Is smooth UI a myth? Is it better to use WebView with strapping on JS? Yes, yes, it was so before the announcement of React Native. Imagine that in the next couple of months, a hybrid system will be released from facebook based on React.js and interacting with native elements of iOS / Android systems (i.e. not creating WebView, as PhoneGap does, but using embedded components that provide above platforms). This approach will allow developers already familiar with React.js to develop native applications in a similar manner.
React Native does not use either the browser or WebView - only the JavaScript API on top of the native components. Let me explain how it works: you write JavaScript code (IMHO, most likely it will be JSX code), and it works with the native components of the operating system for which you are developing, thereby transferring the advantages and usability of React.js from the browser to mobile applications . Unlike the same PhoneGap, which, when a native event occurs, blocks the flow and transfers control to the JS code, waiting for its instructions (in fact, you can observe lags because of this), React Native runs JS in a separate background thread, interacting with the main thread is asynchronous, i.e. In the JS stream, a series of commands are collected to the main thread and at a certain point in time, a grouped request (batch request) is sent, thereby not blocking the main program execution flow (how it works in real life
can be viewed here or
you can download the facebook groups application will appear in the AppStore).
What about styles?
Here we must immediately say that facebook did not stop using HTML-like syntax in JS (X) files, and the next solution was to use CSS object notation (akin to the one that can be used in browsers) within mobile applications. This gives a number of undeniable advantages, for example, you can calculate the quantitative properties of elements (such as color, thickness, size, etc.) right on the fly during program execution and encapsulate styles on a level with your components. It looks like this:
')
var styles = { textStyle: { color: 'yellow', fontSize: 14 } }; React.render(<Text style={styles.textStyle}>Test</Text>, document.body);
As you can see,
<Text/> . iOS Android . JSX ( , JSX).
, React Native "Write once, run anywhere" ( , ), "Learn once, write anywhere" ( , ).
:
React.js Conf 2015 Keynote - Introducing React Native ( React Native) React.js Conf 2015 Keynote 2 - A Deep Dive into React Native ( React Native)
instead of the usual one
<Text/>
. iOS Android . JSX ( , JSX).
, React Native "Write once, run anywhere" ( , ), "Learn once, write anywhere" ( , ).
:
React.js Conf 2015 Keynote - Introducing React Native ( React Native) React.js Conf 2015 Keynote 2 - A Deep Dive into React Native ( React Native)
<Text/>
. iOS Android . JSX ( , JSX).
, React Native "Write once, run anywhere" ( , ), "Learn once, write anywhere" ( , ).
:
React.js Conf 2015 Keynote - Introducing React Native ( React Native) React.js Conf 2015 Keynote 2 - A Deep Dive into React Native ( React Native)
<Text/>
. iOS Android . JSX ( , JSX).
, React Native "Write once, run anywhere" ( , ), "Learn once, write anywhere" ( , ).
:
React.js Conf 2015 Keynote - Introducing React Native ( React Native) React.js Conf 2015 Keynote 2 - A Deep Dive into React Native ( React Native)
<Text/>
. iOS Android . JSX ( , JSX).
, React Native "Write once, run anywhere" ( , ), "Learn once, write anywhere" ( , ).
:
React.js Conf 2015 Keynote - Introducing React Native ( React Native) React.js Conf 2015 Keynote 2 - A Deep Dive into React Native ( React Native)