import {Alert, Linking} from 'react-native'; import Clipboard from '@react-native-community/clipboard'; export const postOnFacebook = (shareURL: string, shareMessage: any) => { let parameters = ''; if (shareURL != undefined) { parameters = parameters + '?u=' + encodeURI(shareURL); } if (shareMessage != undefined) { parameters = parameters + '"e=' + encodeURI(shareMessage); } let url = 'https://www.facebook.com/sharer/sharer.php' + parameters; Linking.openURL(url) .then((data) => {}) .catch(() => {}); }; export const postOnTwitter = (shareURL: string, shareMessage: any) => { let parameters = ''; if (shareURL != undefined) { parameters = parameters + '?url=' + encodeURI(shareURL); } if (shareMessage != undefined) { parameters = parameters + '&text=' + encodeURI(shareMessage); } let url = 'https://www.twitter.com/share/' + parameters; Linking.openURL(url) .then((data) => { console.log('Twitter Opened'); }) .catch(() => { console.log('Something went wrong'); }); }; export const copyUrl = (url: string, type: string) => { copyToClipboard(url, type); }; const copyToClipboard = (url: any, type: string) => { Clipboard.setString(url); Alert.alert( '', `${type} Copied!`, [ { text: 'Cancel', style: 'cancel', }, ], {cancelable: false}, ); };