All Projects → inokawa → react-native-wasm

inokawa / react-native-wasm

Licence: MIT license
A polyfill to use WebAssembly in React Native.

Programming Languages

kotlin
9241 projects
swift
15916 projects
javascript
184084 projects - #8 most used programming language
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to react-native-wasm

sanitizer-polyfill
rewrite constructor arguments, call DOMPurify, profit
Stars: ✭ 46 (+17.95%)
Mutual labels:  polyfill
Promise.allSettled
ES Proposal spec-compliant shim for Promise.allSettled
Stars: ✭ 93 (+138.46%)
Mutual labels:  polyfill
symfony-tools
Collection of polyfill (backport) and incubator features for Symfony 3
Stars: ✭ 19 (-51.28%)
Mutual labels:  polyfill
ember-on-modifier
Implements the `{{on eventName this.someAction}}` element modifier from https://github.com/emberjs/rfcs/blob/master/text/0471-on-modifier.md
Stars: ✭ 37 (-5.13%)
Mutual labels:  polyfill
css grid annotator
Automatically annotate CSS Grid items with row and column positions, so they are correctly positioned in IE11.
Stars: ✭ 59 (+51.28%)
Mutual labels:  polyfill
fetch
A fetch API polyfill for React Native with text streaming support.
Stars: ✭ 27 (-30.77%)
Mutual labels:  polyfill
array-includes
Array.prototype.includes spec-compliant polyfill
Stars: ✭ 42 (+7.69%)
Mutual labels:  polyfill
require-polyfill
Make `require` work in browsers, at runtime. No code bundling needed!
Stars: ✭ 37 (-5.13%)
Mutual labels:  polyfill
Object.getOwnPropertyDescriptors
Spec-compliant shim for `Object.getOwnPropertyDescriptors` that works in ES5.
Stars: ✭ 19 (-51.28%)
Mutual labels:  polyfill
weakmap-polyfill
ECMAScript6 WeakMap polyfill
Stars: ✭ 25 (-35.9%)
Mutual labels:  polyfill
deno-fetch-event-adapter
Dispatches global fetch events using Deno's native http server.
Stars: ✭ 18 (-53.85%)
Mutual labels:  polyfill
react-native-drawer-layout-polyfill
A polyfill for React Natives DrawerLayoutAndroid
Stars: ✭ 48 (+23.08%)
Mutual labels:  polyfill
iframe-worker
A tiny WebWorker polyfill for the file:// protocol
Stars: ✭ 23 (-41.03%)
Mutual labels:  polyfill
String.prototype.trim
ES5 spec-compliant shim for String.prototype.trim
Stars: ✭ 13 (-66.67%)
Mutual labels:  polyfill
Polyfill
An artifact repository to assist writing Gradle Plugins for Android build system.
Stars: ✭ 68 (+74.36%)
Mutual labels:  polyfill
seamless-scroll-polyfill
Scroll Behavior polyfill
Stars: ✭ 134 (+243.59%)
Mutual labels:  polyfill
parcel-plugin-goodie-bag
provides the Promise and fetch goodies needed for IE(11) support w/ parcel bundle loading
Stars: ✭ 15 (-61.54%)
Mutual labels:  polyfill
webpack2-polyfill-plugin
Insert polyfills (such as Promise) for Webpack 2
Stars: ✭ 18 (-53.85%)
Mutual labels:  polyfill
Javascript-Interview-Preparation
A curated collection of javascript interview questions & solutions.
Stars: ✭ 163 (+317.95%)
Mutual labels:  polyfill
polyfill-php81
This component provides functions unavailable in releases prior to PHP 8.1.
Stars: ✭ 618 (+1484.62%)
Mutual labels:  polyfill

react-native-wasm

npm

A polyfill to use WebAssembly in React Native.

This package instantiate WebAssembly in native WebView environment and make communication with React Native to simulate original behavior. Native module of React Native has limited argument types (iOS/Android) so we need to serialize/deserialize the exchanging data, which may have some overhead but will work as in web app.

⚠️ Note

I recommend to use react-native-react-bridge rather than this, to run WebAssembly. Although it's aim is a bit different, it's built on WebView like this and it's working much more stably.

And also check the current progress of wasm support in React Native:

Install

npm install react-native-wasm

# <=0.59 you have to link manually.
react-native link react-native-wasm

# In iOS
cd ios && pod install

And currently you have to create bridging header manually in iOS.

https://reactnative.dev/docs/native-modules-ios#exporting-swift

Important when making third party modules: Static libraries with Swift are only supported in Xcode 9 and later. In order for the Xcode project to build when you use Swift in the iOS static library you include in the module, your main app project must contain Swift code and a bridging header itself. If your app project does not contain any Swift code, a workaround can be a single empty .swift file and an empty bridging header.

Requirements

  • react-native 0.59+ (because of Proxy support in React Native)

Usage

// index.js
import { AppRegistry } from "react-native";
import "react-native-wasm";
...

AppRegistry.registerComponent(appName, () => App);

// Foo.js
const buffer = Uint8Array.from([
	 0x00,0x61,0x73,0x6D,0x01,0x00,0x00,0x00
	,0x01,0x87,0x80,0x80,0x80,0x00,0x01,0x60
	,0x02,0x7F,0x7F,0x01,0x7F,0x03,0x82,0x80
	,0x80,0x80,0x00,0x01,0x00,0x07,0x87,0x80
	,0x80,0x80,0x00,0x01,0x03,0x61,0x64,0x64
	,0x00,0x00,0x0A,0x8D,0x80,0x80,0x80,0x00
	,0x01,0x87,0x80,0x80,0x80,0x00,0x00,0x20
	,0x00,0x20,0x01,0x6A,0x0B]);

WebAssembly.instantiate(buffer).then((res) => {
  console.log(res.instance.exports.add(3, 5)); // 8
});

TODOs

  • instantiate
    • Support iOS
    • Support Android
    • Support importObject
  • compile
  • validate
  • WebAssembly.Instance
  • WebAssembly.Module
  • WebAssembly.Memory
  • WebAssembly.Table
  • Support bundling .wasm file
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].