From 7efd8f3e04b152c1bcbd266d256ee8ee07dbe932 Mon Sep 17 00:00:00 2001 From: israr002 <66955016+israr002@users.noreply.github.com> Date: Wed, 2 Oct 2024 07:18:57 +0530 Subject: [PATCH] add share button in obs detail (#2209) --- .../ObsDetails/DetailsTab/DetailsTab.js | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/components/ObsDetails/DetailsTab/DetailsTab.js b/src/components/ObsDetails/DetailsTab/DetailsTab.js index b7281edd0..f9cf96a65 100644 --- a/src/components/ObsDetails/DetailsTab/DetailsTab.js +++ b/src/components/ObsDetails/DetailsTab/DetailsTab.js @@ -16,6 +16,7 @@ import { View } from "components/styledComponents"; import { t } from "i18next"; import type { Node } from "react"; import React from "react"; +import { Alert, Platform, Share } from "react-native"; import { useTheme } from "react-native-paper"; import { openExternalWebBrowser } from "sharedHelpers/util.ts"; @@ -27,15 +28,44 @@ type Props = { observation: Object } +const OBSERVATION_URL = "https://www.inaturalist.org/observations"; + +const handleShare = async url => { + const sharingOptions = { + url: "", + message: "" + }; + if ( Platform.OS === "ios" ) { + sharingOptions.url = url; + } else { + sharingOptions.message = url; + } + try { + return await Share.share( sharingOptions ); + } catch ( err ) { + Alert.alert( err.message ); + return null; + } +}; + const ViewInBrowserButton = ( { id } ) => ( openExternalWebBrowser( `https://www.inaturalist.org/observations/${id}` )} + onPress={async () => openExternalWebBrowser( `${OBSERVATION_URL}/${id}` )} > {t( "View-in-browser" )} ); +const ShareButton = ( { id } ) => ( + handleShare( `${OBSERVATION_URL}/${id}` )} + > + {t( "Share" )} + +); + const qualityGradeOption = option => { switch ( option ) { case "research": @@ -152,6 +182,7 @@ const DetailsTab = ( { currentUser, observation }: Props ): Node => { + );