diff --git a/apps/mobile/src/components/common/ModalSharedComponents.tsx b/apps/mobile/src/components/common/ModalSharedComponents.tsx index f12ae3fd9..675d805ab 100644 --- a/apps/mobile/src/components/common/ModalSharedComponents.tsx +++ b/apps/mobile/src/components/common/ModalSharedComponents.tsx @@ -1,6 +1,6 @@ import { withOpacity } from "@follow/utils" import { router } from "expo-router" -import { useMemo } from "react" +import { useCallback, useMemo } from "react" import { TouchableOpacity } from "react-native" import { useIsRouteOnlyOne } from "@/src/hooks/useIsRouteOnlyOne" @@ -21,8 +21,17 @@ const ModalHeaderCloseButtonImpl = () => { const routeOnlyOne = useIsRouteOnlyOne() const memoedRouteOnlyOne = useMemo(() => routeOnlyOne, []) + const handlePress = useCallback(() => { + if (router.canDismiss()) { + router.dismiss() + } else { + // If we can't dismiss, redirect to the root route + router.replace("/") + } + }, []) + return ( - router.dismiss()}> + {memoedRouteOnlyOne ? ( ) : ( diff --git a/apps/mobile/src/modules/feed/FollowFeed.tsx b/apps/mobile/src/modules/feed/FollowFeed.tsx index cd0c026e6..9eaa52967 100644 --- a/apps/mobile/src/modules/feed/FollowFeed.tsx +++ b/apps/mobile/src/modules/feed/FollowFeed.tsx @@ -104,6 +104,9 @@ function FollowImpl(props: { feedId: string }) { if (!routeOnlyOne) { parentRoute?.dispatch(StackActions.popToTop()) } + } else { + // If we can't dismiss, redirect to the root route + router.replace("/") } } diff --git a/apps/mobile/src/screens/+native-intent.tsx b/apps/mobile/src/screens/+native-intent.tsx new file mode 100644 index 000000000..13c09c233 --- /dev/null +++ b/apps/mobile/src/screens/+native-intent.tsx @@ -0,0 +1,23 @@ +// Redirects to the home screen when the app is opened with a deep link. +// Test this by running the following command in the terminal: +// pnpx uri-scheme open 'follow://add?id=1' --ios +// +// See https://docs.expo.dev/router/advanced/native-intent/#rewrite-incoming-native-deep-links + +export function redirectSystemPath(_options: { path: string; initial: boolean }) { + const { path } = _options + if (!_options.path) return + const parsedUrl = parseUrl(path) + if (!parsedUrl) return + const id = parsedUrl.searchParams.get("id") + if (!id) return + return `/follow?id=${id}` +} + +const parseUrl = (url: string) => { + try { + return new URL(url) + } catch { + return + } +}