Closed as-85 closed 4 months ago
Have find out, thats this formats whats causing it. Without formats array it works well.
formats: ['code_128', 'qr_code', 'data_matrix']
I tried to add formats
and it work fine;
Can you provide a mini repo?
Here is my test code:
'use client';
import dynamic from 'next/dynamic';
import { DetectedBarcode } from 'react-barcode-scanner';
const BarcodeScanner = dynamic(
() => {
import('react-barcode-scanner/polyfill');
return import('react-barcode-scanner').then((mod) => mod.BarcodeScanner);
},
{ ssr: false }
);
export default function Demo () {
const onCapture = (barcode: DetectedBarcode) => {
console.log(barcode.format, barcode.rawValue)
}
return (
<div style={{ width: '400px', height: '400px' }}>
<BarcodeScanner onCapture={onCapture} options={{ formats: ['code_128', 'qr_code', 'data_matrix'] }} />
</div>
)
}
Here is print:
My code looks like yours but not worked on my mobile devices. Did you try with mobiles? On desktop Chrome it worked fine.
it's because zbar doesn't support data_matrix
format;
According doc, zbar not support aztec
, data_matrix
and pdf417
formats, I will add warning in docs about support formats;
Reference: https://github.com/mchehab/zbar
The document has been updated
On my own app the event onCapture seems not be fired. The app is hosted on vercel. Have tried with different iPhones with Chrome and Safari.
I've tried with next/dynamic and without. Your Demoapp works.
Here is my code. I have tried with different imports.
Imports