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

引入第三方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;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容