Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

appLinking.ts

31 lines1.2 KB

1import type { NavigationState, PartialState } from "@react-navigation/native";
2​
3/**
4 * The Expo dev client launches the app via
5 * <scheme>://expo-development-client/?url=<packager> — that URL addresses
6 * the launcher, not app navigation. Without this filter it falls through
7 * to the NotFound wildcard route on every dev launch.
8 */
9export function shouldHandleAppLink(url: string): boolean {
10 return (
11 !url.includes("expo-development-client") &&
12 !url.includes("://expo-sharing") &&
13 !/^t3code(-dev|-preview)?:\/*$/.test(url)
14 );
16​
17/** Keep the published draft URLs while using the root thread screen. */
18export function restoreDraftLinkState(
19 state: PartialState<NavigationState> | undefined,
20 path: string,
21) {
22 const pathname = path.split("?")[0]?.replace(/^\/+|\/+$/g, "");
23 if (!state || !pathname || !/^new\/draft(?:\/|$)/.test(pathname)) return state;
24 const target = state.routes.at(-1);
25 if (!target) return state;
26 const draft = target.params ?? {};
27 const routes = state.routes.slice(0, -1);
28 routes.push({ name: "Thread", params: { draft } });
29 if (pathname !== "new/draft") routes.push(target);
30 return { ...state, index: routes.length - 1, routes };