【问题标题】:Turn flashlight on/off In QRcodeScanner React native在 QRcodeScanner React native 中打开/关闭手电筒
【发布时间】:2019-09-18 23:53:08
【问题描述】:

我正在使用react-native-qrcode-scanner,我想做的是:当用户按下手电筒图标 flashLight 继续 我这样做了:

<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 }}

相机道具作品 但是当我改变 state.flashLight(真或假)时,闪光灯不会改变

任何想法如何改变相机道具的状态??

【问题讨论】:

  • 您是否尝试在点击图标后使用this.scanner.reactivate()

标签: android react-native flashlight


【解决方案1】:

尝试替换:

RNCamera.Constants.FlashMode.on

与:

RNCamera.Constants.FlashMode.torch

手电筒现在打开了吗?

【讨论】:

    【解决方案2】:

    使用 react-native-qrcode-scanner 版本 1.2.2 或更高版本

    尝试使用 flashMode 而不是 cameraProps

    这是一个工作示例:

          <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 是一个布尔变量,用于设置闪光灯的开启或关闭。

    有关更多信息,请阅读 Methods > flashMode

    上的 Github repo 描述

    【讨论】:

      猜你喜欢
      • 2019-11-18
      • 1970-01-01
      • 1970-01-01
      • 2015-12-20
      • 1970-01-01
      • 2019-10-05
      • 1970-01-01
      • 2014-06-17
      • 1970-01-01
      相关资源
      最近更新 更多