From f922e1650df550b3dec2f010ffdc6c15ea11390d Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Fri, 15 Mar 2024 16:34:42 +0000 Subject: fix(mobile): Bump expo-share-intent version and remove the hacks around the old version --- apps/mobile/app/_layout.tsx | 50 ++++++++++++++++++++------------------------- apps/mobile/app/sharing.tsx | 21 ++++--------------- 2 files changed, 26 insertions(+), 45 deletions(-) (limited to 'apps/mobile/app') 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 ( - - - - - + + + - - - - + > + + + + + + + ); } 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; -- cgit v1.2.3-70-g09d2