Skip to content

Commit 358e46b

Browse files
brentvatneLinusU
andauthored
🎉 Add support for Expo SDK 41+ (#28)
* ❌ Get rid of .expo.js extension, no longer supported in Expo SDK 41+ * 🌹 Move getRandomBase64 back into main file Co-authored-by: Linus Unnebäck <[email protected]>
1 parent 3afc0fa commit 358e46b

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

getRandomBase64.expo.js

-8
This file was deleted.

getRandomBase64.js

-1
This file was deleted.

index.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const base64Decode = require('fast-base64-decode')
2-
const getRandomBase64 = require('./getRandomBase64')
2+
const { NativeModules } = require('react-native')
33

44
class TypeMismatchError extends Error {}
55
class QuotaExceededError extends Error {}
@@ -19,6 +19,20 @@ function insecureRandomValues (array) {
1919
return array
2020
}
2121

22+
/**
23+
* @param {number} byteLength
24+
* @returns {string}
25+
*/
26+
function getRandomBase64 (byteLength) {
27+
if (NativeModules.RNGetRandomValues) {
28+
return NativeModules.RNGetRandomValues.getRandomBase64(byteLength)
29+
} else if (NativeModules.ExpoRandom) {
30+
return NativeModules.ExpoRandom.getRandomBase64String(byteLength)
31+
} else {
32+
throw new Error('Native module not found')
33+
}
34+
}
35+
2236
/**
2337
* @param {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Uint8ClampedArray} array
2438
*/

0 commit comments

Comments
 (0)