jamenamcinteer / react-qr-barcode-scanner

A simple React Component using the client's webcam to read barcodes.
82 stars 75 forks source link

torch prop not work #18

Open DavidRojas1612 opened 3 years ago

DavidRojas1612 commented 3 years ago

I am trying to use the torch prop in my implementation, but I can't get this to work,

const [torch, setTorch] = useState(false);

return (
...
<i className={`icon-Icon_torch ${styles.torch}`} onClick={() => setTorch(prev => !prev)} />
<BarcodeScannerComponent
  width="100%"
  height={
    windowSize.height
      ? windowSize.height - SCAN_CONFIG.footerHeight
      : SCAN_CONFIG.cameraDefaultHeight
  }
  torch={torch}
  facingMode="environment"
  onUpdate={(err, result) => {
    if (result) {
      handleResult(result.getText());
    }
  }}
/>
sksurendrakmr commented 2 years ago

torch props are working fine. It will only work if flashlight or torch is available in device otherwise not.

franciscopantojag commented 2 years ago

Hello @sksurendrakmr, do you know of any examples where the react-qr-barcode-scanner is opened and the flashlight is on? If that's the case, can you please provide one? Thanks in advance!

ZaimSa commented 2 years ago

I had the same problem when I tried to set the value to true directly, to work around the problem you have to use a state variable and add a timeout: setTimeout(()=>{setTorchOn(!torchOn)}, 1500 );

morkeleb commented 2 years ago

I can't get the torch to work on an IPhone 13 nor 14. We're setting the torch property similarly to what @DavidRojas1612 wrote above

jiaxiangcheng commented 1 year ago

I can't get the torch to work on an IPhone 13 nor 14. We're setting the torch property similarly to what @DavidRojas1612 wrote above

On my iphone 13 the torch has no effect, but facingMode it is working

donburks commented 1 year ago

Also cannot get torch to work on iPhone 13.

donburks commented 1 year ago

I had the same problem when I tried to set the value to true directly, to work around the problem you have to use a state variable and add a timeout: setTimeout(()=>{setTorchOn(!torchOn)}, 1500 );

Can you provide a bit more sample code of how you did this, please?