react-qr-reader icon indicating copy to clipboard operation
react-qr-reader copied to clipboard

Opening front camera on Google Chrome in Android even with facingMode set to "environment".

Open salil09 opened this issue 4 years ago • 4 comments

Hi, I am trying to integrate this, it's opening the rear camera in safari on iOS but it's opening the front camera on chrome in android. Below is the code snippet of what we are trying, there's nothing much to do except setting the facingMode to "environment" but still it's not working, we even tried removing the facingMode, as "environment" is by default according to the documentation but that didn't work either. The demo is working perfectly fine on google chrome in android. Please check and let me know what are we doing here. Thanks and sorry about the formatting.

import React, { Component } from 'react'; import QrReader from 'react-qr-reader' import { withRouter } from 'react-router-dom'; let Instascan = require('instascan'); import { Modal } from "react-bootstrap";

class ScanCode extends Component { constructor(props) { super(props); this.state = { result: 'No result', } }

handleScan = data => {
}

handleError = err => {
}

render() {
    return (
        <div>
            {<QrReader
                delay={300}
                facingMode='environment'
                onError={this.handleError}
                onScan={this.handleScan}
                style={{ width: '100%' }}
            />
            }
        </div>
    )
}

}

export default withRouter(ScanCode);

salil09 avatar May 19 '20 11:05 salil09

I have had the same problem with Safari on iOs. The only thing I could do was add a button to change the camera by pressing on it.

1 . Add a state: facingMode: "user"

  1. Add a method
camareButton = () =>{
        if(this.state.facingMode === "environment"){
            this.setState({
                facingMode: "user"
            })
        } else {
            this.setState({
                facingMode: "environment"
            })
        }
      }
  1. Add button <input type="button" value="Camera..." onClick={this.cameraButton} />

  2. Edit Facingmode into < QrReader >

facingMode = {this.state.facingMode}

jlarteagap avatar May 21 '20 14:05 jlarteagap

Maybe this fixes the problem? I had a problem with it not opening the back camera on newer android devices with multiple front and rear cameras, as you have to specify which camera.

I created the following pull request with changes that fix it for me:

https://github.com/JodusNodus/react-qr-reader/pull/164

carrawao avatar Jun 11 '20 16:06 carrawao

There is a possibly-related issue noted in the README: "In Firefox a prompt will be shown to the user asking which camera to use, so facingMode will not affect it."

charleskoehl avatar May 13 '21 00:05 charleskoehl

Try this...

<QrReader
      onResult={handleScan}
      constraints={{
        facingMode: "environment",
      }}
/>

avichovatiya67 avatar Feb 09 '24 07:02 avichovatiya67