引入第三方RN插件##
以react-native-camera(摄像头二维码相关应用)为例
安装插件,关联插件,简单方便###
npm install react-native-camera@https://github.com/lwansbrough/react-native-camera.git --save
react-native link
react-native-camera因为这个使用到摄像头所以在ios10+需要设置info
Privacy - Camera Usage Description
使用例子
/**
* Created by luxiaolong on 16/10/25.
*/
'use strict';
import React from 'react';
import {
StyleSheet,
View,
Text,
TouchableOpacity,
VibrationIOS,
} from 'react-native';
import Camera from 'react-native-camera';
var QRCodeScreen = React.createClass({
render: function() {
return (
<Camera onBarCodeRead={this._onBarCodeRead} style={styles.camera}>
<View style={styles.rectangleContainer}>
<View style={styles.rectangle}/>
</View>
{cancelButton}
</Camera>
);
},
_onBarCodeRead: function(result) {
var $this = this;
if (this.barCodeFlag) {
this.barCodeFlag = false;
setTimeout(function() {
VibrationIOS.vibrate();
console.log(result.data);
}, 1000);
}
}
});
module.exports = QRCodeScreen;
网友评论