import { getRandomBytes, getRandomBytesAsync } from 'expo-random'; import React from 'react'; import { ScrollView } from 'react-native'; import HeadingText from '../components/HeadingText'; import MonoText from '../components/MonoText'; import Colors from '../constants/Colors'; // Placeholder polyfill if (!globalThis.crypto) { globalThis.crypto = { // @ts-ignore getRandomValues: (array) => getRandomBytes(array.byteLength), }; } type State = { random: any; randomAsync: any; uuid: any; }; export default class RandomScreen extends React.Component { static navigationOptions = { title: 'Random', }; readonly state: State = { random: getRandomBytes(10), randomAsync: null, uuid: require('uuid').v4(), }; async componentDidMount() { this._getRandomAsync(); } _getRandomAsync = async () => { const randomAsync = await getRandomBytesAsync(10); this.setState({ randomAsync }); }; render() { return ( getRandomBytes: {JSON.stringify(this.state.random)} getRandomBytesAsync: {JSON.stringify(this.state.randomAsync)} UUID: {JSON.stringify(this.state.uuid)} ); } }