[Android] Share.open always return success: false.
We are encountering an issue with the react-native-share library on Android where the share action is incorrectly flagged as "cancelled" despite the user successfully sharing content via email or other certain share targets. Here is the specific behavior:
Steps to reproduce
- Capture a screenshot or image using react-native-view-shot.
- Trigger the share dialog using react-native-share.open() with the email option or other share targets.
- Select the email share option and send the email successfully.
- The share is completed, but the result indicates that the user "cancelled" the action or "did not share."
Expected behavior
When the user shares via email (or other targets), the share should be successfully recorded as completed, and the appropriate event should be triggered, rather than being flagged as cancelled.
Actual behavior
The share action returns with an error message indicating that the user cancelled the action or did not share, even though the email has been sent successfully. Logs:
LOG User cancelled the share action LOG Captured URI: file:///data/user/0/......./cache/ReactNative-snapshot-image7710230649870402463.jpg ERROR Share failed: [Error: User did not share]
Environment
- React Native version: "react-native": "0.74.7"
- React Native platform + platform version: Android Pixel_6_API_30
react-native-share
Version: "12.0.9"
Code:
const onShare = useCallback(() => {
if (ref?.current?.capture) {
ref.current
.capture()
.then((uri) => {
return Share.open({
title: <TITLE>,
message: <URL>,
url: uri,
})
.then(() => {
<THIS_NEVER_GETS_EXECUTED> // even though the asset was successfully shared
})
.catch((error) => {
console.error('Share failed:', error);
});
})
.catch((error) => {
console.error('ViewShot capture failed:', error);
});
}
}, [.....]);
+1 bug
+1 bug
+1 bug
+1 bug
+1 bug
+1 bug, I have the same bug
Any update for this bug?
I gave on this bug and just do this now:
catch (error) {
if (error && typeof error === "object" && "message" in error) {
const errorMessage = (error as Error).message;
if (!errorMessage.includes("User did not share")) {
console.error("Error sharing CSV:", error);
}
}
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and i will leave this open