1. 程式人生 > >RN 使用react-native-qrcode生成二維碼

RN 使用react-native-qrcode生成二維碼

生成二維碼經常需要,分享一個外掛react-native-qrcode

先npm install下,然後引用即可

npm install react-native-qrcode --save
import QRCode from 'react-native-qrcode';

一個demo:
 

import React, { Component } from 'react'
import QRCode from 'react-native-qrcode';
 
import {
    StyleSheet,
    View,
    TextInput
} from 'react-native';
 
class MFcode extends Component {
  state = {
    text: 'https://me.csdn.net/weixin_37695006',
  };
 
  render() {
    return (
      <View style={styles.container}>
        <TextInput
          style={styles.input}
          onChangeText={(text) => this.setState({text: text})}
          value={this.state.text}
        />
        <QRCode
          value={this.state.text}
          size={200}
          bgColor='purple'
          fgColor='white'/>
      </View>
    );
  };
}
 
const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: 'white',
        alignItems: 'center',
        justifyContent: 'center'
    },
 
    input: {
        height: 40,
        borderColor: 'gray',
        borderWidth: 1,
        margin: 10,
        borderRadius: 5,
        padding: 5,
    }
});

export default MFcode;