我创建了工作示例来共享多个或单个图像反应本机共享 https://react-native-share.github.io/react-native-share/docs/share-open
在这里查看 ExpoSnack https://snack.expo.io/@klakshman318/sharemultiorsingleimagesrn
在每个方法之前添加注释,说明它将做什么以及需要替换什么。
// multiple images share example
const shareMultipleImages = async () => {
const shareOptions = {
title: 'Share multiple files example',
// here replace base64 data with your local filepath
// base64 with mimeType or path to local file
urls: [base64ImagesData.image1, base64ImagesData.image2],
failOnCancel: false,
};
// If you want, you can use a try catch, to parse
// the share response. If the user cancels, etc.
try {
const ShareResponse = await Share.open(shareOptions);
setResult(JSON.stringify(ShareResponse, null, 2));
} catch (error) {
console.log('Error =>', error);
setResult('error: '.concat(getErrorString(error)));
}
};
您可以在 shareMultipleImage 方法中添加本地文件路径,如下所示
urls:您要共享的 Base64 字符串数组。使用 mimeType 或本地文件路径的 base64 (Array[string])
React Native 共享文档 https://react-native-share.github.io/react-native-share/docs/share-open
const shareOptions = {
title: 'Share multiple files example',
urls: ["file..///","file..///","file..///"],
failOnCancel: false,
};