expo-router 0.0.9 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,33 +1,33 @@
1
- import { LinkingOptions, NavigationContainer } from "@react-navigation/native";
2
- import React from "react";
1
+ import { NavigationContainer, NavigationContainerRef } from '@react-navigation/native';
2
+ import React from 'react';
3
3
  declare type NavigationContainerProps = React.ComponentProps<typeof NavigationContainer>;
4
4
  export declare function useNavigationContainerContext(): [Partial<import("@react-navigation/native").NavigationContainerProps & {
5
5
  theme?: import("@react-navigation/native").Theme | undefined;
6
- linking?: LinkingOptions<{}> | undefined;
6
+ linking?: import("@react-navigation/native").LinkingOptions<{}> | undefined;
7
7
  fallback?: React.ReactNode;
8
8
  documentTitle?: import("@react-navigation/native").DocumentTitleOptions | undefined;
9
9
  onReady?: (() => void) | undefined;
10
10
  } & {
11
- ref?: React.Ref<import("@react-navigation/native").NavigationContainerRef<{}>> | undefined;
11
+ ref?: React.Ref<NavigationContainerRef<{}>> | undefined;
12
12
  }>, (props: Partial<import("@react-navigation/native").NavigationContainerProps & {
13
13
  theme?: import("@react-navigation/native").Theme | undefined;
14
- linking?: LinkingOptions<{}> | undefined;
14
+ linking?: import("@react-navigation/native").LinkingOptions<{}> | undefined;
15
15
  fallback?: React.ReactNode;
16
16
  documentTitle?: import("@react-navigation/native").DocumentTitleOptions | undefined;
17
17
  onReady?: (() => void) | undefined;
18
18
  } & {
19
- ref?: React.Ref<import("@react-navigation/native").NavigationContainerRef<{}>> | undefined;
19
+ ref?: React.Ref<NavigationContainerRef<{}>> | undefined;
20
20
  }>) => void];
21
21
  /** react-navigation `NavigationContainer` with automatic `linking` prop generated from the routes context. */
22
22
  export declare const ContextNavigationContainer: React.ForwardRefExoticComponent<Pick<import("@react-navigation/native").NavigationContainerProps & {
23
23
  theme?: import("@react-navigation/native").Theme | undefined;
24
- linking?: LinkingOptions<{}> | undefined;
24
+ linking?: import("@react-navigation/native").LinkingOptions<{}> | undefined;
25
25
  fallback?: React.ReactNode;
26
26
  documentTitle?: import("@react-navigation/native").DocumentTitleOptions | undefined;
27
27
  onReady?: (() => void) | undefined;
28
28
  } & {
29
- ref?: React.Ref<import("@react-navigation/native").NavigationContainerRef<{}>> | undefined;
30
- }, keyof import("@react-navigation/native").NavigationContainerProps | "theme" | "linking" | "fallback" | "documentTitle" | "onReady"> & React.RefAttributes<import("@react-navigation/native").NavigationContainerRef<{}>>>;
31
- export declare function RootContainer({ documentTitle, fallback, initialState, onStateChange, onUnhandledAction, theme }: Omit<NavigationContainerProps, 'independent' | 'onReady' | 'ref' | 'children' | 'linking'>): null;
29
+ ref?: React.Ref<NavigationContainerRef<{}>> | undefined;
30
+ }, keyof import("@react-navigation/native").NavigationContainerProps | "theme" | "linking" | "fallback" | "documentTitle" | "onReady"> & React.RefAttributes<NavigationContainerRef<{}>>>;
31
+ export declare function RootContainer({ documentTitle, fallback, onReady, initialState, onStateChange, onUnhandledAction, theme }: Omit<NavigationContainerProps, 'independent' | 'ref' | 'children' | 'linking'>): null;
32
32
  export {};
33
33
  //# sourceMappingURL=ContextNavigationContainer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContextNavigationContainer.d.ts","sourceRoot":"","sources":["../src/ContextNavigationContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,KAA+B,MAAM,OAAO,CAAC;AAIpD,aAAK,wBAAwB,GAAG,KAAK,CAAC,cAAc,CAChD,OAAO,mBAAmB,CAC7B,CAAC;AASF,wBAAgB,6BAA6B;;;;;;;;;;;;;;;;aAQ5C;AAUD,8GAA8G;AAC9G,eAAO,MAAM,0BAA0B;;;;;;;;4NA6BtC,CAAC;AAgBF,wBAAgB,aAAa,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,wBAAwB,EAAE,aAAa,GAAG,SAAS,GAAG,KAAK,GAAG,UAAU,GAAG,SAAS,CAAC,QAQ3M"}
