about summary refs log tree commit diff
path: root/src/lib/sharing.ts
diff options
context:
space:
mode:
authorAnsh <anshnanda10@gmail.com>2023-04-25 14:04:56 -0700
committerGitHub <noreply@github.com>2023-04-25 14:04:56 -0700
commitc8a7f27d43dc2ba926fd402a14bdcc35aec433da (patch)
tree67fc86709a16b43dd3c04b401a5bd0a7aed4b397 /src/lib/sharing.ts
parent01410ad4bfb5e49aa954ee2e65964a43b1aaf401 (diff)
parentd0d24ea248a74df89c0033a2f63787aaa2f0402d (diff)
downloadvoidsky-c8a7f27d43dc2ba926fd402a14bdcc35aec433da.tar.zst
Merge pull request #536 from bluesky-social/ansh/app-558-share-profile-and-post-broken-on-android
[APP-558] Sharing refactor
Diffstat (limited to 'src/lib/sharing.ts')
-rw-r--r--src/lib/sharing.ts22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lib/sharing.ts b/src/lib/sharing.ts
new file mode 100644
index 000000000..95ebf8ee9
--- /dev/null
+++ b/src/lib/sharing.ts
@@ -0,0 +1,22 @@
+import {isNative} from 'platform/detection'
+// import * as Sharing from 'expo-sharing'
+import Clipboard from '@react-native-clipboard/clipboard'
+import * as Toast from '../view/com/util/Toast'
+import {Share} from 'react-native'
+
+/**
+ * This function shares a URL using the native Share API if available, or copies it to the clipboard
+ * and displays a toast message if not (mostly on web)
+ * @param {string} url - A string representing the URL that needs to be shared or copied to the
+ * clipboard.
+ */
+export async function shareUrl(url: string) {
+  if (isNative) {
+    Share.share({url: url})
+  } else {
+    // React Native Share is not supported by web. Web Share API
+    // has increasing but not full support, so default to clipboard
+    Clipboard.setString(url)
+    Toast.show('Copied to clipboard')
+  }
+}