React native React Native:下载文件时如何显示进度?

React native React Native:下载文件时如何显示进度?,react-native,fetch,React Native,Fetch,要求-我想显示一个累进指示器,显示加载完成的百分比。 我使用fetch进行api服务调用。是否有可能以任何方式获得下载完成百分比? 或者任何第三方库?您可以使用react native js coach查找特定搜索的包数 如需了解进度,可从以下链接使用: 这些都是第三方软件包。如果您想显示任何图像的下载进度,可以使用“react native fetch blob”。请参考下面的url了解更多信息 我已经解决了这个问题, 这是我用过的npm 谢谢,但我需要知道是否有一种方法可以使用fetch或

要求-我想显示一个累进指示器,显示加载完成的百分比。 我使用fetch进行api服务调用。是否有可能以任何方式获得下载完成百分比?
或者任何第三方库?

您可以使用react native js coach查找特定搜索的包数

如需了解进度,可从以下链接使用:


这些都是第三方软件包。

如果您想显示任何图像的下载进度,可以使用“react native fetch blob”。请参考下面的url了解更多信息

我已经解决了这个问题, 这是我用过的npm


谢谢,但我需要知道是否有一种方法可以使用fetch或其他方式在服务调用中接收完成回调。您是否正在寻找类似这样的解决方案:
在此,您可以直接添加从服务中获取的值OK,谢谢ankush。
downloadFile() {
  let dirs = RNFetchBlob.fs.dirs;
  const filePath = `${dirs.DocumentDir}`;
  var filename = this.state.invoiceUrl.substring(this.state.invoiceUrl.lastIndexOf('/')+1);
  RNFetchBlob.config({
      path:`${dirs.DownloadDir}/${filename}`,
      fileCache:false
      // addAndroidDownloads: {
      //     notification : true,
      //     useDownloadManager : true,
      //     description: 'TaxiJo Payment Invoice',
      //     mime:'application/pdf',
      //     mediaScannable:true,
      //     path:`${dirs.DownloadDir}/${filename}`
      // },
  })
  .fetch('GET',this.state.invoiceUrl,{
      'Cache-Control' : 'no-store'
  })
  .progress({ interval: 250 },(received,total)=>{
      console.log('progress',received/total);
      this.setState({
          downloadProgress:(received/total)*100
      })
  })
  .then(res=>{
      // RNFetchBlob.fs.stat(res.path()).then(stats=>{
      //     console.log(stats);
      // }).catch(err=>{
      //     console.log('error while getting mimetypes');
      // })
      this.setState({
          downloadProgress:0
      })
      // RNFetchBlob.fs.exists(res.path()).then(exist=>{
      //     console.log(`file ${exist ? '' : 'not'} exists`)
      // }).catch(
      //     err=>console.log('error while checking existance',err)
      // );
      if(Platform.OS === 'ios'){
          RNFetchBlob.ios.openDocument(res.path());
      }else{
          RNFetchBlob.android.actionViewIntent(res.path(),"application/pdf");
      }
  })
  .catch((errorMessage,statusCode)=>{
      console.log("error with downloading file",errorMessage)
  })
}