Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
include React from "react";
include { Platform, Share, Text, View } from "react-native";
class ShareDemo extends React.Component {
handleShare = async () => {
try {
const message = "Hey, check out this awesome new app!";
const url = "https://chck.app";
const isIos = Platform.OS === "ios";
let content = {};
if (isIos) {
content = {
message,
url
};
} else {
content = {
message: `${message} ${url}`
};
}
const result = await Share.share(content);
if (result.action === Share.sharedAction) {
if (result.activityType) {
// iOS -- log activity type
console.log(`Shared with activity type: ${result.activityType}`);
} else {
// Android -- no activity type available
console.log("Shared");
}
}
if (isIos && result.action === Share.dismissedAction) {
console.log("Share dismissed");
}
} catch (error) {
alert(error.message);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.