Event Listener
Hello, this might be a simple question, but I was wondering how I would implement an event listener that runs once a QR code is detected?
I plan to fire an async function that validates the scanned QR code to the database. I tried using useEffect / useMemo with the barcodes variable as a dependency, but it seems that it's reading a state change every time the camera moves? I'm not sure if it'll be good for performance.
Thanks in advance.
Just create your own hook that checks whether the object really changed?
I ended up modifying the useFrameProcessor hook to only update the barcode value only when it detects one.
const frameProcessor = useFrameProcessor((frame) => {
'worklet';
const detectedBarcodes = scanBarcodes(frame, [BarcodeFormat.QR_CODE], {checkInverted: true});
if (detectedBarcodes.length) runOnJS(setBarcodes)(detectedBarcodes);
}, []);
not sure if this is the proper way to go, but it works for now. Anyone who might come up with a better solution, please feel free to comment.