React-Native(2)--第三方库

2016-11-15  本文已影响0人  尘土的味道

引入第三方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;
上一篇 下一篇

猜你喜欢

热点阅读