React Native

Using the SDK with react native

To use the SDK in a react native context, it is required to include some polyfills for functionality used in the SDK. The list of polyfills to be installed in the project alongside @concordium/web-sdk include:

{
...
"dependencies": {
"@azure/core-asynciterator-polyfill": "...",
"@stardazed/streams-polyfill": "...",
"react-native-get-random-values": "...",
"react-native-polyfill-globals": "...",
"text-encoding": "..."
}
}

Installation

yarn add @concordium/web-sdk react-native-polyfill-globals react-native-get-random-values text-encoding @azure/core-asynciterator-polyfill @stardazed/streams-polyfill # or npm install
npx pod-install # if building for ios, adds native modules from dependencies to project.

Adding polyfill to app

From ./../examples/reactnative/polyfill.ts#1~14

// Requires peer dependency `text-encoding`
import '@azure/core-asynciterator-polyfill';
import '@stardazed/streams-polyfill';
// @ts-ignore
import { polyfill as polyfillCrypto } from 'react-native-polyfill-globals/src/crypto';
// @ts-ignore
import { polyfill as polyfillEncoding } from 'react-native-polyfill-globals/src/encoding';

// Requires peer dependency `react-native-get-random-values`

polyfillEncoding();
polyfillCrypto();

From ./../examples/reactnative/index.js#4~14

import { AppRegistry } from 'react-native';

import App from './App';
import { name as appName } from './app.json';
// Polyfill must come before any reference to @concordium/web-sdk.
// In this case, that means before importing ./App.tsx
import './polyfill';

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

This ensures the native modules required by the SDK are present.

Unsupported functionality

Due to current lack of support for web assembly in react native, some aspects of the SDK are not supported on the platform. This is specifically scoped to the functionality exposed at the entrypoint @concordium/web-sdk/wasm. Everything else supported on web platforms should also be supported on react native.

Generated using TypeDoc