ajith-ab / react-native-receive-sharing-intent

A React Native plugin that enables React Native apps to receive sharing photos, videos, text, urls or any other file types from another app
MIT License
297 stars 106 forks source link

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

Open shreejala-gurzu opened 1 year ago

shreejala-gurzu commented 1 year ago

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.

hemantzarkar commented 1 year ago

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

alexkendall commented 1 year ago

Same issue here.

fukemy commented 1 year ago

i removed clearReceivedFiles, dont know why, so bad lib

Srinivas2445 commented 1 year ago

just comment AppState addEventListener

then place

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

without any conditions dont use clearReceivedFiles()

Now its working...

image

nb-immosnapp commented 1 year ago

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

dhayaljaswantgit commented 1 year ago

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.

ahmedbnr commented 1 year ago

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.

hsilvap commented 1 year ago

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!

tallen11 commented 9 months ago

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.

TahirPK007 commented 9 months ago

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

TahirPK007 commented 9 months ago

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

fukemy commented 8 months ago

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