如何在 React-Native 中共享生成的二维码? [英] How to share generated qr code in React-Native?

查看:58
本文介绍了如何在 React-Native 中共享生成的二维码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用react-native-qrcode-svg"生成了二维码,我想通过电子邮件或类似的方式使用 react-native 的共享模块共享此 svg.

I generated QR code using 'react-native-qrcode-svg', and I want to share this svg thru email or something like that using Share module of react-native.

import { Share } from 'react-native';
import QRCode from 'react-native-qrcode-svg';
render() {
    return (
        ....
        <QRCode
                color="#090909"
                value={this.props.myCode}
                size={150}
            />
       )
    }
....

 onPress = {()=>{
        Share.share({
             message: 'How I will send QR code image?'                          
             title: 'QR code',
        });
....

我想我需要获取 svg 文件句柄并将其设置为共享模块,但想查看示例代码.

I guess that I need to get svg file handle and set it to the share module, but want to see sample code.

推荐答案

解决方案.终于知道怎么分享二维码了.

Solution. Finally able to figure out how to share qr code.

import QRCode from 'react-native-qrcode-svg';
 <QRCode
          value={JSON.stringify({test: 'testdata'})}
          getRef={c => (this.svg = c)}
        />
        <TouchableOpacity onPress={this.saveQRCode}>
          <View style={styles.instructions}>
            <Text>Share QR code</Text>
          </View>
        </TouchableOpacity>


saveQRCode = () => {
    this.svg.toDataURL(this.callback);
  };



callback(dataURL) {
    console.log(dataURL);
    let shareImageBase64 = {
      title: 'React Native',
      url: `data:image/png;base64,${dataURL}`,
      subject: 'Share Link', //  for email
    };
    Share.open(shareImageBase64).catch(error => console.log(error));
  }

这篇关于如何在 React-Native 中共享生成的二维码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