Core (required)

These docs assume basic knowledge of React Native and Matrix jargon.

Steps

1. Add package

yarn add @rn-matrix/core@alpha

2. Add peer dependencies

yarn add react-native-localize @react-native-community/async-storage node-libs-react-native react-native-randombytes

3. Add postinstall script

Add the following line to the scripts section of your package.json:

"postinstall": "sed -i '' '$s/}/,\"browser\":{\"fs\":\"react-native-level-fs\"}}/' node_modules/olm/package.json"
Copy

This script adds a snippet of code to the package.json in the olm library, mapping "fs" to "react-native-level-fs".

4. Add or edit the metro.config.js file

At the root of your project, add or edit the metro.config.js file to include this:

// metro.config.js
module.exports = {
    resolver: {
        extraNodeModules: require('node-libs-react-native'),
    },
}; 

5. Require globals and polyfill URL

Add these lines in your app before anything else:

import 'node-libs-react-native/globals';
import '@rn-matrix/core/shim.js';

import {polyfillGlobal} from 'react-native/Libraries/Utilities/PolyfillFunctions';
polyfillGlobal('URL', () => require('whatwg-url').URL);

6. Install Pods

Do this in the root directory, or if you prefer run cd ios && pod install && cd .. in the root directory.

npx pod-install

7. Run postinstall script

You only need to do this once - it's run automatically when you add or remove packages from now on.

yarn postinstall

8. Proguard (Android)

Add the following line in android/app/proguard-rules.pro

-keep public class com.horcrux.svg.** {*;}

9. Initialize auth

In order to initialize the Matrix SDK to detect auth, you'll need to put this code snippet at the top level of your app, when it starts up, before your app but after the imports we got in step #5.

This is not needed if you're doing token authentication (like with SSO) - only needed for an actual auth flow

import rnm from '@rn-matrix/core';
...
rnm.initAuth()

Last updated