RN 使用react-native-qrcode生成二维码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_37695006/article/details/82664824

生成二维码经常需要,分享一个插件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;

猜你喜欢

转载自blog.csdn.net/weixin_37695006/article/details/82664824
RN