【发布时间】:2022-01-10 10:57:31
【问题描述】:
例如,我有一个带有值的 SMS QRCode:
SMSTO:99999999:Hello World
我想生成一个 QR 码图像,以便能够与 react-native-share 共享它。我怎么能这样做?
【问题讨论】:
标签: javascript react-native qr-code
例如,我有一个带有值的 SMS QRCode:
SMSTO:99999999:Hello World
我想生成一个 QR 码图像,以便能够与 react-native-share 共享它。我怎么能这样做?
【问题讨论】:
标签: javascript react-native qr-code
步骤: 安装 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;
【讨论】: