【发布时间】:2018-06-28 04:59:16
【问题描述】:
我是原生反应的新手。我想使用'react-native-camera'。我创建了一个新项目,正确安装了包(我知道是因为我已经做了三次以确保我没有做错任何事情),它显示了这个错误**无法读取未定义的属性 'oneOfType' ** 和它在这个包'react-native-camera'的index.js中。我找不到任何解决方案。我已经尝试过更改 gradle 版本,gradle 包装器属性,但这个问题与 gradle 无关。这是我的 App.js 中的代码。我知道代码不会产生这个错误,但我是 react-native 的新手,所以我可能遗漏了一些东西。 任何建议将不胜感激
import React, {Component} from 'react';
import {
Text,
View,
StyleSheet
} from 'react-native';
import Camera from 'react-native-camera';
export default class BarcodeScan extends Component {
constructor(props) {
super(props);
this.state = {
qrcode: ''
}
}
onBarCodeRead = (e) => this.setState({qrcode: e.data});
render () {
return (
<View style={styles.container}>
<Camera
style={styles.preview}
onBarCodeRead={this.onBarCodeRead}
ref={cam => this.camera = cam}
aspect={Camera.constants.Aspect.fill}
>
<Text style={{
backgroundColor: 'white'
}}>{this.state.qrcode}</Text>
</Camera>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
},
preview: {
flex: 1,
justifyContent: 'flex-end',
alignItems: 'center'
}
});
【问题讨论】:
-
请问您使用的是什么“react”和“react-native-camera”版本?
-
由于您使用过 RCTCamera,请注意,从 1.0.0 开始,RCCTamera 已被弃用,但如果您想使用它,请使用此文档链接 github.com/react-native-community/react-native-camera/blob/…。您是否根据该链接进行了更改?请确认。
-
显示你的 package.json 文件。
标签: react-native react-native-camera