osdnk / react-native-jsi-meets-rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rust + React Native

That is an extremely simple (and incorrect in many ways) PoW on how to connect Rust code and React Native.

The inspirations were:

  1. https://github.com/Terrahop/react-native-rust-demo
  2. https://github.com/inokawa/react-native-wasm
  3. https://github.com/inokawa/react-native-react-bridge

First, I wanted to compile Rust to wasm and use it within React Native, but the only reasonable way was to do it inside WebView. That looked extraordinarily wrong and, from the perspective of security and maintainability, looked like an abysmal choice.

Hence, I decided to create C bindings in the Rust library. Those bindings are consumed via JSI Module and bridged via JSI to JavaScript. For now, this works only on iOS and only on the simulator. Adding support for the actual iPhone is not problematic, but adding support for Android requires additional effort. react-native-rust-demo looked promising, but I wanted to use JSI binding to have fast, synchronous calls and maintain more control over the flow.

How to run?

RN setup:

yarn 
cd ios && pod install && cd ..
yarn react-native start

Compile library

cd rust
rustup target add x86_64-apple-ios-sim
cargo build --target x86_64-apple-ios
cd ..

Compile app

yarn react-native run-ios

Demo

About


Languages

Language:Java 41.0%Language:C++ 21.7%Language:Objective-C++ 13.4%Language:JavaScript 8.3%Language:Objective-C 6.7%Language:Ruby 4.3%Language:Starlark 1.6%Language:Shell 1.3%Language:C 0.8%Language:CMake 0.7%Language:Rust 0.3%