diff options
| -rw-r--r-- | apps/mobile/app/_layout.tsx | 50 | ||||
| -rw-r--r-- | apps/mobile/app/sharing.tsx | 21 | ||||
| -rw-r--r-- | apps/mobile/lib/last-shared-intent.ts | 15 | ||||
| -rw-r--r-- | apps/mobile/package.json | 5 | ||||
| -rw-r--r-- | pnpm-lock.yaml | 11 |
5 files changed, 32 insertions, 70 deletions
diff --git a/apps/mobile/app/_layout.tsx b/apps/mobile/app/_layout.tsx index b338af5e..9f8f8ad5 100644 --- a/apps/mobile/app/_layout.tsx +++ b/apps/mobile/app/_layout.tsx @@ -5,48 +5,42 @@ import { useEffect } from "react"; import { View } from "react-native"; import { useRouter } from "expo-router"; import { Stack } from "expo-router/stack"; -import { useShareIntent } from "expo-share-intent"; +import { ShareIntentProvider, useShareIntent } from "expo-share-intent"; import { StatusBar } from "expo-status-bar"; -import { useLastSharedIntent } from "@/lib/last-shared-intent"; import { Providers } from "@/lib/providers"; export default function RootLayout() { const router = useRouter(); - const { hasShareIntent, shareIntent, resetShareIntent } = useShareIntent(); - - const lastSharedIntent = useLastSharedIntent(); + const { hasShareIntent } = useShareIntent(); useEffect(() => { - const intentJson = JSON.stringify(shareIntent); - if (hasShareIntent && !lastSharedIntent.isPreviouslyShared(intentJson)) { - // TODO: Remove once https://github.com/achorein/expo-share-intent/issues/14 is fixed - lastSharedIntent.setIntent(intentJson); + if (hasShareIntent) { router.replace({ pathname: "sharing", - params: { shareIntent: intentJson }, }); - resetShareIntent(); } }, [hasShareIntent]); return ( - <Providers> - <View className="h-full w-full bg-white"> - <Stack - screenOptions={{ - headerShown: false, - }} - > - <Stack.Screen name="index" /> - <Stack.Screen - name="sharing" - options={{ - presentation: "modal", + <ShareIntentProvider> + <Providers> + <View className="h-full w-full bg-white"> + <Stack + screenOptions={{ + headerShown: false, }} - /> - </Stack> - <StatusBar style="auto" /> - </View> - </Providers> + > + <Stack.Screen name="index" /> + <Stack.Screen + name="sharing" + options={{ + presentation: "modal", + }} + /> + </Stack> + <StatusBar style="auto" /> + </View> + </Providers> + </ShareIntentProvider> ); } diff --git a/apps/mobile/app/sharing.tsx b/apps/mobile/app/sharing.tsx index f9f423b5..e8b0ad09 100644 --- a/apps/mobile/app/sharing.tsx +++ b/apps/mobile/app/sharing.tsx @@ -1,8 +1,7 @@ -import type { ShareIntent } from "expo-share-intent"; -import { useEffect, useMemo, useState } from "react"; +import { useEffect, useState } from "react"; import { Text, View } from "react-native"; -import { Link, useLocalSearchParams, useRouter } from "expo-router"; -import { useShareIntent } from "expo-share-intent"; +import { Link, useRouter } from "expo-router"; +import { useShareIntentContext } from "expo-share-intent"; import { api } from "@/lib/trpc"; import { z } from "zod"; @@ -12,19 +11,7 @@ type Mode = | { type: "error" }; function SaveBookmark({ setMode }: { setMode: (mode: Mode) => void }) { - // Desperate attempt to fix sharing duplication - const { hasShareIntent, resetShareIntent } = useShareIntent(); - - const params = useLocalSearchParams(); - - const shareIntent = useMemo(() => { - if (params?.shareIntent) { - if (typeof params.shareIntent === "string") { - return JSON.parse(params.shareIntent) as ShareIntent; - } - } - return null; - }, [params]); + const { hasShareIntent, shareIntent, resetShareIntent } = useShareIntentContext(); const invalidateAllBookmarks = api.useUtils().bookmarks.getBookmarks.invalidate; diff --git a/apps/mobile/lib/last-shared-intent.ts b/apps/mobile/lib/last-shared-intent.ts deleted file mode 100644 index 951bcf74..00000000 --- a/apps/mobile/lib/last-shared-intent.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { create } from "zustand"; - -interface LastSharedIntent { - lastIntent: string; - setIntent: (intent: string) => void; - isPreviouslyShared: (intent: string) => boolean; -} - -export const useLastSharedIntent = create<LastSharedIntent>((set, get) => ({ - lastIntent: "", - setIntent: (intent: string) => set({ lastIntent: intent }), - isPreviouslyShared: (intent: string) => { - return get().lastIntent === intent; - }, -})); diff --git a/apps/mobile/package.json b/apps/mobile/package.json index 71dff6cc..b35c420c 100644 --- a/apps/mobile/package.json +++ b/apps/mobile/package.json @@ -26,7 +26,7 @@ "expo-linking": "~6.2.2", "expo-router": "~3.4.8", "expo-secure-store": "^12.8.1", - "expo-share-intent": "^1.0.1", + "expo-share-intent": "^1.1.0", "expo-status-bar": "~1.11.1", "expo-web-browser": "^12.8.2", "lucide-react-native": "^0.354.0", @@ -40,8 +40,7 @@ "react-native-svg": "^15.1.0", "tailwind-merge": "^2.2.1", "use-debounce": "^10.0.0", - "zod": "^3.22.4", - "zustand": "^4.5.1" + "zod": "^3.22.4" }, "devDependencies": { "@babel/core": "^7.20.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5babfe60..696c318d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -180,8 +180,8 @@ importers: specifier: ^12.8.1 version: 12.8.1(expo@50.0.11) expo-share-intent: - specifier: ^1.0.1 - version: 1.0.1(expo-constants@15.4.5)(expo-linking@6.2.2)(expo@50.0.11)(react-native@0.73.4)(react@18.2.0) + specifier: ^1.1.0 + version: 1.1.0(expo-constants@15.4.5)(expo-linking@6.2.2)(expo@50.0.11)(react-native@0.73.4)(react@18.2.0) expo-status-bar: specifier: ~1.11.1 version: 1.11.1 @@ -224,9 +224,6 @@ importers: zod: specifier: ^3.22.4 version: 3.22.4 - zustand: - specifier: ^4.5.1 - version: 4.5.1(@types/react@18.2.58)(react@18.2.0) devDependencies: '@babel/core': specifier: ^7.20.0 @@ -9651,8 +9648,8 @@ packages: expo: 50.0.11(@babel/core@7.23.9)(@react-native/babel-preset@0.73.21) dev: false - /expo-share-intent@1.0.1(expo-constants@15.4.5)(expo-linking@6.2.2)(expo@50.0.11)(react-native@0.73.4)(react@18.2.0): - resolution: {integrity: sha512-dMPoyEZlqKTS5FdQEytmnPHBXqHiXzzzzxuZ1p5S0AXJgZKeQ4mQspd6aLu7t+pt9T2l8yomtyUGBWagG3QNbw==} + /expo-share-intent@1.1.0(expo-constants@15.4.5)(expo-linking@6.2.2)(expo@50.0.11)(react-native@0.73.4)(react@18.2.0): + resolution: {integrity: sha512-k/epm+kmnrfEYHuEWaMeEZb+mBJklyTUoV5gD1wkXiwsK0TSh3Gp8G8xvKnB70RUiAv0/Yhbm15MsxtVZR6GwQ==} peerDependencies: expo: '>=50.0.0' expo-constants: '>=14.4.2' |
