react-native-receive-sharing-intent icon indicating copy to clipboard operation
react-native-receive-sharing-intent copied to clipboard

Can't receive the shared files after ReceiveSharingIntent.clearReceivedFiles( ) is called on unmount.

Open shreejala-gurzu opened this issue 2 years ago • 12 comments

useEffect(() => { ReceiveSharingIntent.getReceivedFiles( (data: any) => { console.log("received data", data); }, (err: any) => { console.log("err", err); }, ShareMedia, ); return () => { ReceiveSharingIntent.clearReceivedFiles(); }; }, []);

Initially, ReceiveSharingIntent.getReceivedFiles() returns the shared file. But after the clearReceivedFiles() function is called on unmount, ReceiveSharingIntent.getReceivedFiles() does not return any file on sharing. However, if we restart the app, it works just fine.

shreejala-gurzu avatar Sep 06 '22 10:09 shreejala-gurzu

The same behavior happens in my app. Please let me know the solution.

hemantzarkar avatar Sep 12 '22 10:09 hemantzarkar

Same issue here.

alexkendall avatar Oct 15 '22 23:10 alexkendall

i removed clearReceivedFiles, dont know why, so bad lib

fukemy avatar Nov 21 '22 03:11 fukemy

just comment AppState addEventListener

then place

this.getFileNames(handler,errorHandler, "");

without any conditions dont use clearReceivedFiles()

Now its working...

image

Srinivas2445 avatar Dec 13 '22 05:12 Srinivas2445

useEffect(() => { ReceiveSharingIntent.getReceivedFiles( (data: any) => { console.log("received data", data); }, (err: any) => { console.log("err", err); }, ShareMedia, ); return () => { ReceiveSharingIntent.clearReceivedFiles(); }; }, []);

Initially, ReceiveSharingIntent.getReceivedFiles() returns the shared file. But after the clearReceivedFiles() function is called on unmount, ReceiveSharingIntent.getReceivedFiles() does not return any file on sharing. However, if we restart the app, it works just fine.

please put ReceiveSharingIntent.clearFileNames() in clearRecivedFiles function of ReceiveSharingIntent.tsx file and comment the isClear=true so it will work with android image

nb-immosnapp avatar Jan 01 '23 08:01 nb-immosnapp

just comment AppState addEventListener

then place

this.getFileNames(handler,errorHandler, "");

without any conditions dont use clearReceivedFiles()

Now its working...

image

Thank you so much, this is the actual solution for the issue.

dhayaljaswantgit avatar Mar 13 '23 18:03 dhayaljaswantgit

useEffect(() => { ReceiveSharingIntent.getReceivedFiles( (data: any) => { console.log("received data", data); }, (err: any) => { console.log("err", err); }, ShareMedia, ); return () => { ReceiveSharingIntent.clearReceivedFiles(); }; }, []); Initially, ReceiveSharingIntent.getReceivedFiles() returns the shared file. But after the clearReceivedFiles() function is called on unmount, ReceiveSharingIntent.getReceivedFiles() does not return any file on sharing. However, if we restart the app, it works just fine.

please put ReceiveSharingIntent.clearFileNames() in clearRecivedFiles function of ReceiveSharingIntent.tsx file and comment the isClear=true so it will work with android image

This solution worked, but the thing is that this library has its fair share of bugs and unexpected behaviors. Is it still maintained? is there someone who's still merging fixes and releasing new versions? because as far as I know, this library is the only decent library that can do sharing intents without much hassle and without resorting to creating your own native library. but the problem is that it contains critical bugs that still aren't fixed and merged in a public release yet, it requires some internal fixes, for me I've externalized the package in my project and to be honest it's not really a good idea to throw an externalized and unmaintained library.

ahmedbnr avatar Mar 21 '23 13:03 ahmedbnr

just comment AppState addEventListener

then place

this.getFileNames(handler,errorHandler, "");

without any conditions dont use clearReceivedFiles()

Now its working...

image

This solution is working for me, thanks!

hsilvap avatar Aug 02 '23 15:08 hsilvap

useEffect(() => { ReceiveSharingIntent.getReceivedFiles( (data: any) => { console.log("received data", data); }, (err: any) => { console.log("err", err); }, ShareMedia, ); return () => { ReceiveSharingIntent.clearReceivedFiles(); }; }, []); Initially, ReceiveSharingIntent.getReceivedFiles() returns the shared file. But after the clearReceivedFiles() function is called on unmount, ReceiveSharingIntent.getReceivedFiles() does not return any file on sharing. However, if we restart the app, it works just fine.

please put ReceiveSharingIntent.clearFileNames() in clearRecivedFiles function of ReceiveSharingIntent.tsx file and comment the isClear=true so it will work with android image

This clearFileNames method is the solution. It's almost like the creator of this package implemented it and then forgot to expose it to the JS runtime and use it. I ended up cloning this repo and exposing clearFilesNames in ReceiveSharingIntent.ts and then calling it inside the getReceivedFiles callback once I've extracted the shared data.

Without doing this, every time you switch from another app to your app, the share listener will fire because the shared data never gets cleared.

tallen11 avatar Nov 06 '23 03:11 tallen11

im still facing the same issue after calling the clearReceivdFiles method i dont get new data until i reload the app

TahirPK007 avatar Nov 30 '23 07:11 TahirPK007

useEffect(() => { ReceiveSharingIntent.getReceivedFiles( (data: any) => { console.log("received data", data); }, (err: any) => { console.log("err", err); }, ShareMedia, ); return () => { ReceiveSharingIntent.clearReceivedFiles(); }; }, []); Initially, ReceiveSharingIntent.getReceivedFiles() returns the shared file. But after the clearReceivedFiles() function is called on unmount, ReceiveSharingIntent.getReceivedFiles() does not return any file on sharing. However, if we restart the app, it works just fine.

please put ReceiveSharingIntent.clearFileNames() in clearRecivedFiles function of ReceiveSharingIntent.tsx file and comment the isClear=true so it will work with android image

This clearFileNames method is the solution. It's almost like the creator of this package implemented it and then forgot to expose it to the JS runtime and use it. I ended up cloning this repo and exposing clearFilesNames in ReceiveSharingIntent.ts and then calling it inside the getReceivedFiles callback once I've extracted the shared data.

Without doing this, every time you switch from another app to your app, the share listener will fire because the shared data never gets cleared.

this didnt work for me im using the latest version of react native

TahirPK007 avatar Nov 30 '23 07:11 TahirPK007

useEffect(() => { ReceiveSharingIntent.getReceivedFiles( (data: any) => { console.log("received data", data); }, (err: any) => { console.log("err", err); }, ShareMedia, ); return () => { ReceiveSharingIntent.clearReceivedFiles(); }; }, []); Initially, ReceiveSharingIntent.getReceivedFiles() returns the shared file. But after the clearReceivedFiles() function is called on unmount, ReceiveSharingIntent.getReceivedFiles() does not return any file on sharing. However, if we restart the app, it works just fine.

please put ReceiveSharingIntent.clearFileNames() in clearRecivedFiles function of ReceiveSharingIntent.tsx file and comment the isClear=true so it will work with android image

this solution not working for IOS

fukemy avatar Dec 28 '23 01:12 fukemy