mobile-native-barcode-generator
Version:
Library to generate barcodes and qr codes natively using Kotlin and Swift, integrated with react native.
51 lines (50 loc) • 1.25 kB
JavaScript
;
import { useEffect, useState } from "react";
import { Image } from "react-native";
import generateQRCode from "../generateQRCode.js";
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
export default function QRCodeView({
testID,
value,
width,
height,
style,
onLoad,
onError
}) {
const [barcode, setBarcode] = useState("");
if (value === "") {
throw new Error("Value cannot be empty");
}
if (width <= 0 || typeof width !== "number") {
throw new Error("Width must be a positive number");
}
if (height <= 0 || typeof height !== "number") {
throw new Error("Height must be a positive number");
}
useEffect(() => {
async function waitFor() {
const qrCodeGeneradet = await generateQRCode(value, width, height);
setBarcode(qrCodeGeneradet);
}
waitFor();
return () => {
setBarcode("");
};
}, [height, value, width]);
return /*#__PURE__*/_jsx(_Fragment, {
children: barcode && /*#__PURE__*/_jsx(Image, {
testID: testID,
source: {
uri: barcode
},
style: [{
width,
height
}, style],
onLoad: onLoad,
onError: onError
})
});
}
//# sourceMappingURL=QRCodeView.js.map