UNPKG

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.26 kB
"use strict"; import { useEffect, useState } from "react"; import { Image } from "react-native"; import generateBarcode from "../generateBarcode.js"; import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime"; export default function BarcodeView({ 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 barcodeGeneradet = await generateBarcode(value, width, height); setBarcode(barcodeGeneradet); } 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=BarcodeView.js.map