0

反應原生攝像頭,onBarCodeRead不工作,我已經安裝了react-native-camera,代碼觸發cammera,但它甚至沒有讀取或識別條碼,即使使用onBarCodeRead函數。 下面是我的代碼和screenshoot反應原生攝像頭,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

回答

0

翻譯

不是你只是聲明瞭barCodeTypes錯了嗎? 我的是這樣的讀取QR碼:

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

和它工作得很好。更改barCodeTypes到這一點,並再次嘗試它,只是確保變革這一點:

onBarCodeRead={this._bacr()} 

成這樣:

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

或:

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

否則,當你的相機讀取QRcode不會觸發該功能。