react-native-camera-未定义不是对象(评估'_react.propTypes.oneOfType)

时间:2018-09-24 20:33:30

标签: reactjs react-native react-native-ios react-native-camera

我想在设备上打开条形码扫描仪项目,但是我对此有疑问。我认为,我在项目中以错误的方式导入了react-native-camera。您能帮我解决这个问题吗?

enter image description here

  • npm:6.4.1
  • react-native-cli:2.0.1
  • 本机:0.57.1

**

  

我的package.json文件:

**

{
  "name": "BarcodeScanner",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "^16.5.0",
    "react-native": "^0.57.1",
    "react-native-camera": "^0.6.0"
  },
  "devDependencies": {
    "babel-jest": "23.6.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.45.6",
    "react-test-renderer": "16.5.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

**

  

我的App.js文件:

import React, {Component,PropTypes} from 'react';
import {View,Text} from 'react-native';
import {RNCamera} from "react-native-camera";

class App extends Component{

  constructor(props) {
    super(props);
    this.state = {
      qrcode: ""
    };
  }

  onBarCodeRead = e => {
    this.setState({ qrcode: e.data });
  };

  render() {
    return (
      <View style={styles.container}>
        <RNCamera
          barCodeTypes={[RNCamera.props.BarCodeType.qr]}
          flashMode={RNCamera.props.FlashMode.on}
          style={styles.preview}
          onBarCodeRead={this.onBarCodeRead}
          ref={cam => (this.props = cam)}
        >
          <Text
            style={{
              backgroundColor: "white"
            }}
          >
            {this.props.qrcode}
          </Text>
        </RNCamera>
      </View>
    );
  }
}

const styles = {
  container: {
    flex: 1,
    flexDirection: "row"
  },
  preview: {
    flex: 1,
    justifyContent: "flex-end",
    alignItems: "center"
  }
}

export default App;

**

0 个答案:

没有答案