remobile / react-native-qrcode-local-image

A local qrcode image parse for react-native
MIT License
55 stars 72 forks source link

React Native QRCodeLocalImage (remobile)

A local qrcode image parse for react-native, support for ios and android

Installation

npm install @remobile/react-native-qrcode-local-image --save

Installation (iOS)

Installation (Android)

...
include ':react-native-qrcode-local-image'
project(':react-native-qrcode-local-image').projectDir = new File(settingsDir, '../node_modules/@remobile/react-native-qrcode-local-image/android')
...
dependencies {
    ...
    compile project(':react-native-qrcode-local-image')
}
......
import com.remobile.qrcodeLocalImage.RCTQRCodeLocalImagePackage;  // <--- import

......

@Override
protected List<ReactPackage> getPackages() {
   ......
   new RCTQRCodeLocalImagePackage()              // <------ add here
   ......
}

Usage

Example

'use strict';

var React = require('react');
var ReactNative = require('react-native');
var {
    StyleSheet,
    View,
    Text,
} = ReactNative;

var Button = require('@remobile/react-native-simple-button');
var QRCode = require('@remobile/react-native-qrcode-local-image');

module.exports = React.createClass({
    getInitialState() {
        return {text: ''}
    },
    onPress() {
        QRCode.decode(!app.isandroid?'/Users/fang/Desktop/qr.png':'/sdcard/qr.png', (error, result)=>{
            this.setState({text: JSON.stringify({error, result})});
        });
    },
    render() {
        return (
            <View style={styles.container}>
                <Button onPress={this.onPress}>测试</Button>
                <Text>
                    {this.state.text}
                </Text>
            </View>
        );
    }
});

var styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: 'transparent',
        justifyContent: 'space-around',
        paddingVertical: 150,
    },
});

method

see detail use