1
+ {"version":3,"file":"ContextNavigationContainer.d.ts","sourceRoot":"","sources":["../src/ContextNavigationContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAoB,mBAAmB,EAAE,sBAAsB,EAAiB,MAAM,0BAA0B,CAAC;AACxH,OAAO,KAAsB,MAAM,OAAO,CAAC;AAM3C,aAAK,wBAAwB,GAAG,KAAK,CAAC,cAAc,CAChD,OAAO,mBAAmB,CAC7B,CAAC;AAIF,wBAAgB,6BAA6B;;;;;;;;;;;;;;;;aAQ5C;AAED,8GAA8G;AAC9G,eAAO,MAAM,0BAA0B;;;;;;;;yLAsBtC,CAAC;AAiDF,wBAAgB,aAAa,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,wBAAwB,EAAE,aAAa,GAAG,KAAK,GAAG,UAAU,GAAG,SAAS,CAAC,QAQxM"}
@@ -1,11 +1,8 @@
1
- import { NavigationContainer } from "@react-navigation/native";
2
- import React, { useMemo, useCallback } from "react";
3
- import { useRoutesContext } from "./context";
4
- import { getLinkingConfig } from "./getLinkingConfig";
5
- function useLinkingConfig() {
6
- const routes = useRoutesContext();
7
- return useMemo(() => getLinkingConfig(routes), [routes]);
8
- }
1
+ import { findFocusedRoute, NavigationContainer } from '@react-navigation/native';
2
+ import React, { useCallback } from 'react';
3
+ import { useLinkingConfig } from './getLinkingConfig';
4
+ import SplashModule from './splash';
5
+ import { VirtualRouteContext } from './useCurrentRoute';
9
6
  const NavigationContainerContext = React.createContext([{}, function () { }]);
10
7
  export function useNavigationContainerContext() {
11
8
  const context = React.useContext(NavigationContainerContext);
@@ -14,46 +11,55 @@ export function useNavigationContainerContext() {
14
11
  }
15
12
  return context;
16
13
  }
17
- let hideAsync;
18
- try {
19
- hideAsync =
20
- require("expo-splash-screen").hideAsync;
21
- // Automatically handle hiding the splash screen if expo-splash-screen is installed.
22
- }
23
- catch { }
24
14
  /** react-navigation `NavigationContainer` with automatic `linking` prop generated from the routes context. */
25
15
  export const ContextNavigationContainer = React.forwardRef((props, ref) => {
26
16
  const [state, setState] = React.useState({});
27
17
  const linking = useLinkingConfig();
28
18
  console.log('linking', linking);
29
- const onReady = useCallback(() => {
30
- props.onReady?.();
31
- if (hideAsync) {
32
- hideAsync();
33
- }
34
- }, [props.onReady]);
35
19
  return (React.createElement(NavigationContainerContext.Provider, { value: [
36
20
  {
37
21
  ...props,
38
22
  linking,
39
- onReady,
40
23
  ...state,
41
24
  },
42
25
  setState,
43
26
  ] },
44
27
  React.createElement(InternalContextNavigationContainer, { ref: ref })));
45
28
  });
29
+ function trimQuery(pathname) {
30
+ const queryIndex = pathname.indexOf('?');
31
+ if (queryIndex !== -1) {
32
+ return pathname.substring(0, queryIndex);
33
+ }
34
+ return pathname;
35
+ }
46
36
  const InternalContextNavigationContainer = React.forwardRef((props, ref) => {
47
37
  const [contextProps] = useNavigationContainerContext();
48
- return (
49
- // @ts-expect-error: children are required
50
- React.createElement(NavigationContainer, { ref: ref, ...props, ...contextProps }));
38
+ const [state, setState] = React.useState({ pathname: null, query: {} });
39
+ const onStateChange = useCallback((state) => {
40
+ if (state) {
41
+ const currentRoute = findFocusedRoute(state);
42
+ setState({ pathname: trimQuery(currentRoute?.path ?? '/'), query: currentRoute?.params ?? {} });
43
+ }
44
+ }, [setState]);
45
+ const navigationRef = React.useRef(null);
46
+ React.useImperativeHandle(ref, () => navigationRef.current, [navigationRef]);
47
+ return (React.createElement(VirtualRouteContext.Provider, { value: state },
48
+ React.createElement(NavigationContainer, { ...props, ...contextProps, ref: navigationRef, onReady: () => {
49
+ contextProps.onReady?.();
50
+ SplashModule?.hideAsync();
51
+ const initialState = navigationRef.current?.getRootState();
52
+ onStateChange(initialState);
53
+ }, onStateChange: (state) => {
54
+ contextProps.onStateChange?.(state);
55
+ onStateChange(state);
56
+ } })));
51
57
  });
52
- export function RootContainer({ documentTitle, fallback, initialState, onStateChange, onUnhandledAction, theme }) {
58
+ export function RootContainer({ documentTitle, fallback, onReady, initialState, onStateChange, onUnhandledAction, theme }) {
53
59
  const [, setProps] = useNavigationContainerContext();
54
60
  React.useEffect(() => {
55
- setProps({ documentTitle, fallback, initialState, onStateChange, onUnhandledAction, theme });
56
- }, [documentTitle, fallback, initialState, onStateChange, onUnhandledAction, theme]);
61
+ setProps({ documentTitle, fallback, onReady, initialState, onStateChange, onUnhandledAction, theme });
62
+ }, [documentTitle, fallback, onReady, initialState, onStateChange, onUnhandledAction, theme]);
57
63
  return null;
58
64
  }
59
65
  //# sourceMappingURL=ContextNavigationContainer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContextNavigationContainer.js","sourceRoot":"","sources":["../src/ContextNavigationContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAkB,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAMtD,SAAS,gBAAgB;IACrB,MAAM,MAAM,GAAG,gBAAgB,EAAE,CAAC;IAClC,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,0BAA0B,GAAG,KAAK,CAAC,aAAa,CAA0F,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;AAEvK,MAAM,UAAU,6BAA6B;IACzC,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,0BAA0B,CAAC,CAAC;IAC7D,IAAI,CAAC,OAAO,EAAE;QACV,MAAM,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;AACN,CAAC,CACJ,CAAC;AAEF,MAAM,UAAU,aAAa,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,KAAK,EAA8F;IACxM,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAG,6BAA6B,EAAE,CAAC;IAErD,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,QAAQ,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC,CAAC;IACjG,CAAC,EAAE,CAAC,aAAa,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,KAAK,CAAC,CAAC,CAAC;IAErF,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import { LinkingOptions, NavigationContainer } from \"@react-navigation/native\";\nimport React, { useMemo, useCallback } from \"react\";\nimport { useRoutesContext } from \"./context\";\nimport { getLinkingConfig } from \"./getLinkingConfig\";\n\ntype NavigationContainerProps = React.ComponentProps<\n typeof NavigationContainer\n>;\n\nfunction useLinkingConfig(): LinkingOptions<{}> {\n const routes = useRoutesContext();\n return useMemo(() => getLinkingConfig(routes), [routes]);\n}\n\nconst NavigationContainerContext = React.createContext<[Partial<NavigationContainerProps>, (props: Partial<NavigationContainerProps>) => void]>([{}, function () { }]);\n\nexport function useNavigationContainerContext() {\n const context = React.useContext(NavigationContainerContext);\n if (!context) {\n throw new Error(\n \"useNavigationContainerContext must be used within a NavigationContainerContext\"\n );\n }\n return context;\n}\n\nlet hideAsync: () => Promise<boolean> | undefined;\ntry {\n hideAsync =\n (require(\"expo-splash-screen\") as typeof import(\"expo-splash-screen\")).hideAsync;\n // Automatically handle hiding the splash screen if expo-splash-screen is installed.\n} catch { }\n\n\n/** react-navigation `NavigationContainer` with automatic `linking` prop generated from the routes context. */\nexport const ContextNavigationContainer = React.forwardRef(\n (props: NavigationContainerProps, ref: NavigationContainerProps[\"ref\"]) => {\n const [state, setState] = React.useState<Partial<NavigationContainerProps>>({});\n\n const linking = useLinkingConfig();\n console.log('linking', linking);\n const onReady = useCallback(() => {\n props.onReady?.();\n if (hideAsync) {\n hideAsync();\n }\n }, [props.onReady]);\n\n return (\n <NavigationContainerContext.Provider value={[\n {\n ...props,\n linking,\n onReady,\n ...state,\n },\n setState,\n ]}>\n <InternalContextNavigationContainer\n ref={ref}\n />\n </NavigationContainerContext.Provider>\n );\n }\n);\n\nconst InternalContextNavigationContainer = React.forwardRef(\n (props: {}, ref: NavigationContainerProps[\"ref\"]) => {\n const [contextProps] = useNavigationContainerContext();\n return (\n // @ts-expect-error: children are required\n <NavigationContainer\n ref={ref}\n {...props}\n {...contextProps}\n />\n );\n }\n);\n\nexport function RootContainer({ documentTitle, fallback, initialState, onStateChange, onUnhandledAction, theme }: Omit<NavigationContainerProps, 'independent' | 'onReady' | 'ref' | 'children' | 'linking'>) {\n const [, setProps] = useNavigationContainerContext();\n\n React.useEffect(() => {\n setProps({ documentTitle, fallback, initialState, onStateChange, onUnhandledAction, theme });\n }, [documentTitle, fallback, initialState, onStateChange, onUnhandledAction, theme]);\n\n return null;\n}"]}
