Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shreejala-gurzu opened this issue Sep 6, 2022 · 12 comments

Comments

@shreejala-gurzu
Copy link

shreejala-gurzu commented Sep 6, 2022

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
Copy link

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

@alexkendall
Copy link

Same issue here.

@fukemy
Copy link

fukemy commented Nov 21, 2022

i removed clearReceivedFiles, dont know why, so bad lib

@Srinivas2445
Copy link

Srinivas2445 commented Dec 13, 2022

just comment AppState addEventListener

then place

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

without any conditions dont use clearReceivedFiles()

Now its working...

image

@nb-immosnapp
Copy link

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
Copy link

dhayaljaswantgit commented Mar 13, 2023

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
Copy link

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
Copy link

hsilvap commented Aug 2, 2023

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
Copy link

tallen11 commented Nov 6, 2023

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
Copy link

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

@TahirPK007
Copy link

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
Copy link

fukemy commented Dec 28, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests