我正在努力做出反应本地分享。现在我可以与标题和消息共享图像。虽然我正在分享图片,但它有点慢。所以我想我需要优化图像文件大小。那么如何做好反应原生。我正在使用react-native-fetch-blob
这是我的工作代码。我如何使用此代码进行优化。
提前致谢
_downloadImageAndShare(url ,title, message) {
const { fs } = RNFetchBlob.fs;
const self = this;
let filePath = null;
RNFetchBlob.config({ fileCache: true })
.fetch('GET', url)
.then(resp => resp.readFile('base64')
.then(base64 => ({ resp, base64 })))
.then(obj => {
filePath = obj.resp.path();
const headers = obj.resp.respInfo.headers;
const type = headers['Content-Type'];
const dataUrl = 'data:' + type + ';base64,' + obj.base64;
RNFetchBlob.fs.unlink(filePath)
return { url: dataUrl, title, message };
})
.then(options => Share.open(options)).catch(err => {err && console.log(err); })
}