Skip to content

Instantly share code, notes, and snippets.

@aloukissas
Created January 31, 2019 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aloukissas/5ada682c42805fcee7550003bce68885 to your computer and use it in GitHub Desktop.
Save aloukissas/5ada682c42805fcee7550003bce68885 to your computer and use it in GitHub Desktop.
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