capacitor-community / barcode-scanner

A fast and efficient (QR) barcode scanner for Capacitor
MIT License
437 stars 167 forks source link

Torch / Flashlight doesn't work during camera stream. #264

Open jonasphp opened 1 year ago

jonasphp commented 1 year ago

I'm trying this on a complete fresh install. I'm using iOS 16, Newest Android OS xCode 14 and capacitor v5, The qr scanner works only flash doesn't this is the current code:

On iOS the torch turns on and then off as soon as the camera view starts, on android it doesn't turn on at all.

` const startScan = async () => { document.body.style.opacity="0.2"; document.body.style.background = "transparent"; document.getElementById("pusher").style.display = "none";

            BarcodeScanner.hideBackground(); // make background of WebView transparent
            BarcodeScanner.enableTorch();
            const result = await BarcodeScanner.startScan(); // start scanning and wait for a result

            // if the result has content
            if (result.hasContent) {
                 document.getElementById("pusher").style.display = "block";

                document.body.style.background = "";
                document.body.style.opacity="1";
              console.log(result.content); // log the raw scanned content
            }
          }
          startScan();`
thegnuu commented 1 year ago

This will not work, you need to use startScanning and enable your torch after this call.

startScan will reset the camera-view and therefore disable the torch, this is unfortunately not so easy to fix with the current implementation. Maybe it works if you call prepare before your enableTorch call, but unfortunately I cannot test it at the moment.