From a80869cee9e841c319e603a51daa9cd34d1e83e8 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Wed, 13 Mar 2024 16:35:17 +0000 Subject: mobile: Add support for sharing text to the app --- packages/mobile/app/+not-found.tsx | 6 ++++++ packages/mobile/app/sharing.tsx | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 packages/mobile/app/+not-found.tsx (limited to 'packages/mobile/app') 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 ; +} 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 }); + } } }, []); -- cgit v1.2.3-70-g09d2