import React, { useMemo } from 'react' import { View } from 'react-native' import Svg, { Rect } from 'react-native-svg' import { generateQrMatrix } from '../utils/generateQrMatrix' const DEFAULT_SIZE = 220 const QrCode = ({ value, size = DEFAULT_SIZE, color = '#FFFFFF', backgroundColor = 'transparent', errorCorrectionLevel = 'M', }) => { const { matrix } = useMemo(() => { try { return generateQrMatrix({ value, errorCorrectionLevel }) } catch (error) { console.error('qr.code.generate.error', error) return { matrix: [] } } }, [value, errorCorrectionLevel]) const cellSize = useMemo(() => { if (!matrix || !matrix.length) { return 0 } return size / matrix.length }, [matrix, size]) return ( {matrix.map((row, rowIndex) => { return row.map((isDark, colIndex) => { if (!isDark) { return null } const key = `${rowIndex}-${colIndex}` return ( ) }) })} ) } export default QrCode