react-native-fs icon indicating copy to clipboard operation
react-native-fs copied to clipboard

RNFS.downloadFile is blocking the UI thread, Cannot do any action or navigation.

Open uday5162 opened this issue 4 years ago • 12 comments

uday5162 avatar Jul 16 '20 07:07 uday5162

Having this issue too. Any ideas?

newfylox avatar Aug 24 '20 16:08 newfylox

Don't know if it's the same bug but I've found something there https://github.com/itinance/react-native-fs/issues/920#issue-686529931

newfylox avatar Aug 26 '20 19:08 newfylox

Can you verify whether this pull request works [#794 (pull request)]

uday5162 avatar Aug 27 '20 03:08 uday5162

@uday5162 will try it today and this weekend. Thanks!

newfylox avatar Aug 28 '20 18:08 newfylox

@uday5162 I tried it and it worked perfectly on Android.

But on iOS, I cannot link my pods to my xCode project. It seems that you're PR is using version 2.16.1 and there is a bug with importing #import <React/RCTImageLoaderProtocol.h> because I am using React-Native 0.60.6 and not >= 0.61

You're PR should be a fix to all versions of RNFS. So my options are to use your PR and apply a patch after, or installing the right RNFS version to my project and apply your PR as a patch.

newfylox avatar Sep 01 '20 15:09 newfylox

I'm seeing this issue as well. It's especially bad on Android. I tried patching with the changes in https://github.com/itinance/react-native-fs/pull/794 but it didn't help.

rcscott avatar Oct 16 '20 19:10 rcscott

Try passing a value for the progressInterval param, e.g. 100.

From what I can tell, because the default value is 0 RNFS invokes the progress callback function every time it receives a bit of data, and that can overwhelm the UI thread (even though the downloader itself runs in its own thread).

P.S. The PR mentioned above deals with the proper cleaning up of callbacks and such. Thread spawning for downloads is already part of the current RNFS codebase.

P.P.S. Alternately, pass a value for progressDivider (say, 5) instead of progressInterval.

idrm avatar Oct 27 '20 19:10 idrm

I guess I solved my problem. Indeed passing progressInterval value helped, but also I found some errors in my code that could have solved my problem.

newfylox avatar Oct 28 '20 00:10 newfylox

@idrm it looks like the progressInterval and progressDivider params are only used when a progress callback is provided. Unfortunately I'm seeing UI blocking even without a progress callback, so specifying those params didn't solve the problem for me. This issue is most noticeable when trying to download a bunch of files at once, in my case I'm trying to download ~10 images.

https://github.com/itinance/react-native-fs/blob/f2f8f4a058cd9acfbcac3b8cf1e08fa1e9b09786/android/src/main/java/com/rnfs/Downloader.java#L119-L137

rcscott avatar Oct 28 '20 12:10 rcscott

Try passing a value for the progressInterval param, e.g. 100.

From what I can tell, because the default value is 0 RNFS invokes the progress callback function every time it receives a bit of data, and that can overwhelm the UI thread (even though the downloader itself runs in its own thread).

P.S. The PR mentioned above deals with the proper cleaning up of callbacks and such. Thread spawning for downloads is already part of the current RNFS codebase.

P.P.S. Alternately, pass a value for progressDivider (say, 5) instead of progressInterval.

Thanks bro, It solve my problem!!!

Quang-Dong avatar Dec 16 '20 07:12 Quang-Dong

Try passing a value for the progressInterval param, e.g. 100.

From what I can tell, because the default value is 0 RNFS invokes the progress callback function every time it receives a bit of data, and that can overwhelm the UI thread (even though the downloader itself runs in its own thread).

P.S. The PR mentioned above deals with the proper cleaning up of callbacks and such. Thread spawning for downloads is already part of the current RNFS codebase.

P.P.S. Alternately, pass a value for progressDivider (say, 5) instead of progressInterval.

Thanks mate. Been struggling with this for a whole day

arelstone avatar Jun 03 '21 09:06 arelstone

Any update?

nikunjdhamelia avatar Aug 03 '22 12:08 nikunjdhamelia

I am having the same problem! Does anyone know if this issue has been fixed?

alizhan1 avatar Nov 23 '22 15:11 alizhan1