This directory contains the React Native module that bridges your React Native application with the underlying Rust Ark project by Second, facilitated by the C++ FFI layer in bark-cpp
. It leverages React Native NitroModules for efficient communication between JavaScript/TypeScript and native C++ code.
- To install the
react-native-nitro-ark
module, run the following command in your React Native project directory: - For all methods and type definitions refer to the
react-native-nitro-ark/src/index.tsx
file.
npm install react-native-nitro-ark react-native-nitro-modules
# or
yarn add react-native-nitro-ark react-native-nitro-modules
- Download the Android binary and put it inside
node_modules/react-native-nitro-ark/android/src/main/jniLibs/arm64-v8a
. - Download the iOS binary,
unzip
it and put it insidenode_modules/react-native-nitro-ark/Ark.xcframework
.
The primary goal of this module is to expose the rust functions of the "Ark" Rust project to your React Native application. It provides:
- A TypeScript API (
src/
) for easy consumption from your React Native JavaScript/TypeScript code. - Native C++ implementations (
cpp/
) that utilize thebark-cpp
FFI to call into the Rust core logic.
This allows you to write high-performance core logic in Rust and seamlessly integrate it into your cross-platform React Native application.
bark-cpp/
: Contains the C++ FFI code that directly interfaces with the Rust "Ark" project. This code is compiled into a static library for Android and iOS.react-native-nitro-ark/cpp/
: Contains the C++ code specific to this React Native Nitro module. This code:- Includes the necessary headers from React Native Nitro.
- Links against the static library produced by
bark-cpp
. - Implements the native methods that are exposed to the TypeScript side.
- Calls the functions provided by the
bark-cpp
FFI layer.
react-native-nitro-ark/react-native/src/
: Contains the TypeScript/JavaScript code that defines the public API of this module. This is what your React Native application will import and use. It makes calls to the native C++ methods defined in thecpp/
directory via the React Native Nitro bridge.react-native-nitro-ark/example/
: Contains an example React Native application that demonstrates how to use thereact-native-nitro-ark
module. This directory includes the necessary files to set up a React Native project and showcases the usage of the TypeScript API.
The interaction flow is generally as follows:
- React Native App (JS/TS): Your application code imports and calls functions from the TypeScript API exposed in
react-native-nitro-ark/src/
. - TypeScript API (
react-native-nitro-ark/src/
): These TypeScript functions act as a wrapper. They use React Native Nitro's mechanisms to invoke corresponding native C++ methods. - React Native Nitro Bridge: Nitro efficiently marshals data and forwards the call from JavaScript to the native C++ environment.
- Nitro C++ Module (
react-native-nitro-ark/cpp/
): The C++ methods implemented here receive the call. - FFI Call: This C++ code then calls the relevant functions exposed by the
bark-cpp
FFI layer. Thesebark-cpp
functions are available because the static library produced frombark-cpp
is linked into the application. - Bark C++ FFI (
react-native-nitro-ark/bark-cpp/
): This layer translates the C++ call into a call to the Rust "Ark" project's compiled code.
- The
bark-cpp
code needs to be compiled into static libraries for each target platform (iOS and Android). - This React Native module (
react-native-nitro-ark
) then links against these precompiled static libraries. - Ensure that your main application's build system (Xcode for iOS, Gradle for Android) is configured to:
- Compile and link the C++ code in
react-native-nitro-ark/cpp/
. - Link the static libraries from
bark-cpp
. - Integrate the React Native Nitro module correctly.
- Compile and link the C++ code in
Refer to the React Native Nitro documentation and the specific build configurations within the ios/
and android/
directories for detailed integration steps.
- Rust
- React Native
- The compiled static libraries from
bark-cpp
.