【问题标题】:react native camera, onBarCodeRead not working反应本机相机,onBarCodeRead 不起作用
【发布时间】:2017-07-19 19:50:08
【问题描述】:

react native camera,onBarCodeRead 不起作用,我已经安装了 react-native-camera,代码触发了摄像头,但即使使用 onBarCodeRead 功能,它也不会读取或发现条形码。 以下是我的代码和截图

 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

【问题讨论】:

    标签: javascript android react-native react-native-android react-native-camera


    【解决方案1】:

    翻译

    您不是刚刚声明了您的 barCodeTypes 错误吗? 我的是这样读取二维码的:

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

    它工作得很好。将您的 barCodeTypes 更改为此并再试一次,并确保更改此:

    onBarCodeRead={this._bacr()}
    

    进入这个:

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

    或:

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

    否则,当您的相机读取二维码时,它不会启动该功能。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-20
      • 2018-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-22
      相关资源
      最近更新 更多