1
+ {"version":3,"file":"ContextNavigationContainer.js","sourceRoot":"","sources":["../src/ContextNavigationContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAyC,MAAM,0BAA0B,CAAC;AACxH,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,YAAY,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAMxD,MAAM,0BAA0B,GAAG,KAAK,CAAC,aAAa,CAA0F,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;AAEvK,MAAM,UAAU,6BAA6B;IACzC,MAAM,O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AAE,KAAK,EAAkF;IACrM,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAG,6BAA6B,EAAE,CAAC;IAErD,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,QAAQ,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC,CAAC;IAC1G,CAAC,EAAE,CAAC,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,KAAK,CAAC,CAAC,CAAC;IAE9F,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import { findFocusedRoute, NavigationContainer, NavigationContainerRef, ParamListBase } from '@react-navigation/native';\nimport React, { useCallback } from 'react';\n\nimport { useLinkingConfig } from './getLinkingConfig';\nimport SplashModule from './splash';\nimport { VirtualRouteContext } from './useCurrentRoute';\n\ntype NavigationContainerProps = React.ComponentProps<\n typeof NavigationContainer\n>;\n\nconst NavigationContainerContext = React.createContext<[Partial<NavigationContainerProps>, (props: Partial<NavigationContainerProps>) => void]>([{}, function () { }]);\n\nexport function useNavigationContainerContext() {\n const context = React.useContext(NavigationContainerContext);\n if (!context) {\n throw new Error(\n \"useNavigationContainerContext must be used within a NavigationContainerContext\"\n );\n }\n return context;\n}\n\n/** react-navigation `NavigationContainer` with automatic `linking` prop generated from the routes context. */\nexport const ContextNavigationContainer = React.forwardRef(\n (props: NavigationContainerProps, ref: NavigationContainerProps[\"ref\"]) => {\n const [state, setState] = React.useState<Partial<NavigationContainerProps>>({});\n\n const linking = useLinkingConfig();\n console.log('linking', linking);\n\n return (\n <NavigationContainerContext.Provider value={[\n {\n ...props,\n linking,\n ...state,\n },\n setState,\n ]}>\n <InternalContextNavigationContainer\n ref={ref}\n />\n </NavigationContainerContext.Provider>\n );\n }\n);\n\nfunction trimQuery(pathname: string): string {\n const queryIndex = pathname.indexOf('?');\n if (queryIndex !== -1) {\n return pathname.substring(0, queryIndex);\n }\n return pathname;\n}\n\nconst InternalContextNavigationContainer = React.forwardRef(\n (props: {}, ref: NavigationContainerProps[\"ref\"]) => {\n const [contextProps] = useNavigationContainerContext();\n const [state, setState] = React.useState<{ pathname: string | null, query: Record<string, any> }>({ pathname: null, query: {} });\n\n const onStateChange = useCallback((state) => {\n if (state) {\n const currentRoute = findFocusedRoute(state);\n setState({ pathname: trimQuery(currentRoute?.path ?? '/'), query: currentRoute?.params ?? {} });\n }\n }, [setState]);\n\n const navigationRef = React.useRef<NavigationContainerRef<ParamListBase>>(null);\n\n React.useImperativeHandle(ref, () => navigationRef.current!, [navigationRef]);\n\n return (\n <VirtualRouteContext.Provider value={state}>\n { /* @ts-expect-error: children are required */}\n <NavigationContainer\n {...props}\n {...contextProps}\n ref={navigationRef}\n onReady={() => {\n contextProps.onReady?.();\n SplashModule?.hideAsync();\n const initialState = navigationRef.current?.getRootState();\n onStateChange(initialState);\n }}\n onStateChange={(state) => {\n contextProps.onStateChange?.(state);\n onStateChange(state);\n }}\n />\n </VirtualRouteContext.Provider>\n );\n }\n);\n\nexport function RootContainer({ documentTitle, fallback, onReady, initialState, onStateChange, onUnhandledAction, theme }: Omit<NavigationContainerProps, 'independent' | 'ref' | 'children' | 'linking'>) {\n const [, setProps] = useNavigationContainerContext();\n\n React.useEffect(() => {\n setProps({ documentTitle, fallback, onReady, initialState, onStateChange, onUnhandledAction, theme });\n }, [documentTitle, fallback, onReady, initialState, onStateChange, onUnhandledAction, theme]);\n\n return null;\n}"]}
@@ -2,4 +2,5 @@ import { LinkingOptions, PathConfigMap } from "@react-navigation/native";
2
2
  import { RouteNode } from "./Route";
3
3
  export declare function treeToReactNavigationLinkingRoutes(nodes: RouteNode[], parents?: string[]): PathConfigMap<{}>;
4
4
  export declare function getLinkingConfig(routes: RouteNode[]): LinkingOptions<{}>;
5
+ export declare function useLinkingConfig(): LinkingOptions<{}>;
5
6
  //# sourceMappingURL=getLinkingConfig.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getLinkingConfig.d.ts","sourceRoot":"","sources":["../src/getLinkingConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAYzE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAqBpC,wBAAgB,kCAAkC,CAChD,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,GAAE,MAAM,EAAO,GACrB,aAAa,CAAC,EAAE,CAAC,CAwBnB;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,cAAc,CAAC,EAAE,CAAC,CA0FxE"}
