aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-03-13 16:35:17 +0000
committerMohamedBassem <me@mbassem.com>2024-03-13 16:35:17 +0000
commita80869cee9e841c319e603a51daa9cd34d1e83e8 (patch)
tree28baa59eea45ec846ea29ecaae8db9813143d1d9 /packages
parente40a18132119a90d9b4bf035ecf741b930342688 (diff)
downloadkarakeep-a80869cee9e841c319e603a51daa9cd34d1e83e8.tar.zst
mobile: Add support for sharing text to the app
Diffstat (limited to 'packages')
-rw-r--r--packages/mobile/app.json3
-rw-r--r--packages/mobile/app/+not-found.tsx6
-rw-r--r--packages/mobile/app/sharing.tsx9
-rw-r--r--packages/mobile/package.json3
4 files changed, 18 insertions, 3 deletions
diff --git a/packages/mobile/app.json b/packages/mobile/app.json
index 56773b57..96eb93a0 100644
--- a/packages/mobile/app.json
+++ b/packages/mobile/app.json
@@ -38,7 +38,8 @@
"NSExtensionActivationSupportsWebURLWithMaxCount": 1,
"NSExtensionActivationSupportsWebPageWithMaxCount": 0,
"NSExtensionActivationSupportsImageWithMaxCount": 0,
- "NSExtensionActivationSupportsMovieWithMaxCount": 0
+ "NSExtensionActivationSupportsMovieWithMaxCount": 0,
+ "NSExtensionActivationSupportsText": true
}
}
],
diff --git a/packages/mobile/app/+not-found.tsx b/packages/mobile/app/+not-found.tsx
new file mode 100644
index 00000000..466505b6
--- /dev/null
+++ b/packages/mobile/app/+not-found.tsx
@@ -0,0 +1,6 @@
+import { View } from "react-native";
+
+// This is kinda important given that the sharing modal always resolve to an unknown route
+export default function NotFound() {
+ return <View />;
+}
diff --git a/packages/mobile/app/sharing.tsx b/packages/mobile/app/sharing.tsx
index 41c3212e..59c6fc25 100644
--- a/packages/mobile/app/sharing.tsx
+++ b/packages/mobile/app/sharing.tsx
@@ -2,6 +2,7 @@ import { Link, useLocalSearchParams, useRouter } from "expo-router";
import { ShareIntent } from "expo-share-intent";
import { useEffect, useMemo, useState } from "react";
import { View, Text } from "react-native";
+import { z } from "zod";
import { api } from "@/lib/trpc";
@@ -27,7 +28,13 @@ function SaveBookmark({ setMode }: { setMode: (mode: Mode) => void }) {
useEffect(() => {
if (!isPending && shareIntent?.text) {
- mutate({ type: "link", url: shareIntent.text });
+ const val = z.string().url();
+ if (val.safeParse(shareIntent.text).success) {
+ // This is a URL, else treated as text
+ mutate({ type: "link", url: shareIntent.text });
+ } else {
+ mutate({ type: "text", text: shareIntent.text });
+ }
}
}, []);
diff --git a/packages/mobile/package.json b/packages/mobile/package.json
index 37cc5ee4..9a9198c7 100644
--- a/packages/mobile/package.json
+++ b/packages/mobile/package.json
@@ -35,7 +35,8 @@
"react-native-screens": "~3.29.0",
"react-native-svg": "^15.1.0",
"tailwind-merge": "^2.2.1",
- "use-debounce": "^10.0.0"
+ "use-debounce": "^10.0.0",
+ "zod": "^3.22.4"
},
"devDependencies": {
"@babel/core": "^7.20.0",