Telerik has opened for public access NativeScript, a framework for creating native cross-platform applications for Android, iOS and Windows Universal.
NativeScript is not a new JavaScript flavor nor a wrapper around native functionality, but it includes a JavaScript runtime and a mechanism to translate JavaScript calls to native ones. Applications are written in JavaScript (or TypeScript, CoffeeScript, etc.) and they are interpreted by V8 on Android and by WebKit JavaScriptCore on iOS and Windows Phone. After that, the NativeScript runtime discovers the native API that is targeted, converts the JS data types to corresponding native types, and calls native APIs, returning whatever values are coming from them, as shown in the following diagram:
As an example, the creation of this File object var file = new java.io.File(path);,
on Android goes through the following steps:
- The code is interpreted by V8
- Metadata determines the corresponding native method to call. Metadata is a pre-built set of all the available APIs on each platform, providing type and method signatures.
- The Type Conversion modules converts the JavaScript String to a
java.lang.String
object - The runtime creates a proxy object for
java.io.File
- Calls on the original JS File object are delegated to the corresponding Java instance through this proxy
There is a 10% performance penalty introduced by the NativeScript runtime compared to pure native code, according to Telerik.
The NativeScript runtime can target any native API in the supported platforms including sensor APIs and third-party libraries written in Objective C, Java or .NET. The UI components are native widgets and the UI events are processed by native handlers, such as View.OnClickListener, UIControl.addTarget,
declared in JavaScript code.
To avoid requiring developers to have deep knowledge of the three mobile platforms supported, the framework includes the NativeScript Modules Layer (NML) which abstracts the connection with native code, automatically translating JavaScript calls into native ones. NML includes the following modules, among others: Application, Camera, Color, Console, Data, File System, HTTP, Imaging, Local Settings, Location, Timer, UI. But, one is not limited to using NML, being able to access any native API.
A few other features of NativeScript are, in short:
-
Currently supported platforms: iOS7+, Android 4.2+. Support for Windows Phone is coming in April. Earlier version of Android are to be supported soon.
-
Compilation for iOS can be done remotely without requiring a Mac or iOS tools.
-
Development can be done in any IDE.
-
Supports any cross-browser JavaScript library.
-
Supports CSS.
-
Supports MVVM.
-
0-day support for new native platforms.
NativeScript is open sourced on GitHub under an Apache 2.0 license.