feat: fixes and formatter
This commit is contained in:
+22
-22
@@ -1,32 +1,32 @@
|
||||
import React, { useMemo } from "react";
|
||||
import { View } from "react-native";
|
||||
import Svg, { Rect } from "react-native-svg";
|
||||
import { generateQrMatrix } from "../utils/generateQrMatrix";
|
||||
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 DEFAULT_SIZE = 220
|
||||
|
||||
const QrCode = ({
|
||||
value,
|
||||
size = DEFAULT_SIZE,
|
||||
color = "#FFFFFF",
|
||||
backgroundColor = "transparent",
|
||||
errorCorrectionLevel = "M",
|
||||
color = '#FFFFFF',
|
||||
backgroundColor = 'transparent',
|
||||
errorCorrectionLevel = 'M',
|
||||
}) => {
|
||||
const { matrix } = useMemo(() => {
|
||||
try {
|
||||
return generateQrMatrix({ value, errorCorrectionLevel });
|
||||
return generateQrMatrix({ value, errorCorrectionLevel })
|
||||
} catch (error) {
|
||||
console.error("qr.code.generate.error", error);
|
||||
return { matrix: [] };
|
||||
console.error('qr.code.generate.error', error)
|
||||
return { matrix: [] }
|
||||
}
|
||||
}, [value, errorCorrectionLevel]);
|
||||
}, [value, errorCorrectionLevel])
|
||||
|
||||
const cellSize = useMemo(() => {
|
||||
if (!matrix || !matrix.length) {
|
||||
return 0;
|
||||
return 0
|
||||
}
|
||||
return size / matrix.length;
|
||||
}, [matrix, size]);
|
||||
return size / matrix.length
|
||||
}, [matrix, size])
|
||||
|
||||
return (
|
||||
<View
|
||||
@@ -40,10 +40,10 @@ const QrCode = ({
|
||||
{matrix.map((row, rowIndex) => {
|
||||
return row.map((isDark, colIndex) => {
|
||||
if (!isDark) {
|
||||
return null;
|
||||
return null
|
||||
}
|
||||
|
||||
const key = `${rowIndex}-${colIndex}`;
|
||||
const key = `${rowIndex}-${colIndex}`
|
||||
|
||||
return (
|
||||
<Rect
|
||||
@@ -54,12 +54,12 @@ const QrCode = ({
|
||||
height={cellSize}
|
||||
fill={color}
|
||||
/>
|
||||
);
|
||||
});
|
||||
)
|
||||
})
|
||||
})}
|
||||
</Svg>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
)
|
||||
}
|
||||
|
||||
export default QrCode;
|
||||
export default QrCode
|
||||
|
||||
Reference in New Issue
Block a user