【问题标题】:Generate a QRCode image to share from a QR Code value [closed]生成 QRCode 图像以从 QR 码值共享 [关闭]
【发布时间】:2022-01-10 10:57:31
【问题描述】:

例如,我有一个带有值的 SMS QRCode:

SMSTO:99999999:Hello World

我想生成一个 QR 码图像,以便能够与 react-native-share 共享它。我怎么能这样做?

【问题讨论】:

标签: javascript react-native qr-code


【解决方案1】:

步骤: 安装 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

与应用关联

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;

礼貌:https://stackoverflow.com/a/53219478/17632251

【讨论】:

    猜你喜欢
    • 2011-12-15
    • 2011-07-08
    • 2011-05-31
    • 2011-10-24
    • 1970-01-01
    • 1970-01-01
    • 2013-12-23
    • 2012-12-24
    相关资源
    最近更新 更多