1
+ {"version":3,"file":"getLinkingConfig.d.ts","sourceRoot":"","sources":["../src/getLinkingConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAUzE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AA6BpC,wBAAgB,kCAAkC,CAChD,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,GAAE,MAAM,EAAO,GACrB,aAAa,CAAC,EAAE,CAAC,CAwBnB;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,cAAc,CAAC,EAAE,CAAC,CAuBxE;AAED,wBAAgB,gBAAgB,IAAI,cAAc,CAAC,EAAE,CAAC,CAGrD"}
@@ -1,9 +1,8 @@
1
- import * as Linking from "expo-linking";
2
- import Constants, { ExecutionEnvironment } from "expo-constants";
1
+ import { useMemo } from "react";
3
2
  import { getAllWebRedirects } from "./aasa";
4
- import getPathFromState from "./fork/getPathFromState";
5
- import getStateFromPath from "./fork/getStateFromPath";
6
3
  import { matchDeepDynamicRouteName, matchDynamicName, matchFragmentName, } from "./matchers";
4
+ import { addEventListener, getInitialURL, getRootURL, getPathFromState, getStateFromPath, } from "./linking";
5
+ import { useRoutesContext } from "./context";
7
6
  // `[page]` -> `:page`
8
7
  // `page` -> `page`
9
8
  function convertDynamicRouteToReactNavigation(name) {
@@ -41,11 +40,10 @@ export function treeToReactNavigationLinkingRoutes(nodes, parents = []) {
41
40
  return firstPass;
42
41
  }
43
42
  export function getLinkingConfig(routes) {
44
- const rootURL = Linking.createURL("/");
45
43
  return {
46
44
  prefixes: [
47
45
  /* your linking prefixes */
48
- rootURL,
46
+ getRootURL(),
49
47
  // This ensures that we can redirect correctly when the user comes from an associated domain
50
48
  // i.e. iOS Safari banner.
51
49
  ...getAllWebRedirects(),
@@ -58,67 +56,14 @@ export function getLinkingConfig(routes) {
58
56
  // This helps keep the native functionality working like the web functionality.
59
57
  // For example, if you had a root navigator where the first screen was `/settings` and the second was `/index`
60
58
  // then `/index` would be used on web and `/settings` would be used on native.
61
- async getInitialURL() {
62
- const url = await Promise.race([
63
- (async () => {
64
- const url = await Linking.getInitialURL();
65
- // NOTE(EvanBacon): This could probably be wrapped with the development boundary
66
- // since Expo Go is mostly just used in development.
67
- // Expo Go is weird and requires the root path to be `/--/`
68
- if (url &&
69
- Constants.executionEnvironment === ExecutionEnvironment.StoreClient) {
70
- const parsed = Linking.parse(url);
71
- // If the URL is defined (default in Expo Go dev apps) and the URL has no path:
72
- // `exp://192.168.87.39:19000/` then use the default `exp://192.168.87.39:19000/--/`
73
- if (parsed.path === null || ["", "/"].includes(parsed.path)) {
74
- return rootURL;
75
- }
76
- }
77
- // The path will be nullish in bare apps when the app is launched from the home screen.
78
- // TODO(EvanBacon): define some policy around notifications.
79
- return url ?? rootURL;
80
- })(),
81
- new Promise((resolve) =>
82
- // Timeout in 150ms if `getInitialState` doesn't resolve
83
- // Workaround for https://github.com/facebook/react-native/issues/25675
84
- setTimeout(() => resolve(rootURL), 150)),
85
- ]);
86
- return url;
87
- },
88
- subscribe: (listener) => {
89
- let callback = undefined;
90
- if (Constants.executionEnvironment === ExecutionEnvironment.StoreClient) {
91
- // This extra work is only done in the Expo Go app.
92
- callback = ({ url }) => {
93
- const parsed = Linking.parse(url);
94
- // If the URL is defined (default in Expo Go dev apps) and the URL has no path:
95
- // `exp://192.168.87.39:19000/` then use the default `exp://192.168.87.39:19000/--/`
96
- if (parsed.path === null || ["", "/"].includes(parsed.path)) {
97
- listener(rootURL);
98
- }
99
- else {
100
- listener(url);
101
- }
102
- };
103
- }
104
- else {
105
- callback = ({ url }) => listener(url);
106
- }
107
- const subscription = Linking.addEventListener("url", callback);
108
- // Storing this in a local variable stops Jest from complaining about import after teardown
109
- const removeEventListener = Linking.removeEventListener?.bind(Linking);
110
- return () => {
111
- // https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7
112
- if (subscription?.remove) {
113
- subscription.remove();
114
- }
115
- else {
116
- removeEventListener?.("url", callback);
117
- }
118
- };
119
- },
59
+ getInitialURL: getInitialURL,
60
+ subscribe: addEventListener,
120
61
  getStateFromPath,
121
62
  getPathFromState,
122
63
  };
123
64
  }
65
+ export function useLinkingConfig() {
66
+ const routes = useRoutesContext();
67
+ return useMemo(() => getLinkingConfig(routes), [routes]);
68
+ }
124
69
  //# sourceMappingURL=getLinkingConfig.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getLinkingConfig.js","sourceRoot":"","sources":["../src/getLinkingConfig.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC,OAAO,SAAS,EAAE,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,gBAAgB,MAAM,yBAAyB,CAAC;AACvD,OAAO,gBAAgB,MAAM,yBAAyB,CAAC;AACvD,OAAO,EACL,yBAAyB,EACzB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAGpB,sBAAsB;AACtB,mBAAmB;AACnB,SAAS,oCAAoC,CAAC,IAAY;IACxD,IAAI,yBAAyB,CAAC,IAAI,CAAC,EAAE;QACnC,OAAO,GAAG,C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,GAAG,CAAC,EAAE,GAAG,EAAmB,EAAE,EAAE;oBACtC,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBAClC,+EAA+E;oBAC/E,oFAAoF;oBACpF,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;wBAC3D,QAAQ,CAAC,OAAO,CAAC,CAAC;qBACnB;yBAAM;wBACL,QAAQ,CAAC,GAAG,CAAC,CAAC;qBACf;gBACH,CAAC,CAAC;aACH;iBAAM;gBACL,QAAQ,GAAG,CAAC,EAAE,GAAG,EAAmB,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;aACxD;YACD,MAAM,YAAY,GAAG,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE,QAAQ,CAEhD,CAAC;YAEd,2FAA2F;YAC3F,MAAM,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YAEvE,OAAO,GAAG,EAAE;gBACV,2FAA2F;gBAC3F,IAAI,YAAY,EAAE,MAAM,EAAE;oBACxB,YAAY,CAAC,MAAM,EAAE,CAAC;iBACvB;qBAAM;oBACL,mBAAmB,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;iBACxC;YACH,CAAC,CAAC;QACJ,CAAC;QACD,gBAAgB;QAChB,gBAAgB;KACjB,CAAC;AACJ,CAAC","sourcesContent":["import { LinkingOptions, PathConfigMap } from \"@react-navigation/native\";\nimport * as Linking from \"expo-linking\";\n\nimport Constants, { ExecutionEnvironment } from \"expo-constants\";\nimport { getAllWebRedirects } from \"./aasa\";\nimport getPathFromState from \"./fork/getPathFromState\";\nimport getStateFromPath from \"./fork/getStateFromPath\";\nimport {\n matchDeepDynamicRouteName,\n matchDynamicName,\n matchFragmentName,\n} from \"./matchers\";\nimport { RouteNode } from \"./Route\";\n\n// `[page]` -> `:page`\n// `page` -> `page`\nfunction convertDynamicRouteToReactNavigation(name: string) {\n if (matchDeepDynamicRouteName(name)) {\n return \"*\";\n }\n const dynamicName = matchDynamicName(name);\n\n if (dynamicName) {\n return `:${dynamicName}`;\n }\n\n if (name === \"index\" || matchFragmentName(name)) {\n return \"\";\n }\n\n return name;\n}\n\nexport function treeToReactNavigationLinkingRoutes(\n nodes: RouteNode[],\n parents: string[] = []\n): PathConfigMap<{}> {\n // TODO: Intercept errors, strip invalid routes, and warn instead.\n // Our warnings can be more helpful than upstream since we know the associated file name.\n const firstPass = nodes\n .map((node) => {\n const path = convertDynamicRouteToReactNavigation(node.route);\n\n if (!node.children.length) {\n return [node.route, path];\n }\n\n const screens = treeToReactNavigationLinkingRoutes(node.children, [\n ...parents,\n path,\n ]);\n\n return [node.route, { path, screens }] as const;\n })\n .reduce<PathConfigMap<{}>>((acc, [route, current]) => {\n acc[route] = current;\n return acc;\n }, {});\n\n return firstPass;\n}\n\nexport function getLinkingConfig(routes: RouteNode[]): LinkingOptions<{}> {\n const rootURL = Linking.createURL(\"/\");\n\n return {\n prefixes: [\n /* your linking prefixes */\n rootURL,\n\n // This ensures that we can redirect correctly when the user comes from an associated domain\n // i.e. iOS Safari banner.\n ...getAllWebRedirects(),\n ],\n config: {\n screens: treeToReactNavigationLinkingRoutes(routes),\n },\n // A custom getInitialURL is used on native to ensure the app always starts at\n // the root path if it's launched from something other than a deep link.\n // This helps keep the native functionality working like the web functionality.\n // For example, if you had a root navigator where the first screen was `/settings` and the second was `/index`\n // then `/index` would be used on web and `/settings` would be used on native.\n async getInitialURL(): Promise<string> {\n const url = await Promise.race<string>([\n (async () => {\n const url = await Linking.getInitialURL();\n\n // NOTE(EvanBacon): This could probably be wrapped with the development boundary\n // since Expo Go is mostly just used in development.\n\n // Expo Go is weird and requires the root path to be `/--/`\n if (\n url &&\n Constants.executionEnvironment === ExecutionEnvironment.StoreClient\n ) {\n const parsed = Linking.parse(url);\n // If the URL is defined (default in Expo Go dev apps) and the URL has no path:\n // `exp://192.168.87.39:19000/` then use the default `exp://192.168.87.39:19000/--/`\n if (parsed.path === null || [\"\", \"/\"].includes(parsed.path)) {\n return rootURL;\n }\n }\n // The path will be nullish in bare apps when the app is launched from the home screen.\n // TODO(EvanBacon): define some policy around notifications.\n return url ?? rootURL;\n })(),\n new Promise<string>((resolve) =>\n // Timeout in 150ms if `getInitialState` doesn't resolve\n // Workaround for https://github.com/facebook/react-native/issues/25675\n setTimeout(() => resolve(rootURL), 150)\n ),\n ]);\n return url;\n },\n subscribe: (listener) => {\n let callback: (({ url }: { url: string }) => void) | undefined =\n undefined;\n\n if (Constants.executionEnvironment === ExecutionEnvironment.StoreClient) {\n // This extra work is only done in the Expo Go app.\n callback = ({ url }: { url: string }) => {\n const parsed = Linking.parse(url);\n // If the URL is defined (default in Expo Go dev apps) and the URL has no path:\n // `exp://192.168.87.39:19000/` then use the default `exp://192.168.87.39:19000/--/`\n if (parsed.path === null || [\"\", \"/\"].includes(parsed.path)) {\n listener(rootURL);\n } else {\n listener(url);\n }\n };\n } else {\n callback = ({ url }: { url: string }) => listener(url);\n }\n const subscription = Linking.addEventListener(\"url\", callback) as\n | { remove(): void }\n | undefined;\n\n // Storing this in a local variable stops Jest from complaining about import after teardown\n const removeEventListener = Linking.removeEventListener?.bind(Linking);\n\n return () => {\n // https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7\n if (subscription?.remove) {\n subscription.remove();\n } else {\n removeEventListener?.(\"url\", callback);\n }\n };\n },\n getStateFromPath,\n getPathFromState,\n };\n}\n"]}
1
+ {"version":3,"file":"getLinkingConfig.js","sourceRoot":"","sources":["../src/getLinkingConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAE5C,OAAO,EACL,yBAAyB,EACzB,gBAAgB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AG,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC;QACrB,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;IAET,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAmB;IAClD,OAAO;QACL,QAAQ,EAAE;YACR,2BAA2B;YAC3B,UAAU,EAAE;YAEZ,4FAA4F;YAC5F,0BAA0B;YAC1B,GAAG,kBAAkB,EAAE;SACxB;QACD,MAAM,EAAE;YACN,OAAO,EAAE,kCAAkC,CAAC,MAAM,CAAC;SACpD;QACD,8EAA8E;QAC9E,wEAAwE;QACxE,+EAA+E;QAC/E,8GAA8G;QAC9G,8EAA8E;QAC9E,aAAa,EAAE,aAAa;QAC5B,SAAS,EAAE,gBAAgB;QAC3B,gBAAgB;QAChB,gBAAgB;KACjB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,MAAM,MAAM,GAAG,gBAAgB,EAAE,CAAC;IAClC,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["import { LinkingOptions, PathConfigMap } from \"@react-navigation/native\";\nimport { useMemo } from \"react\";\n\nimport { getAllWebRedirects } from \"./aasa\";\n\nimport {\n matchDeepDynamicRouteName,\n matchDynamicName,\n matchFragmentName,\n} from \"./matchers\";\nimport { RouteNode } from \"./Route\";\nimport {\n addEventListener,\n getInitialURL,\n getRootURL,\n getPathFromState,\n getStateFromPath,\n} from \"./linking\";\nimport { useRoutesContext } from \"./context\";\n\n// `[page]` -> `:page`\n// `page` -> `page`\nfunction convertDynamicRouteToReactNavigation(name: string) {\n if (matchDeepDynamicRouteName(name)) {\n return \"*\";\n }\n const dynamicName = matchDynamicName(name);\n\n if (dynamicName) {\n return `:${dynamicName}`;\n }\n\n if (name === \"index\" || matchFragmentName(name)) {\n return \"\";\n }\n\n return name;\n}\n\nexport function treeToReactNavigationLinkingRoutes(\n nodes: RouteNode[],\n parents: string[] = []\n): PathConfigMap<{}> {\n // TODO: Intercept errors, strip invalid routes, and warn instead.\n // Our warnings can be more helpful than upstream since we know the associated file name.\n const firstPass = nodes\n .map((node) => {\n const path = convertDynamicRouteToReactNavigation(node.route);\n\n if (!node.children.length) {\n return [node.route, path];\n }\n\n const screens = treeToReactNavigationLinkingRoutes(node.children, [\n ...parents,\n path,\n ]);\n\n return [node.route, { path, screens }] as const;\n })\n .reduce<PathConfigMap<{}>>((acc, [route, current]) => {\n acc[route] = current;\n return acc;\n }, {});\n\n return firstPass;\n}\n\nexport function getLinkingConfig(routes: RouteNode[]): LinkingOptions<{}> {\n return {\n prefixes: [\n /* your linking prefixes */\n getRootURL(),\n\n // This ensures that we can redirect correctly when the user comes from an associated domain\n // i.e. iOS Safari banner.\n ...getAllWebRedirects(),\n ],\n config: {\n screens: treeToReactNavigationLinkingRoutes(routes),\n },\n // A custom getInitialURL is used on native to ensure the app always starts at\n // the root path if it's launched from something other than a deep link.\n // This helps keep the native functionality working like the web functionality.\n // For example, if you had a root navigator where the first screen was `/settings` and the second was `/index`\n // then `/index` would be used on web and `/settings` would be used on native.\n getInitialURL: getInitialURL,\n subscribe: addEventListener,\n getStateFromPath,\n getPathFromState,\n };\n}\n\nexport function useLinkingConfig(): LinkingOptions<{}> {\n const routes = useRoutesContext();\n return useMemo(() => getLinkingConfig(routes), [routes]);\n}\n"]}
package/build/index.d.ts CHANGED
@@ -12,4 +12,6 @@ export { ErrorBoundary } from "./views/ErrorBoundary";
12
12
  export { Layout, Children } from "./views/Layout";
13
13
  export { Link } from "./views/Link";
14
14
  export { RootContainer, useNavigationContainerContext } from "./ContextNavigationContainer";
15
+ export { useCurrentRoute } from "./useCurrentRoute";
16
+ export * as Linking from './linking';
15
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],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AAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,KAAK,OAAO,MAAM,WAAW,CAAA"}
package/build/index.js CHANGED
@@ -11,4 +11,7 @@ export { ErrorBoundary } from "./views/ErrorBoundary";
11
11
  export { Layout, Children } from "./views/Layout";
12
12
  export { Link } from "./views/Link";
13
13
  export { RootContainer, useNavigationContainerContext } from "./ContextNavigationContainer";
14
+ export { useCurrentRoute } from "./useCurrentRoute";
15
+ import * as Linking_1 from './linking';
16
+ export { Linking_1 as Linking };
14
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI1C,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC","sourcesContent":["export { useRoutes } from \"./Route\";\nexport { useScreens } from \"./useScreens\";\n\nexport { ErrorBoundaryProps } from \"./views/Try\";\n\nexport { Stack } from \"./layouts/Stack\";\nexport { NativeStack } from \"./layouts/NativeStack\";\nexport { Tabs } from \"./layouts/Tabs\";\nexport { Drawer } from \"./layouts/Drawer\";\nexport { withLayoutContext } from \"./layouts/withLayoutContext\";\n\nexport { ExpoRoot } from \"./views/Root\";\nexport { Unmatched } from \"./views/Unmatched\";\nexport { ErrorBoundary } from \"./views/ErrorBoundary\";\n\nexport { Layout, Children } from \"./views/Layout\";\nexport { Link } from \"./views/Link\";\nexport { RootContainer, useNavigationContainerContext } from \"./ContextNavigationContainer\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI1C,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;2BAE3B,WAAW;sBAAxB,OAAO","sourcesContent":["export { useRoutes } from \"./Route\";\nexport { useScreens } from \"./useScreens\";\n\nexport { ErrorBoundaryProps } from \"./views/Try\";\n\nexport { Stack } from \"./layouts/Stack\";\nexport { NativeStack } from \"./layouts/NativeStack\";\nexport { Tabs } from \"./layouts/Tabs\";\nexport { Drawer } from \"./layouts/Drawer\";\nexport { withLayoutContext } from \"./layouts/withLayoutContext\";\n\nexport { ExpoRoot } from \"./views/Root\";\nexport { Unmatched } from \"./views/Unmatched\";\nexport { ErrorBoundary } from \"./views/ErrorBoundary\";\n\nexport { Layout, Children } from \"./views/Layout\";\nexport { Link } from \"./views/Link\";\nexport { RootContainer, useNavigationContainerContext } from \"./ContextNavigationContainer\";\nexport { useCurrentRoute } from \"./useCurrentRoute\";\n\nexport * as Linking from './linking'"]}
@@ -0,0 +1,7 @@
1
+ import getPathFromState from "./fork/getPathFromState";
2
+ import getStateFromPath from "./fork/getStateFromPath";
3
+ export declare function getInitialURL(): Promise<string>;
4
+ export declare function getRootURL(): string;
5
+ export declare function addEventListener(listener: (url: string) => void): () => void;
6
+ export { getStateFromPath, getPathFromState };
7
+ //# sourceMappingURL=linking.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linking.d.ts","sourceRoot":"","sources":["../src/linking.ts"],"names":[],"mappings":"AAGA,OAAO,gBAAgB,MAAM,yBAAyB,CAAC;AACvD,OAAO,gBAAgB,MAAM,yBAAyB,CAAC;AAOvD,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CA+BrD;AAID,wBAAgB,UAAU,WAKzB;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,cAiC/D;AAED,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC"}
@@ -0,0 +1,77 @@
1
+ import Constants, { ExecutionEnvironment } from "expo-constants";
2
+ import * as Linking from "expo-linking";
3
+ import getPathFromState from "./fork/getPathFromState";
4
+ import getStateFromPath from "./fork/getStateFromPath";
5
+ // A custom getInitialURL is used on native to ensure the app always starts at
6
+ // the root path if it's launched from something other than a deep link.
7
+ // This helps keep the native functionality working like the web functionality.
8
+ // For example, if you had a root navigator where the first screen was `/settings` and the second was `/index`
9
+ // then `/index` would be used on web and `/settings` would be used on native.
10
+ export async function getInitialURL() {
11
+ const url = await Promise.race([
12
+ (async () => {
13
+ const url = await Linking.getInitialURL();
14
+ // NOTE(EvanBacon): This could probably be wrapped with the development boundary
15
+ // since Expo Go is mostly just used in development.
16
+ // Expo Go is weird and requires the root path to be `/--/`
17
+ if (url &&
18
+ Constants.executionEnvironment === ExecutionEnvironment.StoreClient) {
19
+ const parsed = Linking.parse(url);
20
+ // If the URL is defined (default in Expo Go dev apps) and the URL has no path:
21
+ // `exp://192.168.87.39:19000/` then use the default `exp://192.168.87.39:19000/--/`
22
+ if (parsed.path === null || ["", "/"].includes(parsed.path)) {
23
+ return getRootURL();
24
+ }
25
+ }
26
+ // The path will be nullish in bare apps when the app is launched from the home screen.
27
+ // TODO(EvanBacon): define some policy around notifications.
28
+ return url ?? getRootURL();
29
+ })(),
30
+ new Promise((resolve) =>
31
+ // Timeout in 150ms if `getInitialState` doesn't resolve
32
+ // Workaround for https://github.com/facebook/react-native/issues/25675
33
+ setTimeout(() => resolve(getRootURL()), 150)),
34
+ ]);
35
+ return url;
36
+ }
37
+ let _rootURL;
38
+ export function getRootURL() {
39
+ if (_rootURL === undefined) {
40
+ _rootURL = Linking.createURL("/");
41
+ }
42
+ return _rootURL;
43
+ }
44
+ export function addEventListener(listener) {
45
+ let callback = undefined;
46
+ if (Constants.executionEnvironment === ExecutionEnvironment.StoreClient) {
47
+ // This extra work is only done in the Expo Go app.
48
+ callback = ({ url }) => {
49
+ const parsed = Linking.parse(url);
50
+ // If the URL is defined (default in Expo Go dev apps) and the URL has no path:
51
+ // `exp://192.168.87.39:19000/` then use the default `exp://192.168.87.39:19000/--/`
52
+ if (parsed.path === null || ["", "/"].includes(parsed.path)) {
53
+ listener(getRootURL());
54
+ }
55
+ else {
56
+ listener(url);
57
+ }
58
+ };
59
+ }
60
+ else {
61
+ callback = ({ url }) => listener(url);
62
+ }
63
+ const subscription = Linking.addEventListener("url", callback);
64
+ // Storing this in a local variable stops Jest from complaining about import after teardown
65
+ const removeEventListener = Linking.removeEventListener?.bind(Linking);
66
+ return () => {
67
+ // https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7
68
+ if (subscription?.remove) {
69
+ subscription.remove();
70
+ }
71
+ else {
72
+ removeEventListener?.("url", callback);
73
+ }
74
+ };
75
+ }
76
+ export { getStateFromPath, getPathFromState };
77
+ //# sourceMappingURL=linking.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linking.js","sourceRoot":"","sources":["../src/linking.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,EAAE,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC,OAAO,gBAAgB,MAAM,yBAAyB,CAAC;AACvD,OAAO,gBAAgB,MAAM,yBAAyB,CAAC;AAEvD,8EAA8E;AAC9E,wEAAwE;AACxE,+EAA+E;AAC/E,8GAA8G;AAC9G,8EAA8E;AAC9E,MAAM,CAAC,KAAK,UAAU,aAAa;IACjC,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,IAAI,CAAS;QACrC,CAAC,KAAK,IAAI,EAAE;YACV,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,aAAa,EAAE,CAAC;YAE1C,gFAAgF;YA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IAAI,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;gBAC3D,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;aACxB;iBAAM;gBACL,QAAQ,CAAC,GAAG,CAAC,CAAC;aACf;QACH,CAAC,CAAC;KACH;SAAM;QACL,QAAQ,GAAG,CAAC,EAAE,GAAG,EAAmB,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;KACxD;IACD,MAAM,YAAY,GAAG,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE,QAAQ,CAEhD,CAAC;IAEd,2FAA2F;IAC3F,MAAM,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAEvE,OAAO,GAAG,EAAE;QACV,2FAA2F;QAC3F,IAAI,YAAY,EAAE,MAAM,EAAE;YACxB,YAAY,CAAC,MAAM,EAAE,CAAC;SACvB;aAAM;YACL,mBAAmB,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;SACxC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC","sourcesContent":["import Constants, { ExecutionEnvironment } from \"expo-constants\";\nimport * as Linking from \"expo-linking\";\n\nimport getPathFromState from \"./fork/getPathFromState\";\nimport getStateFromPath from \"./fork/getStateFromPath\";\n\n// A custom getInitialURL is used on native to ensure the app always starts at\n// the root path if it's launched from something other than a deep link.\n// This helps keep the native functionality working like the web functionality.\n// For example, if you had a root navigator where the first screen was `/settings` and the second was `/index`\n// then `/index` would be used on web and `/settings` would be used on native.\nexport async function getInitialURL(): Promise<string> {\n const url = await Promise.race<string>([\n (async () => {\n const url = await Linking.getInitialURL();\n\n // NOTE(EvanBacon): This could probably be wrapped with the development boundary\n // since Expo Go is mostly just used in development.\n\n // Expo Go is weird and requires the root path to be `/--/`\n if (\n url &&\n Constants.executionEnvironment === ExecutionEnvironment.StoreClient\n ) {\n const parsed = Linking.parse(url);\n // If the URL is defined (default in Expo Go dev apps) and the URL has no path:\n // `exp://192.168.87.39:19000/` then use the default `exp://192.168.87.39:19000/--/`\n if (parsed.path === null || [\"\", \"/\"].includes(parsed.path)) {\n return getRootURL();\n }\n }\n // The path will be nullish in bare apps when the app is launched from the home screen.\n // TODO(EvanBacon): define some policy around notifications.\n return url ?? getRootURL();\n })(),\n new Promise<string>((resolve) =>\n // Timeout in 150ms if `getInitialState` doesn't resolve\n // Workaround for https://github.com/facebook/react-native/issues/25675\n setTimeout(() => resolve(getRootURL()), 150)\n ),\n ]);\n return url;\n}\n\nlet _rootURL: string | undefined;\n\nexport function getRootURL() {\n if (_rootURL === undefined) {\n _rootURL = Linking.createURL(\"/\");\n }\n return _rootURL;\n}\n\nexport function addEventListener(listener: (url: string) => void) {\n let callback: (({ url }: { url: string }) => void) | undefined = undefined;\n\n if (Constants.executionEnvironment === ExecutionEnvironment.StoreClient) {\n // This extra work is only done in the Expo Go app.\n callback = ({ url }: { url: string }) => {\n const parsed = Linking.parse(url);\n // If the URL is defined (default in Expo Go dev apps) and the URL has no path:\n // `exp://192.168.87.39:19000/` then use the default `exp://192.168.87.39:19000/--/`\n if (parsed.path === null || [\"\", \"/\"].includes(parsed.path)) {\n listener(getRootURL());\n } else {\n listener(url);\n }\n };\n } else {\n callback = ({ url }: { url: string }) => listener(url);\n }\n const subscription = Linking.addEventListener(\"url\", callback) as\n | { remove(): void }\n | undefined;\n\n // Storing this in a local variable stops Jest from complaining about import after teardown\n const removeEventListener = Linking.removeEventListener?.bind(Linking);\n\n return () => {\n // https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7\n if (subscription?.remove) {\n subscription.remove();\n } else {\n removeEventListener?.(\"url\", callback);\n }\n };\n}\n\nexport { getStateFromPath, getPathFromState };\n"]}
@@ -0,0 +1,3 @@
1
+ declare let SplashModule: typeof import("expo-splash-screen") | null;
2
+ export default SplashModule;
3
+ //# sourceMappingURL=splash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"splash.d.ts","sourceRoot":"","sources":["../src/splash.ts"],"names":[],"mappings":"AAEA,QAAA,IAAI,YAAY,EAAE,cAAc,oBAAoB,CAAC,GAAG,IAAW,CAAC;AAUpE,eAAe,YAAY,CAAC"}
@@ -0,0 +1,12 @@
1
+ import Constants, { ExecutionEnvironment } from "expo-constants";
2
+ let SplashModule = null;
3
+ try {
4
+ if (Constants.executionEnvironment !== ExecutionEnvironment.StoreClient) {
5
+ SplashModule = require("expo-splash-screen");
6
+ }
7
+ }
8
+ catch (e) {
9
+ // Ignore
10
+ }
11
+ export default SplashModule;
12
+ //# sourceMappingURL=splash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"splash.js","sourceRoot":"","sources":["../src/splash.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,EAAE,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEjE,IAAI,YAAY,GAA+C,IAAI,CAAC;AAEpE,IAAI;IACF,IAAI,SAAS,CAAC,oBAAoB,KAAK,oBAAoB,CAAC,WAAW,EAAE;QACvE,YAAY,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;KAC9C;CACF;AAAC,OAAO,CAAC,EAAE;IACV,SAAS;CACV;AAED,eAAe,YAAY,CAAC","sourcesContent":["import Constants, { ExecutionEnvironment } from \"expo-constants\";\n\nlet SplashModule: typeof import(\"expo-splash-screen\") | null = null;\n\ntry {\n if (Constants.executionEnvironment !== ExecutionEnvironment.StoreClient) {\n SplashModule = require(\"expo-splash-screen\");\n }\n} catch (e) {\n // Ignore\n}\n\nexport default SplashModule;\n"]}
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+ export declare const VirtualRouteContext: React.Context<{
3
+ pathname: string | null;
4
+ query: Record<string, any>;
5
+ }>;
6
+ export declare function useCurrentRoute(): {
7
+ pathname: string | null;
8
+ query: Record<string, any>;
9
+ };
10
+ //# sourceMappingURL=useCurrentRoute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCurrentRoute.d.ts","sourceRoot":"","sources":["../src/useCurrentRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,eAAO,MAAM,mBAAmB;cACpB,MAAM,GAAG,IAAI;WAChB,OAAO,MAAM,EAAE,GAAG,CAAC;EACK,CAAC;AAMlC,wBAAgB,eAAe;;;EAQ9B"}
@@ -0,0 +1,13 @@
1
+ import React from "react";
2
+ export const VirtualRouteContext = React.createContext({ pathname: null, query: {} });
3
+ if (process.env.NODE_ENV !== "production") {
4
+ VirtualRouteContext.displayName = "VirtualRouteContext";
5
+ }
6
+ export function useCurrentRoute() {
7
+ const context = React.useContext(VirtualRouteContext);
8
+ if (!context) {
9
+ throw new Error("useCurrentRoute must be used within a NavigationContainerContext");
10
+ }
11
+ return context;
12
+ }
13
+ //# sourceMappingURL=useCurrentRoute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCurrentRoute.js","sourceRoot":"","sources":["../src/useCurrentRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAC,aAAa,CAGnD,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;AAElC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;IACzC,mBAAmB,CAAC,WAAW,GAAG,qBAAqB,CAAC;CACzD;AAED,MAAM,UAAU,eAAe;IAC7B,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC;IACtD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CACb,kEAAkE,CACnE,CAAC;KACH;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import React from \"react\";\n\nexport const VirtualRouteContext = React.createContext<{\n pathname: string | null;\n query: Record<string, any>;\n}>({ pathname: null, query: {} });\n\nif (process.env.NODE_ENV !== \"production\") {\n VirtualRouteContext.displayName = \"VirtualRouteContext\";\n}\n\nexport function useCurrentRoute() {\n const context = React.useContext(VirtualRouteContext);\n if (!context) {\n throw new Error(\n \"useCurrentRoute must be used within a NavigationContainerContext\"\n );\n }\n return context;\n}\n"]}
package/entry.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { registerRootComponent } from "expo";
2
2
  import { ExpoRoot } from "expo-router";
3
3
  import { View, Platform } from "react-native";
4
- import Constants, { ExecutionEnvironment } from "expo-constants";
4
+
5
+ import SplashModule from "expo-router/build/splash";
5
6
 
6
7
  // Must be exported or Fast Refresh won't update the context >:[
7
8
  export function App() {
@@ -53,30 +54,18 @@ function convertError(error) {
53
54
  return new Error(String(error));
54
55
  }
55
56
 
56
- function preventAutoHide() {
57
- // Not applicable to Expo Go.
58
- if (Constants.executionEnvironment !== ExecutionEnvironment.StoreClient) {
59
- try {
60
- // Automatically handle hiding the splash screen if expo-splash-screen is installed.
61
- return require("expo-splash-screen").preventAutoHideAsync();
62
- } catch {}
63
- }
64
- }
65
-
66
- function hideSplash() {
67
- try {
68
- return require("expo-splash-screen").hideAsync();
69
- } catch {}
70
- }
71
-
72
57
  (() => {
73
58
  try {
74
- preventAutoHide();
59
+ if (SplashModule) {
60
+ SplashModule.preventAutoHideAsync();
61
+ }
75
62
 
76
63
  registerRootComponent(App);
77
64
  } catch (e) {
78
65
  // Hide the splash screen if there was an error so the user can see it.
79
- hideSplash();
66
+ if (SplashModule) {
67
+ SplashModule.hideAsync();
68
+ }
80
69
 
81
70
  const error = convertError(e);
82
71
  // Prevent the app from throwing confusing:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-router",
3
- "version": "0.0.9",
3
+ "version": "0.0.13",
4
4
  "main": "build/index.js",
5
5
  "files": [
6
6
  "entry.js",
@@ -44,7 +44,7 @@
44
44
  "jest": "^26.6.3"
45
45
  },
46
46
  "dependencies": {
47
- "@bacons/expo-metro-runtime": "^1.2.0",
47
+ "@bacons/expo-metro-runtime": "^2.0.1",
48
48
  "@bacons/react-views": "^1.1.3",
49
49
  "@radix-ui/react-slot": "^1.0.0",
50
50
  "@react-navigation/bottom-tabs": "^6.3.3",
@@ -54,6 +54,7 @@
54
54
  "@react-navigation/stack": "^6.2.3",
55
55
  "expo-constants": "~13.2.4",
56
56
  "expo-linking": "^3.2.2",
57
+ "expo-splash-screen": "^0.16.2",
57
58
  "expo-status-bar": "^1.4.0",
58
59
  "react-native-gesture-handler": "~2.5.0",
59
60
  "react-native-reanimated": "~2.9.1",