KBeanie

How NativeScript works?

Create Native iOS and Android Apps with JavaScript.

https://www.nativescript.org/

NativeScript is an open source framework for building truly native mobile apps Angular, Vue.js, TypeScript or JavaScript. Just like ReactNative, NativeScript targets web developers who are familiar with JavaScript by providing a platform and tools to get started in no time.

You can even share and re-use existing web-based application code to get accelerate your development. All you need to know is JavaScript, HTML, and CSS. You build the UI in HTML and CSS and write your business logic in JavaScript (TypeScript, Angular, Vue.js are the other options).

NativeScript is backed by Progress

How NativeScript works

NativeScript components

NativeScript components

1. NativeScript runtimes

NativeScript runtimes for iOS and Android are the core part of the framework and act as a bridge between the JavaScript and the native worlds. This allows you to call native APIs on Android and iOS using common JavaScript code.

The JavaScript code that you write runs on a JavaScript Virtual Machine, Google’s V8 for Android and WebKit’s JavaScriptCore on iOS. The runtimes are a part of your application package that gets installed along with your application. The virtual machines are loaded in the application’s process and runs on the application’s main thread, quite like ReactNative.

2. Core modules

Various modules available in the framework provide a cross-platform abstraction layer for the native APIs. This layer provides a common interface to call into platform-specific methods for your JavaScript code. You do not need to know any platform-specific APIs.

The core modules translate your calls into platform-specific calls that are executed at the runtime.

3. Plugins

You can think of plugins as third-party libraries. These are npm packages that are developed by other developers which can accelerate your development. i.e, Facebook SDK, Socket.io etc

4. Metadata, Type Conversion and Call Dispatcher

NativeScript in action

When your JavaScript code runs, the platform-specific Metadata is looked up to find the corresponding function. Metadata is a pre-prepared set of mappings between the JavaScript APIs and the native APIs. This is generated during compilation and thus, isn’t much of an overhead at runtime.

Once the target function is identified, Type Conversion of the JavaScript types helps transform the data to native data types, and back to JavaScript type when a result is returned. This is also known as Marshalling.

Finally, the Call Dispatcher takes care of making the actual calls to the native APIs and also receives the results and passes it back to the Type Conversion layer.


Get started

You need not know about the inner workings of the framework to start developing mobile apps using NativeScript, however, having a basic idea on how it works in theory is a good thing to learn.

You can find more information here about NativeScript. Get started!!!

Leave a Reply

Your email address will not be published. Required fields are marked *