5

im using react-native-qrcode-scanner and what i want to do is : when user press on a flashlight icon flashLight go on i done this :

<QRCodeScanner
        showMarker
        onRead={this.onSuccess.bind(this)}
        cameraStyle={{ height: SCREEN_HEIGHT }}
        cameraProps={{ flashMode: this.state.flashLight ? RNCamera.Constants.FlashMode.on : RNCamera.Constants.FlashMode.off, captureAudio: false }}

camera prop works but when i change the state.flashLight (true or false) the flashLight not change

any Idea how change camera prop with state ??

2 Answers2

4

Try to replace:

RNCamera.Constants.FlashMode.on

with:

RNCamera.Constants.FlashMode.torch

Does the flashlight turn on now?

Nino9612
  • 928
  • 5
  • 12
4

Using react-native-qrcode-scanner version 1.2.2 or above

Try to use flashMode instead of cameraProps.

Here is a working example:

      <QRCodeScanner
              ref={(node) => { this.scanner = node }}
              onRead={this.onSuccess.bind(this)}
              showMarker
              cameraStyle={{ height: SCREEN_HEIGHT }}
              customMarker={this.renderCustomMarker}
              flashMode={this.state.torchEnable ? RNCamera.Constants.FlashMode.torch : RNCamera.Constants.FlashMode.off}
              />

this.state.torchEnable is a boolean variable used to set flash on or off.

For more info read the Github repo description on Methods > flashMode

lcsvcn
  • 1,184
  • 3
  • 13
  • 28