生成 QRCode 图像以从 QR 码值共享

Generate a QRCode image to share from a QR Code value

例如,我有一个短信二维码,其值为:

SMSTO:99999999:你好世界

我想生成一个二维码图像,这样我就可以用 react-native-share 分享它。我该怎么做?

步骤: 安装 react-native-qrcode-image

npm install git+https://github.com/Kishanjvaghela/react-native-qrcode-image.git --save

安装 react-native-share

npm install react-native-share --save

Link 它与应用

react-native link react-native-share

在您的组件中使用二维码

import QRCode from 'react-native-qrcode-image';
import Share from 'react-native-share';

class Dashboard extends React.Component {
  static navigationOptions = {
    title: Strings.dashboardTitle
  };

  constructor(props) {
    super(props);
    this.qrCode = '';
  }

  openShareScreen() {
    if (this.qrCode) {
      const shareOptions = {
        type: 'image/jpg',
        title: '',
        url: this.qrCode
      };
      Share.open(shareOptions)
        .then(res => console.log(res))
        .catch(err => console.error(err));
    }
  }

  render() {
    const { type, address } = this.state;
    return (
      <TouchableHighlight onPress={this.openShareScreen}>
        <View>
          <QRCode
            getBase64={base64 => {
              this.qrCode = base64;
            }}
            value={address}
            size={150}
            bgColor="#FFFFFF"
            fgColor="#000000"
          />
        </View>
      </TouchableHighlight>
    );
  }
}

export default Dashboard;

礼貌: