Skip to content

Commit

Permalink
mobile: Add support for sharing text to the app
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Mar 13, 2024
1 parent e40a181 commit a80869c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/mobile/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"NSExtensionActivationSupportsWebURLWithMaxCount": 1,
"NSExtensionActivationSupportsWebPageWithMaxCount": 0,
"NSExtensionActivationSupportsImageWithMaxCount": 0,
"NSExtensionActivationSupportsMovieWithMaxCount": 0
"NSExtensionActivationSupportsMovieWithMaxCount": 0,
"NSExtensionActivationSupportsText": true
}
}
],
Expand Down
6 changes: 6 additions & 0 deletions packages/mobile/app/+not-found.tsx
Original file line number Diff line number Diff line change
@@ -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 />;
}
9 changes: 8 additions & 1 deletion packages/mobile/app/sharing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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 });
}
}
}, []);

Expand Down
3 changes: 2 additions & 1 deletion packages/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a80869c

Please sign in to comment.