Open History to see the last commit
1// Polyfill for crypto.randomUUID() which is not available in React Native Hermes
2if (typeof global.crypto === 'undefined') {
3 global.crypto = {} as Crypto
4}
5
6if (typeof global.crypto.randomUUID !== 'function') {
7 global.crypto.randomUUID =
8 function randomUUID(): `${string}-${string}-${string}-${string}-${string}` {
9 // Simple UUID v4 implementation
10 const hex = '0123456789abcdef'
11 let uuid = ''
12 for (let i = 0; i < 36; i++) {
13 if (i === 8 || i === 13 || i === 18 || i === 23) {
14 uuid += '-'
15 } else if (i === 14) {
16 uuid += '4' // Version 4
17 } else if (i === 19) {
18 uuid += hex[(Math.random() * 4) | 8] // Variant bits
19 } else {
20 uuid += hex[(Math.random() * 16) | 0]
21 }
22 }
23 return uuid as `${string}-${string}-${string}-${string}-${string}`
24 }
25}