Название: jаvascript Native Interface: Build cross-platform apps with native performance Автор: Tony Gaitatzis Издательство: BackupBrain Год: 2024 Страниц: 194 Язык: английский Формат: pdf, epub Размер: 10.9 MB
About this Book:
In mobile development, there is a trade-off between portability code and fast execution. A new feature of React Native called jаvascript Native Interface (JSI) removes that trade-off by allowing developers to write portable code that executes as binary code on the native device.
jаvascript Interface (JSI) offers developers to the convenience of cross-platform apps with the performance of native apps. It lets developers to write functions in C++ that can be called directly from jаvascript, for example in a React Native front-end. It works by combining two existing features of React Native: • The native code (for example Swift or Java) can call binary functions from compiled C++ • React Native jаvascript can call properly-defined native functions
C++ code can be written in a cross-platform way and compiled for a variety of devices, such as Android and iOS, as long as it doesn’t work on device-specific or platform-specific features such as user interfaces or certain hardware such as sensors or specific camera features. Since both the jаvascript and C++ are cross-platform and the native layer can bind these languages together, it is possible to create React Native apps for several platforms with one code base. jаvascript Native Interface code must be written so that functions and data types are compatible with the jаvascript type system, and those functions must be properly exported to the jаvascript environment. This book will walk you through understanding how to set up a React Native project to use JSI, and how to implement common function types in JSI, including those that take or return arrays and complex object types, Promises, and multi-threaded functions.
jаvascript Interface (JSI) is a lightweight, general-purpose API provided by Facebook for interacting with jаvascript data types and functions in C++ code. Introduced in the context of React Native, JSI offers a way to call C++ functions directly from jаvascript and vice versa. Before JSI, React Native used a “Native Bridge” feature, which required that developers write native code in the device-native language, for example Swift on iOS and Java or Kotlin on Android. React Native developers who wanted to have the performance of a native app therefore needed to maintain two code-bases for the same features. JSI solves this by allowing developers to maintain high-performance code in only one language: C++. While JSI brings numerous advantages, especially for complex and performance-critical applications, it's worth noting that it requires a good understanding of both C++ and jаvascript, as well as the internals of React Native. As such, it's often used for building advanced features, or optimizing performance-critical paths.
What You Will Learn:
This book teaches you how to write JSI code so that you can have write-once, run-everywhere mobile apps that feel like they are written in native code.
You will learn how to set up a JSI project on MacOS, Windows, and Linux. It will teach you how to register native functions, and how to accept any type of parameter and return any type of value. Importantly, this also includes working with objects, arrays, callback functions, and promises.
Who This Book Is For: This book is intended for programmers, engineers, and technology enthusiasts who want to learn about mobile development.
Скачать jаvascript Native Interface: Build cross-platform apps with native performance