最近写项目用到了二维码扫描,就去找了下,发现有个第三方的react-native-camera,支持android 和ios,功能还挺强大的,有兴趣的朋友可以去看下https://github.com/lwansbrough/react-native-camera。以下是我的自己写的一个仿微信样式写的二维码扫描。
npm install react-native-camera@https://github.com/lwansbrough/react-native-camera.git --save
react-native link react-native-camera
import React from 'react'; import { StyleSheet, TouchableOpacity, View, Text, InteractionManager, Animated, Easing, Platform, Image } from 'react-native'; import Camera from 'react-native-camera'; var Dimensions = require('Dimensions'); var {width, height} = Dimensions.get('window'); export default class CodeReading extends React.Component { constructor(props) { super(props); this.camera = null; this.state = { show:true, anim: new Animated.Value(0), camera: { aspect: Camera.constants.Aspect.fill, }, }; } componentDidMount(){ InteractionManager.runAfterInteractions(()=>{ this.startAnimation() }); } startAnimation(){ if(this.state.show