Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the library to work in React Native #2

Open
noway opened this issue Nov 6, 2021 · 5 comments
Open

Get the library to work in React Native #2

noway opened this issue Nov 6, 2021 · 5 comments

Comments

@noway
Copy link
Member

noway commented Nov 6, 2021

Tests should pass in React Native environment

@NeedsAdjustment
Copy link

NeedsAdjustment commented Nov 17, 2021

Polyfilling TextEncoding (seems to) work currently, stuck on finding a suitable implementation of BigInt currently (that supports 0x... notation). I'm not sure what other core libraries don't have inbuilt React Native equivalents.

Also (attempting to) ping @meshcollider

@NeedsAdjustment
Copy link

NeedsAdjustment commented Nov 17, 2021

Successfully got polyfills working for a react native implementation (soon to be public), based on modified code from this. Imo using a helper package is a bit clunky, but it's a possible way forward.

@NeedsAdjustment
Copy link

Specifically:

import 'text-encoding-polyfill'
global.Buffer = global.Buffer || require('buffer').Buffer

if (typeof BigInt === 'undefined') {
    const bi = require('big-integer')

    function myBigInt(value) {
        if (typeof value === 'string') {
            const match = value.match(/^0([xo])([0-9a-f]+)$/i)
            if (match) {
                return bi(match[2], match[1].toLowerCase() === 'x' ? 16 : 8)
            }
        }
        return bi(value)
    }

    global.BigInt = myBigInt

    if (process === undefined) {
        process = require('process')
    } else if (process.nextTick === undefined) {
        process.nextTick = require('process').nextTick
    }
}

@rafcontreras
Copy link
Member

We have two React Native apps now using this package, I suggest this closes.

@noway
Copy link
Member Author

noway commented Nov 22, 2021

Let's write down some documentation, maybe create REACT_NATIVE.md and link it in README.md?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants