简体   繁体   English

反应本机摄像头,onBarCodeRead不起作用

[英]react native camera, onBarCodeRead not working

react native camera, onBarCodeRead not working, i have installed react-native-camera, the code trigger the cammera, but it doesnot read or spot barcode even with onBarCodeRead function. 反应本地相机,onBarCodeRead无法正常工作,我已经安装了react-native-camera,代码触发了摄像头,但是即使使用onBarCodeRead功能,它也不会读取或识别条形码。 The below is my code and screenshoot 以下是我的代码和截图

 import React, { Component } from 'react';
 import { Image, Platform } from 'react-native';
 import { connect } from 'react-redux';
 import { Actions } from 'react-native-router-flux';
 import { Container, Header, Title, Content, Button, Icon, List, ListItem, Text, Footer, Left, Right, Body } from 'native-base';

 import styles from './styles';
 import { UserLogin, username,password} from '../../actions/index.js';
 import Spinner from 'react-native-loading-spinner-overlay';
 import Camera from 'react-native-camera';
 const glow2 = require('../../../images/glow2.png');

 const backgroundImage = require('../../../images/glow2.png');
 const logo = require('../../../images/logo.png');
 class Qrcamera extends Component {
  render() {
   return (
     <Container style={{ backgroundColor: '#fff' }}>
       <Image source={glow2} style={styles.container} >

      <Header style={{ backgroundColor: '#004774' }} >
        <Left>
          <Button transparent onPress={this.props.openDrawer} >
            <Icon active name="menu" style={{ fontSize: 30, lineHeight: 32 }} />
          </Button>
        </Left>
        <Body>
          <Title>Scanner</Title>
        </Body>
        <Right />

      </Header>

      <Content padder style={{ backgroundColor: 'transparent' }}>

        <Camera
      ref={(cam) => {
        this.camera = cam;
      }}
      style={styles.preview}
      aspect={Camera.constants.Aspect.fill}
      onBarCodeRead={this._bacr()}
      barCodeTypes={['org.iso.QRCode']}
      >

    </Camera>


      </Content>


    </Image>
    </Container>
  );
}
 _bacr(){
    alert("hey sported barcode!");
 }

}

export default connect()(Qrcamera);

enter image description here 在此处输入图片说明

Translation 翻译

Isn't that you just declared your barCodeTypes wrong? 您不是刚刚声明了barCodeTypes错误吗? Mine is like this for reading QR-Code: 我的是这样阅读QR代码:

barCodeTypes={[Camera.constants.BarCodeType.qr]}

and it works just fine. 而且效果很好。 Change your barCodeTypes into this and try it again and just make sure that change this: 将您的barCodeTypes更改为此,然后再试一次,并确保更改此内容:

onBarCodeRead={this._bacr()}

into this: 到这个:

onBarCodeRead={this._bacr.bind(this)}

or: 要么:

onBarCodeRead={()=>{this._bacr()}}

otherwise, when your camera reads a QRcode it won't fire up the function. 否则,当您的相机读取QR码时,不会启动该功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM