扫描代码和错误未定义不是一个对象



我想设置对EAN13代码的扫描,我使用的是react原生相机包,但我遇到了**

TypeError:undefined不是对象(正在评估'_reactNativeCamera.Camer.constants'(

**,我希望您能帮助我找出代码中的错误所在。

如果你能指导我,帮助我,那就太好了,非常感谢。

import React, { Component } from 'react';
import {
Text,
View,
Alert,
TouchableOpacity,
Image
} from 'react-native';
import {Camera} from 'react-native-camera';
import styles from '../../../assets/styles'
export default class Ean13 extends Component {
constructor(props) {
super(props);
this.handleTourch = this.handleTourch.bind(this);
this.state = {
torchOn: false
}
}
onBarCodeRead = (e) => {
Alert.alert("Barcode value is" + e.data, "Barcode type is" + e.type);
}
render() {
return (
<View style={styles.container}>
<Camera
style={styles.preview}
torchMode={this.state.torchOn ? Camera.constants.TorchMode.on : Camera.constants.TorchMode.off}
onBarCodeRead={this.onBarCodeRead}
ref={cam => this.camera = cam}
aspect={Camera.constants.Aspect.fill}
>
<Text style={{
backgroundColor: 'white'
}}>BARCODE SCANNER</Text>
</Camera>
<View style={styles.bottomOverlay}>
<TouchableOpacity onPress={() => this.handleTourch(this.state.torchOn)}>
<Image style={styles.cameraIcon}
source={this.state.torchOn === true ? require('../../../assets/images/flash.png') : require('../../../assets/images/no-flash.png')} />
</TouchableOpacity>
</View>
</View>
)
}
handleTourch(value) {
if (value === true) {
this.setState({ torchOn: false });
} else {
this.setState({ torchOn: true });
}
}
}

您已使用相机

这应该是RNCamera

import { RNCamera } from 'react-native-camera';

并从中读取常数

RNCamera.constants.TorchMode.on

检查文档https://github.com/react-native-camera/react-native-camera/blob/master/docs/RNCamera.md

相关内容

最新更新