expo-router 5.0.3 → 5.0.5

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.
Files changed (46) hide show
  1. package/build/Route.d.ts.map +1 -1
  2. package/build/Route.js +1 -1
  3. package/build/Route.js.map +1 -1
  4. package/build/fork/native-stack/NativeStackView.d.ts.map +1 -1
  5. package/build/fork/native-stack/NativeStackView.js +1 -1
  6. package/build/fork/native-stack/NativeStackView.js.map +1 -1
  7. package/build/fork/useLinking.js +1 -1
  8. package/build/fork/useLinking.js.map +1 -1
  9. package/build/global-state/routeInfo.d.ts.map +1 -1
  10. package/build/global-state/routeInfo.js +9 -3
  11. package/build/global-state/routeInfo.js.map +1 -1
  12. package/build/global-state/router-store.d.ts +2 -4
  13. package/build/global-state/router-store.d.ts.map +1 -1
  14. package/build/global-state/router-store.js +38 -17
  15. package/build/global-state/router-store.js.map +1 -1
  16. package/build/global-state/storeContext.d.ts +2 -4
  17. package/build/global-state/storeContext.d.ts.map +1 -1
  18. package/build/hooks.js +1 -1
  19. package/build/hooks.js.map +1 -1
  20. package/build/layouts/RootModal.js +1 -1
  21. package/build/layouts/RootModal.js.map +1 -1
  22. package/build/layouts/withLayoutContext.d.ts.map +1 -1
  23. package/build/layouts/withLayoutContext.js +1 -0
  24. package/build/layouts/withLayoutContext.js.map +1 -1
  25. package/build/rsc/router/client.js +2 -2
  26. package/build/rsc/router/client.js.map +1 -1
  27. package/build/testing-library/index.d.ts +0 -11
  28. package/build/testing-library/index.d.ts.map +1 -1
  29. package/build/testing-library/index.js.map +1 -1
  30. package/build/ui/TabTrigger.d.ts.map +1 -1
  31. package/build/ui/TabTrigger.js +1 -1
  32. package/build/ui/TabTrigger.js.map +1 -1
  33. package/build/ui/Tabs.d.ts.map +1 -1
  34. package/build/ui/Tabs.js +2 -2
  35. package/build/ui/Tabs.js.map +1 -1
  36. package/build/useNavigation.d.ts.map +1 -1
  37. package/build/useNavigation.js +4 -0
  38. package/build/useNavigation.js.map +1 -1
  39. package/build/views/ErrorBoundary.js +1 -1
  40. package/build/views/ErrorBoundary.js.map +1 -1
  41. package/build/views/Navigator.js +2 -2
  42. package/build/views/Navigator.js.map +1 -1
  43. package/build/views/Toast.js +1 -1
  44. package/build/views/Toast.js.map +1 -1
  45. package/package.json +3 -3
  46. package/types/expect.d.ts +10 -0
@@ -1 +1 @@
1
- {"version":3,"file":"Route.d.ts","sourceRoot":"","sources":["../src/Route.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA6B,KAAK,aAAa,EAAE,KAAK,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAG9F,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,MAAM,MAAM,iBAAiB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEpF,MAAM,MAAM,WAAW,GAAG;IACxB,aAAa,CAAC,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC;IAClD,OAAO,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACxC,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,GAAG,CAAC;IACnC,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE;QAC7B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;KAC5C,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,4BAA4B;IAC5B,IAAI,EAAE,OAAO,GAAG,KAAK,GAAG,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EAAE,CAAC;IACpC,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,UAAU,EAAE,MAAM,CAAC;IACnB,8DAA8D;IAC9D,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,iCAAiC;IACjC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,sBAAsB;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,wFAAwF;IACxF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,oLAAoL;IACpL,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAGF,eAAO,MAAM,uBAAuB,yEAE/B,CAAC;AAMN,+DAA+D;AAC/D,wBAAgB,YAAY,IAAI,SAAS,GAAG,IAAI,CAE/C;AAED,wBAAgB,aAAa,IAAI,MAAM,CAMtC;AAED,MAAM,MAAM,UAAU,GAAG,iBAAiB,CAAC;IACzC,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;KAAE,CAAC;CACxD,CAAC,CAAC;AAEH,iEAAiE;AACjE,wBAAgB,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,UAAU,+BAM1D;AAED,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,CAAC"}
package/build/Route.js CHANGED
@@ -17,7 +17,7 @@ if (process.env.NODE_ENV !== 'production') {
17
17
  }
18
18
  /** Return the RouteNode at the current contextual boundary. */
19
19
  function useRouteNode() {
20
- return (0, react_1.useContext)(CurrentRouteContext);
20
+ return (0, react_1.use)(CurrentRouteContext);
21
21
  }
22
22
  function useContextKey() {
23
23
  const node = useRouteNode();
@@ -1 +1 @@
1
- {"version":3,"file":"Route.js","sourceRoot":"","sources":["../src/Route.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;AA2Db,oCAEC;AAED,sCAMC;AAQD,sBAMC;AAjFD,iCAA8F;AAE9F,yCAA2C;AAC3C,6CAAiE;AAgFxD,sGAhFA,kCAAqB,OAgFA;AAAE,2FAhFA,uBAAU,OAgFA;AApC1C,MAAM,mBAAmB,GAAG,IAAA,qBAAa,EAAmB,IAAI,CAAC,CAAC;AACrD,QAAA,uBAAuB,GAAG,IAAA,qBAAa,EAElD,EAAE,CAAC,CAAC;AAEN,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;IAC1C,mBAAmB,CAAC,WAAW,GAAG,WAAW,CAAC;AAChD,CAAC;AAED,+DAA+D;AAC/D,SAAgB,YAAY;IAC1B,OAAO,IAAA,kBAAU,EAAC,mBAAmB,CAAC,CAAC;AACzC,CAAC;AAED,SAAgB,aAAa;IAC3B,MAAM,IAAI,GAAG,YAAY,EAAE,CAAC;IAC5B,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,IAAA,wBAAa,EAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AACxC,CAAC;AAOD,iEAAiE;AACjE,SAAgB,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAc;IACzD,OAAO,CACL,CAAC,+BAAuB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CACrD;MAAA,CAAC,mBAAmB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,QAAQ,CACrF;IAAA,EAAE,+BAAuB,CAAC,QAAQ,CAAC,CACpC,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport { createContext, useContext, type ComponentType, type PropsWithChildren } from 'react';\n\nimport { getContextKey } from './matchers';\nimport { sortRoutesWithInitial, sortRoutes } from './sortRoutes';\nimport { type ErrorBoundaryProps } from './views/Try';\n\nexport type DynamicConvention = { name: string; deep: boolean; notFound?: boolean };\n\nexport type LoadedRoute = {\n ErrorBoundary?: ComponentType<ErrorBoundaryProps>;\n default?: ComponentType<any>;\n unstable_settings?: Record<string, any>;\n getNavOptions?: (args: any) => any;\n generateStaticParams?: (props: {\n params?: Record<string, string | string[]>;\n }) => Record<string, string | string[]>[];\n};\n\nexport type RouteNode = {\n /** The type of RouteNode */\n type: 'route' | 'api' | 'layout' | 'redirect' | 'rewrite';\n /** Load a route into memory. Returns the exports from a route. */\n loadRoute: () => Partial<LoadedRoute>;\n /** Loaded initial route name. */\n initialRouteName?: string;\n /** Nested routes */\n children: RouteNode[];\n /** Is the route a dynamic path */\n dynamic: null | DynamicConvention[];\n /** `index`, `error-boundary`, etc. */\n route: string;\n /** Context Module ID, used for matching children. */\n contextKey: string;\n /** Redirect Context Module ID, used for matching children. */\n destinationContextKey?: string;\n /** Is the redirect permanent. */\n permanent?: boolean;\n /** Added in-memory */\n generated?: boolean;\n /** Internal screens like the directory or the auto 404 should be marked as internal. */\n internal?: boolean;\n /** File paths for async entry modules that should be included in the initial chunk request to ensure the runtime JavaScript matches the statically rendered HTML representation. */\n entryPoints?: string[];\n /** HTTP methods for this route. If undefined, assumed to be ['GET'] */\n methods?: string[];\n};\n\nconst CurrentRouteContext = createContext<RouteNode | null>(null);\nexport const LocalRouteParamsContext = createContext<\n Record<string, string | undefined> | undefined\n>({});\n\nif (process.env.NODE_ENV !== 'production') {\n CurrentRouteContext.displayName = 'RouteNode';\n}\n\n/** Return the RouteNode at the current contextual boundary. */\nexport function useRouteNode(): RouteNode | null {\n return useContext(CurrentRouteContext);\n}\n\nexport function useContextKey(): string {\n const node = useRouteNode();\n if (node == null) {\n throw new Error('No filename found. This is likely a bug in expo-router.');\n }\n return getContextKey(node.contextKey);\n}\n\nexport type RouteProps = PropsWithChildren<{\n node: RouteNode;\n route?: { params: Record<string, string | undefined> };\n}>;\n\n/** Provides the matching routes and filename to the children. */\nexport function Route({ children, node, route }: RouteProps) {\n return (\n <LocalRouteParamsContext.Provider value={route?.params}>\n <CurrentRouteContext.Provider value={node}>{children}</CurrentRouteContext.Provider>\n </LocalRouteParamsContext.Provider>\n );\n}\n\nexport { sortRoutesWithInitial, sortRoutes };\n"]}
1
+ {"version":3,"file":"Route.js","sourceRoot":"","sources":["../src/Route.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;AA2Db,oCAEC;AAED,sCAMC;AAQD,sBAMC;AAjFD,iCAAuF;AAEvF,yCAA2C;AAC3C,6CAAiE;AAgFxD,sGAhFA,kCAAqB,OAgFA;AAAE,2FAhFA,uBAAU,OAgFA;AApC1C,MAAM,mBAAmB,GAAG,IAAA,qBAAa,EAAmB,IAAI,CAAC,CAAC;AACrD,QAAA,uBAAuB,GAAG,IAAA,qBAAa,EAElD,EAAE,CAAC,CAAC;AAEN,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;IAC1C,mBAAmB,CAAC,WAAW,GAAG,WAAW,CAAC;AAChD,CAAC;AAED,+DAA+D;AAC/D,SAAgB,YAAY;IAC1B,OAAO,IAAA,WAAG,EAAC,mBAAmB,CAAC,CAAC;AAClC,CAAC;AAED,SAAgB,aAAa;IAC3B,MAAM,IAAI,GAAG,YAAY,EAAE,CAAC;IAC5B,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,IAAA,wBAAa,EAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AACxC,CAAC;AAOD,iEAAiE;AACjE,SAAgB,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAc;IACzD,OAAO,CACL,CAAC,+BAAuB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CACrD;MAAA,CAAC,mBAAmB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,QAAQ,CACrF;IAAA,EAAE,+BAAuB,CAAC,QAAQ,CAAC,CACpC,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport { createContext, use, type ComponentType, type PropsWithChildren } from 'react';\n\nimport { getContextKey } from './matchers';\nimport { sortRoutesWithInitial, sortRoutes } from './sortRoutes';\nimport { type ErrorBoundaryProps } from './views/Try';\n\nexport type DynamicConvention = { name: string; deep: boolean; notFound?: boolean };\n\nexport type LoadedRoute = {\n ErrorBoundary?: ComponentType<ErrorBoundaryProps>;\n default?: ComponentType<any>;\n unstable_settings?: Record<string, any>;\n getNavOptions?: (args: any) => any;\n generateStaticParams?: (props: {\n params?: Record<string, string | string[]>;\n }) => Record<string, string | string[]>[];\n};\n\nexport type RouteNode = {\n /** The type of RouteNode */\n type: 'route' | 'api' | 'layout' | 'redirect' | 'rewrite';\n /** Load a route into memory. Returns the exports from a route. */\n loadRoute: () => Partial<LoadedRoute>;\n /** Loaded initial route name. */\n initialRouteName?: string;\n /** Nested routes */\n children: RouteNode[];\n /** Is the route a dynamic path */\n dynamic: null | DynamicConvention[];\n /** `index`, `error-boundary`, etc. */\n route: string;\n /** Context Module ID, used for matching children. */\n contextKey: string;\n /** Redirect Context Module ID, used for matching children. */\n destinationContextKey?: string;\n /** Is the redirect permanent. */\n permanent?: boolean;\n /** Added in-memory */\n generated?: boolean;\n /** Internal screens like the directory or the auto 404 should be marked as internal. */\n internal?: boolean;\n /** File paths for async entry modules that should be included in the initial chunk request to ensure the runtime JavaScript matches the statically rendered HTML representation. */\n entryPoints?: string[];\n /** HTTP methods for this route. If undefined, assumed to be ['GET'] */\n methods?: string[];\n};\n\nconst CurrentRouteContext = createContext<RouteNode | null>(null);\nexport const LocalRouteParamsContext = createContext<\n Record<string, string | undefined> | undefined\n>({});\n\nif (process.env.NODE_ENV !== 'production') {\n CurrentRouteContext.displayName = 'RouteNode';\n}\n\n/** Return the RouteNode at the current contextual boundary. */\nexport function useRouteNode(): RouteNode | null {\n return use(CurrentRouteContext);\n}\n\nexport function useContextKey(): string {\n const node = useRouteNode();\n if (node == null) {\n throw new Error('No filename found. This is likely a bug in expo-router.');\n }\n return getContextKey(node.contextKey);\n}\n\nexport type RouteProps = PropsWithChildren<{\n node: RouteNode;\n route?: { params: Record<string, string | undefined> };\n}>;\n\n/** Provides the matching routes and filename to the children. */\nexport function Route({ children, node, route }: RouteProps) {\n return (\n <LocalRouteParamsContext.Provider value={route?.params}>\n <CurrentRouteContext.Provider value={node}>{children}</CurrentRouteContext.Provider>\n </LocalRouteParamsContext.Provider>\n );\n}\n\nexport { sortRoutesWithInitial, sortRoutes };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"NativeStackView.d.ts","sourceRoot":"","sources":["../../../src/fork/native-stack/NativeStackView.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACtF,OAAO,EAAE,cAAc,EAAuB,MAAM,OAAO,CAAC;AAI5D,wBAAgB,eAAe,CAAC,KAAK,EAAE,cAAc,CAAC,OAAO,iBAAiB,CAAC,+BAM9E"}
1
+ {"version":3,"file":"NativeStackView.d.ts","sourceRoot":"","sources":["../../../src/fork/native-stack/NativeStackView.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACtF,OAAO,EAAE,cAAc,EAAgB,MAAM,OAAO,CAAC;AAIrD,wBAAgB,eAAe,CAAC,KAAK,EAAE,cAAc,CAAC,OAAO,iBAAiB,CAAC,+BAM9E"}
@@ -10,7 +10,7 @@ function NativeStackView(props) {
10
10
  </RootModal_1.RootModalProvider>);
11
11
  }
12
12
  function NativeStackViewInner(props) {
13
- const rootModals = (0, react_1.useContext)(RootModal_1.RootModalContext);
13
+ const rootModals = (0, react_1.use)(RootModal_1.RootModalContext);
14
14
  // Append the root modals to the state
15
15
  const state = (0, react_1.useMemo)(() => {
16
16
  if (rootModals.routes.length === 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"NativeStackView.js","sourceRoot":"","sources":["../../../src/fork/native-stack/NativeStackView.tsx"],"names":[],"mappings":";;AAKA,0CAMC;AAXD,iEAAsF;AACtF,iCAA4D;AAE5D,uDAA8E;AAE9E,SAAgB,eAAe,CAAC,KAA+C;IAC7E,OAAO,CACL,CAAC,6BAAiB,CAChB;MAAA,CAAC,oBAAoB,CAAC,IAAI,KAAK,CAAC,EAClC;IAAA,EAAE,6BAAiB,CAAC,CACrB,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB,CAAC,KAA+C;IAC3E,MAAM,UAAU,GAAG,IAAA,kBAAU,EAAC,4BAAgB,CAAC,CAAC;IAEhD,sCAAsC;IACtC,MAAM,KAAK,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE;QACzB,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnC,OAAO,KAAK,CAAC,KAAK,CAAC;QACrB,CAAC;QAED,OAAO;YACL,GAAG,KAAK,CAAC,KAAK;YACd,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC;SACrD,CAAC;IACJ,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAErC,OAAO,CAAC,8BAAiB,CAAC,IAAI,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,EAAG,CAAC;AACxD,CAAC","sourcesContent":["import { NativeStackView as RNNativeStackView } from '@react-navigation/native-stack';\nimport { ComponentProps, useContext, useMemo } from 'react';\n\nimport { RootModalContext, RootModalProvider } from '../../layouts/RootModal';\n\nexport function NativeStackView(props: ComponentProps<typeof RNNativeStackView>) {\n return (\n <RootModalProvider>\n <NativeStackViewInner {...props} />\n </RootModalProvider>\n );\n}\n\nfunction NativeStackViewInner(props: ComponentProps<typeof RNNativeStackView>) {\n const rootModals = useContext(RootModalContext);\n\n // Append the root modals to the state\n const state = useMemo(() => {\n if (rootModals.routes.length === 0) {\n return props.state;\n }\n\n return {\n ...props.state,\n routes: props.state.routes.concat(rootModals.routes),\n };\n }, [props.state, rootModals.routes]);\n\n return <RNNativeStackView {...props} state={state} />;\n}\n"]}
1
+ {"version":3,"file":"NativeStackView.js","sourceRoot":"","sources":["../../../src/fork/native-stack/NativeStackView.tsx"],"names":[],"mappings":";;AAKA,0CAMC;AAXD,iEAAsF;AACtF,iCAAqD;AAErD,uDAA8E;AAE9E,SAAgB,eAAe,CAAC,KAA+C;IAC7E,OAAO,CACL,CAAC,6BAAiB,CAChB;MAAA,CAAC,oBAAoB,CAAC,IAAI,KAAK,CAAC,EAClC;IAAA,EAAE,6BAAiB,CAAC,CACrB,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB,CAAC,KAA+C;IAC3E,MAAM,UAAU,GAAG,IAAA,WAAG,EAAC,4BAAgB,CAAC,CAAC;IAEzC,sCAAsC;IACtC,MAAM,KAAK,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE;QACzB,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnC,OAAO,KAAK,CAAC,KAAK,CAAC;QACrB,CAAC;QAED,OAAO;YACL,GAAG,KAAK,CAAC,KAAK;YACd,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC;SACrD,CAAC;IACJ,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAErC,OAAO,CAAC,8BAAiB,CAAC,IAAI,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,EAAG,CAAC;AACxD,CAAC","sourcesContent":["import { NativeStackView as RNNativeStackView } from '@react-navigation/native-stack';\nimport { ComponentProps, use, useMemo } from 'react';\n\nimport { RootModalContext, RootModalProvider } from '../../layouts/RootModal';\n\nexport function NativeStackView(props: ComponentProps<typeof RNNativeStackView>) {\n return (\n <RootModalProvider>\n <NativeStackViewInner {...props} />\n </RootModalProvider>\n );\n}\n\nfunction NativeStackViewInner(props: ComponentProps<typeof RNNativeStackView>) {\n const rootModals = use(RootModalContext);\n\n // Append the root modals to the state\n const state = useMemo(() => {\n if (rootModals.routes.length === 0) {\n return props.state;\n }\n\n return {\n ...props.state,\n routes: props.state.routes.concat(rootModals.routes),\n };\n }, [props.state, rootModals.routes]);\n\n return <RNNativeStackView {...props} state={state} />;\n}\n"]}
@@ -138,7 +138,7 @@ function useLinking(ref, { enabled = true, config, getStateFromPath = native_1.g
138
138
  // Otherwise there's an error in the linking configuration
139
139
  return state?.routes.some((r) => !rootState?.routeNames.includes(r.name));
140
140
  }, [ref]);
141
- const server = React.useContext(serverLocationContext_1.ServerContext);
141
+ const server = React.use(serverLocationContext_1.ServerContext);
142
142
  const getInitialState = React.useCallback(() => {
143
143
  let value;
144
144
  if (enabledRef.current) {
@@ -1 +1 @@
1
- {"version":3,"file":"useLinking.js","sourceRoot":"","sources":["../../src/fork/useLinking.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EA,gCAsXC;AAED,4DAEC;AArcD,qDAUkC;AAClC,sEAAsC;AACtC,6CAA+B;AAE/B,+DAA4D;AAC5D,yDAAmD;AACnD,iFAAsE;AAItE;;;GAGG;AACH,MAAM,iBAAiB,GAAG,CACxB,CAAgB,EAChB,CAAgB,EACgB,EAAE;IAClC,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC;QAC1D,OAAO,CAAC,SAAS,EAAE,SAAS,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;gBAC7E,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;YACnC,CAAC;QACH,CAAC,CAAC;QAEF,+FAA+F;QAC/F,0DAA0D;QAC1D,qGAAqG;QACrG,OAAO,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,IAAA,cAAM,EAAC,aAAa,CAAC,CAAC,CAAC;IAClE,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IAE5B,OAAO;QACL,eAAe;KAChB,CAAC;AACJ,CAAC;AAED,SAAgB,wBAAwB;IACtC,OAAO,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;AACnE,CAAC","sourcesContent":["import {\n LinkingOptions,\n findFocusedRoute,\n getActionFromState as getActionFromStateDefault,\n getPathFromState as getPathFromStateDefault,\n getStateFromPath as getStateFromPathDefault,\n type NavigationContainerRef,\n type NavigationState,\n type ParamListBase,\n useNavigationIndependentTree,\n} from '@react-navigation/native';\nimport isEqual from 'fast-deep-equal';\nimport * as React from 'react';\n\nimport { createMemoryHistory } from './createMemoryHistory';\nimport { appendBaseUrl } from './getPathFromState';\nimport { ServerContext } from '../global-state/serverLocationContext';\n\ntype ResultState = ReturnType<typeof getStateFromPathDefault>;\n\n/**\n * Find the matching navigation state that changed between 2 navigation states\n * e.g.: a -> b -> c -> d and a -> b -> c -> e -> f, if history in b changed, b is the matching state\n */\nconst findMatchingState = <T extends NavigationState>(\n a: T | undefined,\n b: T | undefined\n): [T | undefined, T | undefined] => {\n if (a === undefined || b === undefined || a.key !== b.key) {\n return [undefined, undefined];\n }\n\n // Tab and drawer will have `history` property, but stack will have history in `routes`\n const aHistoryLength = a.history ? a.history.length : a.routes.length;\n const bHistoryLength = b.history ? b.history.length : b.routes.length;\n\n const aRoute = a.routes[a.index];\n const bRoute = b.routes[b.index];\n\n const aChildState = aRoute.state as T | undefined;\n const bChildState = bRoute.state as T | undefined;\n\n // Stop here if this is the state object that changed:\n // - history length is different\n // - focused routes are different\n // - one of them doesn't have child state\n // - child state keys are different\n if (\n aHistoryLength !== bHistoryLength ||\n aRoute.key !== bRoute.key ||\n aChildState === undefined ||\n bChildState === undefined ||\n aChildState.key !== bChildState.key\n ) {\n return [a, b];\n }\n\n return findMatchingState(aChildState, bChildState);\n};\n\n/**\n * Run async function in series as it's called.\n */\nexport const series = (cb: () => Promise<void>) => {\n let queue = Promise.resolve();\n const callback = () => {\n queue = queue.then(cb);\n };\n return callback;\n};\n\nconst linkingHandlers: symbol[] = [];\n\ntype Options = LinkingOptions<ParamListBase>;\n\nexport function useLinking(\n ref: React.RefObject<NavigationContainerRef<ParamListBase> | null>,\n {\n enabled = true,\n config,\n getStateFromPath = getStateFromPathDefault,\n getPathFromState = getPathFromStateDefault,\n getActionFromState = getActionFromStateDefault,\n }: Options,\n onUnhandledLinking: (lastUnhandledLining: string | undefined) => void\n) {\n const independent = useNavigationIndependentTree();\n\n React.useEffect(() => {\n if (process.env.NODE_ENV === 'production') {\n return undefined;\n }\n\n if (independent) {\n return undefined;\n }\n\n if (enabled !== false && linkingHandlers.length) {\n console.error(\n [\n 'Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:',\n \"- You don't have multiple NavigationContainers in the app each with 'linking' enabled\",\n '- Only a single instance of the root component is rendered',\n ]\n .join('\\n')\n .trim()\n );\n }\n\n const handler = Symbol();\n\n if (enabled !== false) {\n linkingHandlers.push(handler);\n }\n\n return () => {\n const index = linkingHandlers.indexOf(handler);\n\n if (index > -1) {\n linkingHandlers.splice(index, 1);\n }\n };\n }, [enabled, independent]);\n\n const [history] = React.useState(createMemoryHistory);\n\n // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners\n // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`\n // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect\n const enabledRef = React.useRef(enabled);\n const configRef = React.useRef(config);\n const getStateFromPathRef = React.useRef(getStateFromPath);\n const getPathFromStateRef = React.useRef(getPathFromState);\n const getActionFromStateRef = React.useRef(getActionFromState);\n\n React.useEffect(() => {\n enabledRef.current = enabled;\n configRef.current = config;\n getStateFromPathRef.current = getStateFromPath;\n getPathFromStateRef.current = getPathFromState;\n getActionFromStateRef.current = getActionFromState;\n });\n\n const validateRoutesNotExistInRootState = React.useCallback(\n (state: ResultState) => {\n const navigation = ref.current;\n const rootState = navigation?.getRootState();\n // Make sure that the routes in the state exist in the root navigator\n // Otherwise there's an error in the linking configuration\n return state?.routes.some((r) => !rootState?.routeNames.includes(r.name));\n },\n [ref]\n );\n\n const server = React.useContext(ServerContext);\n\n const getInitialState = React.useCallback(() => {\n let value: ResultState | undefined;\n\n if (enabledRef.current) {\n const location =\n server?.location ?? (typeof window !== 'undefined' ? window.location : undefined);\n\n const path = location ? location.pathname + location.search : undefined;\n\n if (path) {\n value = getStateFromPathRef.current(path, configRef.current);\n }\n\n // If the link were handled, it gets cleared in NavigationContainer\n onUnhandledLinking(path);\n }\n\n const thenable = {\n then(onfulfilled?: (state: ResultState | undefined) => void) {\n return Promise.resolve(onfulfilled ? onfulfilled(value) : value);\n },\n catch() {\n return thenable;\n },\n };\n\n return thenable as PromiseLike<ResultState | undefined>;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const previousIndexRef = React.useRef<number | undefined>(undefined);\n const previousStateRef = React.useRef<NavigationState | undefined>(undefined);\n const pendingPopStatePathRef = React.useRef<string | undefined>(undefined);\n\n React.useEffect(() => {\n previousIndexRef.current = history.index;\n\n return history.listen(() => {\n const navigation = ref.current;\n\n if (!navigation || !enabled) {\n return;\n }\n\n const { location } = window;\n\n const path = location.pathname + location.search + location.hash;\n const index = history.index;\n\n const previousIndex = previousIndexRef.current ?? 0;\n\n previousIndexRef.current = index;\n pendingPopStatePathRef.current = path;\n\n // When browser back/forward is clicked, we first need to check if state object for this index exists\n // If it does we'll reset to that state object\n // Otherwise, we'll handle it like a regular deep link\n const record = history.get(index);\n\n if (record?.path === path && record?.state) {\n navigation.resetRoot(record.state);\n return;\n }\n\n const state = getStateFromPathRef.current(path, configRef.current);\n\n // We should only dispatch an action when going forward\n // Otherwise the action will likely add items to history, which would mess things up\n if (state) {\n // If the link were handled, it gets cleared in NavigationContainer\n onUnhandledLinking(path);\n // Make sure that the routes in the state exist in the root navigator\n // Otherwise there's an error in the linking configuration\n if (validateRoutesNotExistInRootState(state)) {\n return;\n }\n\n if (\n index > previousIndex ||\n /* START FORK\n *\n * This is a workaround for React Navigation's handling of hashes (it doesn't handle them)\n * When you click on <a href=\"#hash\">, the browser will first fire a popstate event\n * and this callback will be called.\n *\n * From React Navigation's perspective, it's treating the new hash change like a back/forward\n * button press, so it thinks it should reset the state. When we should\n * be to be pushing the new state\n *\n * Our fix is to check if the index is the same as the previous index\n * and if the incoming path is the same as the old path but with the hash added,\n * then treat it as a push instead of a reset\n *\n * This also works for subsequent hash changes, as internally RN\n * doesn't store the hash in the history state.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/popstate_event#when_popstate_is_sent\n */\n (index === previousIndex && (!record || `${record?.path}${location.hash}` === path))\n // END FORK\n ) {\n const action = getActionFromStateRef.current(state, configRef.current);\n\n if (action !== undefined) {\n try {\n navigation.dispatch(action);\n } catch (e) {\n // Ignore any errors from deep linking.\n // This could happen in case of malformed links, navigation object not being initialized etc.\n console.warn(\n `An error occurred when trying to handle the link '${path}': ${\n typeof e === 'object' && e != null && 'message' in e ? e.message : e\n }`\n );\n }\n } else {\n navigation.resetRoot(state);\n }\n } else {\n navigation.resetRoot(state);\n }\n } else {\n // if current path didn't return any state, we should revert to initial state\n navigation.resetRoot(state);\n }\n });\n }, [enabled, history, onUnhandledLinking, ref, validateRoutesNotExistInRootState]);\n\n React.useEffect(() => {\n if (!enabled) {\n return;\n }\n\n const getPathForRoute = (\n route: ReturnType<typeof findFocusedRoute>,\n state: NavigationState\n ): string => {\n let path;\n\n // If the `route` object contains a `path`, use that path as long as `route.name` and `params` still match\n // This makes sure that we preserve the original URL for wildcard routes\n if (route?.path) {\n const stateForPath = getStateFromPathRef.current(route.path, configRef.current);\n\n if (stateForPath) {\n const focusedRoute = findFocusedRoute(stateForPath);\n\n if (\n focusedRoute &&\n focusedRoute.name === route.name &&\n isEqual({ ...focusedRoute.params }, { ...route.params })\n ) {\n // START FORK - Ensure paths coming from events (e.g refresh) have the base URL\n // path = route.path;\n path = appendBaseUrl(route.path);\n // END FORK\n }\n }\n }\n\n if (path == null) {\n path = getPathFromStateRef.current(state, configRef.current);\n }\n\n // START FORK - ExpoRouter manually handles hashes. This code is intentionally removed\n // const previousRoute = previousStateRef.current\n // ? findFocusedRoute(previousStateRef.current)\n // : undefined;\n\n // Preserve the hash if the route didn't change\n // if (\n // previousRoute &&\n // route &&\n // 'key' in previousRoute &&\n // 'key' in route &&\n // previousRoute.key === route.key\n // ) {\n // path = path + location.hash;\n // }\n // END FORK\n\n return path;\n };\n\n if (ref.current) {\n // We need to record the current metadata on the first render if they aren't set\n // This will allow the initial state to be in the history entry\n const state = ref.current.getRootState();\n\n if (state) {\n const route = findFocusedRoute(state);\n const path = getPathForRoute(route, state);\n\n if (previousStateRef.current === undefined) {\n previousStateRef.current = state;\n }\n\n history.replace({ path, state });\n }\n }\n\n const onStateChange = async () => {\n const navigation = ref.current;\n\n if (!navigation || !enabled) {\n return;\n }\n\n const previousState = previousStateRef.current;\n const state = navigation.getRootState();\n\n // root state may not available, for example when root navigators switch inside the container\n if (!state) {\n return;\n }\n\n const pendingPath = pendingPopStatePathRef.current;\n const route = findFocusedRoute(state);\n const path = getPathForRoute(route, state);\n\n previousStateRef.current = state;\n pendingPopStatePathRef.current = undefined;\n\n // To detect the kind of state change, we need to:\n // - Find the common focused navigation state in previous and current state\n // - If only the route keys changed, compare history/routes.length to check if we go back/forward/replace\n // - If no common focused navigation state found, it's a replace\n const [previousFocusedState, focusedState] = findMatchingState(previousState, state);\n\n if (\n previousFocusedState &&\n focusedState &&\n // We should only handle push/pop if path changed from what was in last `popstate`\n // Otherwise it's likely a change triggered by `popstate`\n path !== pendingPath\n ) {\n const historyDelta =\n (focusedState.history ? focusedState.history.length : focusedState.routes.length) -\n (previousFocusedState.history\n ? previousFocusedState.history.length\n : previousFocusedState.routes.length);\n\n if (historyDelta > 0) {\n // If history length is increased, we should pushState\n // Note that path might not actually change here, for example, drawer open should pushState\n history.push({ path, state });\n } else if (historyDelta < 0) {\n // If history length is decreased, i.e. entries were removed, we want to go back\n\n const nextIndex = history.backIndex({ path });\n const currentIndex = history.index;\n\n try {\n if (\n nextIndex !== -1 &&\n nextIndex < currentIndex &&\n // We should only go back if the entry exists and it's less than current index\n history.get(nextIndex - currentIndex)\n ) {\n // An existing entry for this path exists and it's less than current index, go back to that\n await history.go(nextIndex - currentIndex);\n } else {\n // We couldn't find an existing entry to go back to, so we'll go back by the delta\n // This won't be correct if multiple routes were pushed in one go before\n // Usually this shouldn't happen and this is a fallback for that\n await history.go(historyDelta);\n }\n\n // Store the updated state as well as fix the path if incorrect\n history.replace({ path, state });\n } catch {\n // The navigation was interrupted\n }\n } else {\n // If history length is unchanged, we want to replaceState\n history.replace({ path, state });\n }\n } else {\n // If no common navigation state was found, assume it's a replace\n // This would happen if the user did a reset/conditionally changed navigators\n history.replace({ path, state });\n }\n };\n\n // We debounce onStateChange coz we don't want multiple state changes to be handled at one time\n // This could happen since `history.go(n)` is asynchronous\n // If `pushState` or `replaceState` were called before `history.go(n)` completes, it'll mess stuff up\n return ref.current?.addListener('state', series(onStateChange));\n }, [enabled, history, ref]);\n\n return {\n getInitialState,\n };\n}\n\nexport function getInitialURLWithTimeout(): string | null | Promise<string | null> {\n return typeof window === 'undefined' ? '' : window.location.href;\n}\n"]}
1
+ {"version":3,"file":"useLinking.js","sourceRoot":"","sources":["../../src/fork/useLinking.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;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EAAE,CAAC,YAAY,CAAC,CAAC;wBACjC,CAAC;wBAED,+DAA+D;wBAC/D,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;oBACnC,CAAC;oBAAC,MAAM,CAAC;wBACP,iCAAiC;oBACnC,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,0DAA0D;oBAC1D,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;gBACnC,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,iEAAiE;gBACjE,6EAA6E;gBAC7E,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;YACnC,CAAC;QACH,CAAC,CAAC;QAEF,+FAA+F;QAC/F,0DAA0D;QAC1D,qGAAqG;QACrG,OAAO,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,IAAA,cAAM,EAAC,aAAa,CAAC,CAAC,CAAC;IAClE,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IAE5B,OAAO;QACL,eAAe;KAChB,CAAC;AACJ,CAAC;AAED,SAAgB,wBAAwB;IACtC,OAAO,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;AACnE,CAAC","sourcesContent":["import {\n LinkingOptions,\n findFocusedRoute,\n getActionFromState as getActionFromStateDefault,\n getPathFromState as getPathFromStateDefault,\n getStateFromPath as getStateFromPathDefault,\n type NavigationContainerRef,\n type NavigationState,\n type ParamListBase,\n useNavigationIndependentTree,\n} from '@react-navigation/native';\nimport isEqual from 'fast-deep-equal';\nimport * as React from 'react';\n\nimport { createMemoryHistory } from './createMemoryHistory';\nimport { appendBaseUrl } from './getPathFromState';\nimport { ServerContext } from '../global-state/serverLocationContext';\n\ntype ResultState = ReturnType<typeof getStateFromPathDefault>;\n\n/**\n * Find the matching navigation state that changed between 2 navigation states\n * e.g.: a -> b -> c -> d and a -> b -> c -> e -> f, if history in b changed, b is the matching state\n */\nconst findMatchingState = <T extends NavigationState>(\n a: T | undefined,\n b: T | undefined\n): [T | undefined, T | undefined] => {\n if (a === undefined || b === undefined || a.key !== b.key) {\n return [undefined, undefined];\n }\n\n // Tab and drawer will have `history` property, but stack will have history in `routes`\n const aHistoryLength = a.history ? a.history.length : a.routes.length;\n const bHistoryLength = b.history ? b.history.length : b.routes.length;\n\n const aRoute = a.routes[a.index];\n const bRoute = b.routes[b.index];\n\n const aChildState = aRoute.state as T | undefined;\n const bChildState = bRoute.state as T | undefined;\n\n // Stop here if this is the state object that changed:\n // - history length is different\n // - focused routes are different\n // - one of them doesn't have child state\n // - child state keys are different\n if (\n aHistoryLength !== bHistoryLength ||\n aRoute.key !== bRoute.key ||\n aChildState === undefined ||\n bChildState === undefined ||\n aChildState.key !== bChildState.key\n ) {\n return [a, b];\n }\n\n return findMatchingState(aChildState, bChildState);\n};\n\n/**\n * Run async function in series as it's called.\n */\nexport const series = (cb: () => Promise<void>) => {\n let queue = Promise.resolve();\n const callback = () => {\n queue = queue.then(cb);\n };\n return callback;\n};\n\nconst linkingHandlers: symbol[] = [];\n\ntype Options = LinkingOptions<ParamListBase>;\n\nexport function useLinking(\n ref: React.RefObject<NavigationContainerRef<ParamListBase> | null>,\n {\n enabled = true,\n config,\n getStateFromPath = getStateFromPathDefault,\n getPathFromState = getPathFromStateDefault,\n getActionFromState = getActionFromStateDefault,\n }: Options,\n onUnhandledLinking: (lastUnhandledLining: string | undefined) => void\n) {\n const independent = useNavigationIndependentTree();\n\n React.useEffect(() => {\n if (process.env.NODE_ENV === 'production') {\n return undefined;\n }\n\n if (independent) {\n return undefined;\n }\n\n if (enabled !== false && linkingHandlers.length) {\n console.error(\n [\n 'Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:',\n \"- You don't have multiple NavigationContainers in the app each with 'linking' enabled\",\n '- Only a single instance of the root component is rendered',\n ]\n .join('\\n')\n .trim()\n );\n }\n\n const handler = Symbol();\n\n if (enabled !== false) {\n linkingHandlers.push(handler);\n }\n\n return () => {\n const index = linkingHandlers.indexOf(handler);\n\n if (index > -1) {\n linkingHandlers.splice(index, 1);\n }\n };\n }, [enabled, independent]);\n\n const [history] = React.useState(createMemoryHistory);\n\n // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners\n // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`\n // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect\n const enabledRef = React.useRef(enabled);\n const configRef = React.useRef(config);\n const getStateFromPathRef = React.useRef(getStateFromPath);\n const getPathFromStateRef = React.useRef(getPathFromState);\n const getActionFromStateRef = React.useRef(getActionFromState);\n\n React.useEffect(() => {\n enabledRef.current = enabled;\n configRef.current = config;\n getStateFromPathRef.current = getStateFromPath;\n getPathFromStateRef.current = getPathFromState;\n getActionFromStateRef.current = getActionFromState;\n });\n\n const validateRoutesNotExistInRootState = React.useCallback(\n (state: ResultState) => {\n const navigation = ref.current;\n const rootState = navigation?.getRootState();\n // Make sure that the routes in the state exist in the root navigator\n // Otherwise there's an error in the linking configuration\n return state?.routes.some((r) => !rootState?.routeNames.includes(r.name));\n },\n [ref]\n );\n\n const server = React.use(ServerContext);\n\n const getInitialState = React.useCallback(() => {\n let value: ResultState | undefined;\n\n if (enabledRef.current) {\n const location =\n server?.location ?? (typeof window !== 'undefined' ? window.location : undefined);\n\n const path = location ? location.pathname + location.search : undefined;\n\n if (path) {\n value = getStateFromPathRef.current(path, configRef.current);\n }\n\n // If the link were handled, it gets cleared in NavigationContainer\n onUnhandledLinking(path);\n }\n\n const thenable = {\n then(onfulfilled?: (state: ResultState | undefined) => void) {\n return Promise.resolve(onfulfilled ? onfulfilled(value) : value);\n },\n catch() {\n return thenable;\n },\n };\n\n return thenable as PromiseLike<ResultState | undefined>;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const previousIndexRef = React.useRef<number | undefined>(undefined);\n const previousStateRef = React.useRef<NavigationState | undefined>(undefined);\n const pendingPopStatePathRef = React.useRef<string | undefined>(undefined);\n\n React.useEffect(() => {\n previousIndexRef.current = history.index;\n\n return history.listen(() => {\n const navigation = ref.current;\n\n if (!navigation || !enabled) {\n return;\n }\n\n const { location } = window;\n\n const path = location.pathname + location.search + location.hash;\n const index = history.index;\n\n const previousIndex = previousIndexRef.current ?? 0;\n\n previousIndexRef.current = index;\n pendingPopStatePathRef.current = path;\n\n // When browser back/forward is clicked, we first need to check if state object for this index exists\n // If it does we'll reset to that state object\n // Otherwise, we'll handle it like a regular deep link\n const record = history.get(index);\n\n if (record?.path === path && record?.state) {\n navigation.resetRoot(record.state);\n return;\n }\n\n const state = getStateFromPathRef.current(path, configRef.current);\n\n // We should only dispatch an action when going forward\n // Otherwise the action will likely add items to history, which would mess things up\n if (state) {\n // If the link were handled, it gets cleared in NavigationContainer\n onUnhandledLinking(path);\n // Make sure that the routes in the state exist in the root navigator\n // Otherwise there's an error in the linking configuration\n if (validateRoutesNotExistInRootState(state)) {\n return;\n }\n\n if (\n index > previousIndex ||\n /* START FORK\n *\n * This is a workaround for React Navigation's handling of hashes (it doesn't handle them)\n * When you click on <a href=\"#hash\">, the browser will first fire a popstate event\n * and this callback will be called.\n *\n * From React Navigation's perspective, it's treating the new hash change like a back/forward\n * button press, so it thinks it should reset the state. When we should\n * be to be pushing the new state\n *\n * Our fix is to check if the index is the same as the previous index\n * and if the incoming path is the same as the old path but with the hash added,\n * then treat it as a push instead of a reset\n *\n * This also works for subsequent hash changes, as internally RN\n * doesn't store the hash in the history state.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/popstate_event#when_popstate_is_sent\n */\n (index === previousIndex && (!record || `${record?.path}${location.hash}` === path))\n // END FORK\n ) {\n const action = getActionFromStateRef.current(state, configRef.current);\n\n if (action !== undefined) {\n try {\n navigation.dispatch(action);\n } catch (e) {\n // Ignore any errors from deep linking.\n // This could happen in case of malformed links, navigation object not being initialized etc.\n console.warn(\n `An error occurred when trying to handle the link '${path}': ${\n typeof e === 'object' && e != null && 'message' in e ? e.message : e\n }`\n );\n }\n } else {\n navigation.resetRoot(state);\n }\n } else {\n navigation.resetRoot(state);\n }\n } else {\n // if current path didn't return any state, we should revert to initial state\n navigation.resetRoot(state);\n }\n });\n }, [enabled, history, onUnhandledLinking, ref, validateRoutesNotExistInRootState]);\n\n React.useEffect(() => {\n if (!enabled) {\n return;\n }\n\n const getPathForRoute = (\n route: ReturnType<typeof findFocusedRoute>,\n state: NavigationState\n ): string => {\n let path;\n\n // If the `route` object contains a `path`, use that path as long as `route.name` and `params` still match\n // This makes sure that we preserve the original URL for wildcard routes\n if (route?.path) {\n const stateForPath = getStateFromPathRef.current(route.path, configRef.current);\n\n if (stateForPath) {\n const focusedRoute = findFocusedRoute(stateForPath);\n\n if (\n focusedRoute &&\n focusedRoute.name === route.name &&\n isEqual({ ...focusedRoute.params }, { ...route.params })\n ) {\n // START FORK - Ensure paths coming from events (e.g refresh) have the base URL\n // path = route.path;\n path = appendBaseUrl(route.path);\n // END FORK\n }\n }\n }\n\n if (path == null) {\n path = getPathFromStateRef.current(state, configRef.current);\n }\n\n // START FORK - ExpoRouter manually handles hashes. This code is intentionally removed\n // const previousRoute = previousStateRef.current\n // ? findFocusedRoute(previousStateRef.current)\n // : undefined;\n\n // Preserve the hash if the route didn't change\n // if (\n // previousRoute &&\n // route &&\n // 'key' in previousRoute &&\n // 'key' in route &&\n // previousRoute.key === route.key\n // ) {\n // path = path + location.hash;\n // }\n // END FORK\n\n return path;\n };\n\n if (ref.current) {\n // We need to record the current metadata on the first render if they aren't set\n // This will allow the initial state to be in the history entry\n const state = ref.current.getRootState();\n\n if (state) {\n const route = findFocusedRoute(state);\n const path = getPathForRoute(route, state);\n\n if (previousStateRef.current === undefined) {\n previousStateRef.current = state;\n }\n\n history.replace({ path, state });\n }\n }\n\n const onStateChange = async () => {\n const navigation = ref.current;\n\n if (!navigation || !enabled) {\n return;\n }\n\n const previousState = previousStateRef.current;\n const state = navigation.getRootState();\n\n // root state may not available, for example when root navigators switch inside the container\n if (!state) {\n return;\n }\n\n const pendingPath = pendingPopStatePathRef.current;\n const route = findFocusedRoute(state);\n const path = getPathForRoute(route, state);\n\n previousStateRef.current = state;\n pendingPopStatePathRef.current = undefined;\n\n // To detect the kind of state change, we need to:\n // - Find the common focused navigation state in previous and current state\n // - If only the route keys changed, compare history/routes.length to check if we go back/forward/replace\n // - If no common focused navigation state found, it's a replace\n const [previousFocusedState, focusedState] = findMatchingState(previousState, state);\n\n if (\n previousFocusedState &&\n focusedState &&\n // We should only handle push/pop if path changed from what was in last `popstate`\n // Otherwise it's likely a change triggered by `popstate`\n path !== pendingPath\n ) {\n const historyDelta =\n (focusedState.history ? focusedState.history.length : focusedState.routes.length) -\n (previousFocusedState.history\n ? previousFocusedState.history.length\n : previousFocusedState.routes.length);\n\n if (historyDelta > 0) {\n // If history length is increased, we should pushState\n // Note that path might not actually change here, for example, drawer open should pushState\n history.push({ path, state });\n } else if (historyDelta < 0) {\n // If history length is decreased, i.e. entries were removed, we want to go back\n\n const nextIndex = history.backIndex({ path });\n const currentIndex = history.index;\n\n try {\n if (\n nextIndex !== -1 &&\n nextIndex < currentIndex &&\n // We should only go back if the entry exists and it's less than current index\n history.get(nextIndex - currentIndex)\n ) {\n // An existing entry for this path exists and it's less than current index, go back to that\n await history.go(nextIndex - currentIndex);\n } else {\n // We couldn't find an existing entry to go back to, so we'll go back by the delta\n // This won't be correct if multiple routes were pushed in one go before\n // Usually this shouldn't happen and this is a fallback for that\n await history.go(historyDelta);\n }\n\n // Store the updated state as well as fix the path if incorrect\n history.replace({ path, state });\n } catch {\n // The navigation was interrupted\n }\n } else {\n // If history length is unchanged, we want to replaceState\n history.replace({ path, state });\n }\n } else {\n // If no common navigation state was found, assume it's a replace\n // This would happen if the user did a reset/conditionally changed navigators\n history.replace({ path, state });\n }\n };\n\n // We debounce onStateChange coz we don't want multiple state changes to be handled at one time\n // This could happen since `history.go(n)` is asynchronous\n // If `pushState` or `replaceState` were called before `history.go(n)` completes, it'll mess stuff up\n return ref.current?.addListener('state', series(onStateChange));\n }, [enabled, history, ref]);\n\n return {\n getInitialState,\n };\n}\n\nexport function getInitialURLWithTimeout(): string | null | Promise<string | null> {\n return typeof window === 'undefined' ? '' : window.location.href;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"routeInfo.d.ts","sourceRoot":"","sources":["../../src/global-state/routeInfo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAIxD,MAAM,MAAM,SAAS,GAAG;IACtB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IACnD,YAAY,EAAE,eAAe,CAAC;IAC9B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,SAS9B,CAAC;AAEF;;GAEG;AACH,KAAK,WAAW,GAAG,CAAC,iBAAiB,GAAG,eAAe,GAAG,YAAY,CAAC,eAAe,CAAC,CAAC,GAAG;IACzF,MAAM,EAAE;QACN,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,wBAAwB,CAAC;QAClC,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,WAAW,CAAC;KACrB,EAAE,CAAC;CACL,CAAC;AAEF,KAAK,wBAAwB,GACzB,MA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,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,wBAAwB,CAAC;CACnC,CAAC;AAEN,wBAAgB,qBAAqB,CAAC,KAAK,CAAC,EAAE,WAAW,GAAG,SAAS,CA8IpE"}
@@ -25,7 +25,7 @@ function getRouteInfoFromState(state) {
25
25
  const segments = [];
26
26
  const params = Object.create(null);
27
27
  while (state) {
28
- route = state.routes[0];
28
+ route = state.routes['index' in state && state.index ? state.index : 0];
29
29
  Object.assign(params, route.params);
30
30
  let routeName = route.name;
31
31
  if (routeName.startsWith('/')) {
@@ -41,7 +41,10 @@ function getRouteInfoFromState(state) {
41
41
  let routeParams = route.params;
42
42
  while (routeParams && 'screen' in routeParams) {
43
43
  if (typeof routeParams.screen === 'string') {
44
- segments.push(...routeParams.screen.split('/'));
44
+ const screen = routeParams.screen.startsWith('/')
45
+ ? routeParams.screen.slice(1)
46
+ : routeParams.screen;
47
+ segments.push(...screen.split('/'));
45
48
  }
46
49
  if (typeof routeParams.params === 'object' && !Array.isArray(routeParams.params)) {
47
50
  routeParams = routeParams.params;
@@ -51,7 +54,10 @@ function getRouteInfoFromState(state) {
51
54
  }
52
55
  }
53
56
  if (route.params && 'screen' in route.params && route.params.screen === 'string') {
54
- segments.push(route.params.screen);
57
+ const screen = route.params.screen.startsWith('/')
58
+ ? route.params.screen.slice(1)
59
+ : route.params.screen;
60
+ segments.push(...screen.split('/'));
55
61
  }
56
62
  if (segments[segments.length - 1] === 'index') {
57
63
  segments.pop();
@@ -1 +1 @@
1
- {"version":3,"file":"routeInfo.js","sourceRoot":"","sources":["../../src/global-state/routeInfo.ts"],"names":[],"mappings":";;;AA+CA,sDAwIC;AApLD,4CAAkD;AAClD,2EAA+D;AAYlD,QAAA,gBAAgB,GAAc;IACzC,mBAAmB,EAAE,EAAE;IACvB,YAAY,EAAE,IAAI,eAAe,EAAE;IACnC,QAAQ,EAAE,GAAG;IACb,MAAM,EAAE,EAAE;IACV,QAAQ,EAAE,EAAE;IACZ,kBAAkB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Y;QACZ,kBAAkB;QAClB,6CAA6C;QAC7C,OAAO,EAAE,KAAK;KACf,CAAC;AACJ,CAAC","sourcesContent":["import type { NavigationState, PartialState } from '@react-navigation/native';\n\nimport type { FocusedRouteState } from './router-store';\nimport { INTERNAL_SLOT_NAME } from '../constants';\nimport { appendBaseUrl } from '../fork/getPathFromState-forks';\n\nexport type UrlObject = {\n unstable_globalHref: string;\n pathname: string;\n readonly params: Record<string, string | string[]>;\n searchParams: URLSearchParams;\n segments: string[];\n pathnameWithParams: string;\n isIndex: boolean;\n};\n\nexport const defaultRouteInfo: UrlObject = {\n unstable_globalHref: '',\n searchParams: new URLSearchParams(),\n pathname: '/',\n params: {},\n segments: [],\n pathnameWithParams: '/',\n // TODO: Remove this, it is not used anywhere\n isIndex: false,\n};\n\n/**\n * A better typed version of `FocusedRouteState` that is easier to parse\n */\ntype StrictState = (FocusedRouteState | NavigationState | PartialState<NavigationState>) & {\n routes: {\n key?: string;\n name: string;\n params?: StrictFocusedRouteParams;\n path?: string;\n state?: StrictState;\n }[];\n};\n\ntype StrictFocusedRouteParams =\n | Record<string, string | string[]>\n | {\n screen?: string;\n params?: StrictFocusedRouteParams;\n };\n\nexport function getRouteInfoFromState(state?: StrictState): UrlObject {\n if (!state) return defaultRouteInfo;\n\n let route = state.routes[0];\n if (route.name !== INTERNAL_SLOT_NAME) {\n throw new Error(`Expected the first route to be ${INTERNAL_SLOT_NAME}, but got ${route.name}`);\n }\n\n state = route.state;\n\n const segments: string[] = [];\n const params: UrlObject['params'] = Object.create(null);\n\n while (state) {\n route = state.routes[0];\n\n Object.assign(params, route.params);\n\n let routeName = route.name;\n if (routeName.startsWith('/')) {\n routeName = routeName.slice(1);\n }\n\n segments.push(...routeName.split('/'));\n state = route.state;\n }\n\n /**\n * If React Navigation didn't render the entire tree (e.g it was interrupted in a layout)\n * then the state maybe incomplete. The reset of the path is in the params, instead of being a route\n */\n let routeParams: StrictFocusedRouteParams | undefined = route.params;\n while (routeParams && 'screen' in routeParams) {\n if (typeof routeParams.screen === 'string') {\n segments.push(...routeParams.screen.split('/'));\n }\n\n if (typeof routeParams.params === 'object' && !Array.isArray(routeParams.params)) {\n routeParams = routeParams.params;\n } else {\n routeParams = undefined;\n }\n }\n\n if (route.params && 'screen' in route.params && route.params.screen === 'string') {\n segments.push(route.params.screen);\n }\n\n if (segments[segments.length - 1] === 'index') {\n segments.pop();\n }\n\n delete params['screen'];\n delete params['params'];\n\n const pathParams = new Set<string>();\n\n const pathname =\n '/' +\n segments\n .filter((segment) => {\n return !(segment.startsWith('(') && segment.endsWith(')'));\n })\n .flatMap((segment) => {\n if (segment === '+not-found') {\n const notFoundPath = params['not-found'];\n\n pathParams.add('not-found');\n\n if (typeof notFoundPath === 'undefined') {\n // Not founds are optional, do nothing if its not present\n return [];\n } else if (Array.isArray(notFoundPath)) {\n return notFoundPath;\n } else {\n return [notFoundPath];\n }\n } else if (segment.startsWith('[...') && segment.endsWith(']')) {\n let paramName = segment.slice(4, -1);\n\n // Legacy for React Navigation optional params\n if (paramName.endsWith('?')) {\n paramName = paramName.slice(0, -1);\n }\n\n const values = params[paramName];\n pathParams.add(paramName);\n\n // Catchall params are optional\n return values || [];\n } else if (segment.startsWith('[') && segment.endsWith(']')) {\n const paramName = segment.slice(1, -1);\n const value = params[paramName];\n pathParams.add(paramName);\n\n // Optional params are optional\n return value ? [value] : [];\n } else {\n return [segment];\n }\n })\n .join('/');\n\n const searchParams = new URLSearchParams(\n Object.entries(params).flatMap(([key, value]) => {\n // Search params should not include path params\n if (pathParams.has(key)) {\n return [];\n } else if (Array.isArray(value)) {\n return value.map((v) => [key, v]);\n }\n return [[key, value]];\n })\n );\n\n let hash: string | undefined;\n if (searchParams.has('#')) {\n hash = searchParams.get('#') || undefined;\n searchParams.delete('#');\n }\n\n // We cannot use searchParams.size because it is not included in the React Native polyfill\n const searchParamString = searchParams.toString();\n let pathnameWithParams = searchParamString ? pathname + '?' + searchParamString : pathname;\n pathnameWithParams = hash ? pathnameWithParams + '#' + hash : pathnameWithParams;\n\n return {\n segments,\n pathname,\n params,\n unstable_globalHref: appendBaseUrl(pathnameWithParams),\n searchParams,\n pathnameWithParams,\n // TODO: Remove this, it is not used anywhere\n isIndex: false,\n };\n}\n"]}
1
+ {"version":3,"file":"routeInfo.js","sourceRoot":"","sources":["../../src/global-state/routeInfo.ts"],"names":[],"mappings":";;;AA+CA,sDA8IC;AA1LD,4CAAkD;AAClD,2EAA+D;AAYlD,QAAA,gBAAgB,GAAc;IACzC,mBAAmB,EAAE,EAAE;IACvB,YAAY,EAAE,IAAI,eAAe,EAAE;IACnC,QAAQ,EAAE,GAAG;IACb,MAAM,EAAE,EAAE;IACV,QAAQ,EAAE,EAAE;IACZ,kBAAkB,EAAE,GAAG;IACvB,6CAA6C;IAC7C,OAAO,EAAE,KAAK;CACf,CAAC;AAsBF,SAAgB,qBAAqB,CAAC,KAAmB;IACvD,IAAI,CAAC,KAAK;QAAE,OAAO,wBAAgB,CAAC;IAEpC,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC5B,IAAI,KAAK,CAAC,IAAI,KAAK,8BAAkB,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,kCAAkC,8BAAkB,aAAa,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IACjG,CAAC;IAED,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAEpB,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,MAAM,MAAM,GAAwB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAExD,OAAO,KAAK,EAAE,CAAC;QACb,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,IAAI,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAExE,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,C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AC,EAAE,CAAC;YACxB,OAAO,EAAE,CAAC;QACZ,CAAC;aAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QACpC,CAAC;QACD,OAAO,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;IACxB,CAAC,CAAC,CACH,CAAC;IAEF,IAAI,IAAwB,CAAC;IAC7B,IAAI,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,IAAI,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC;QAC1C,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,0FAA0F;IAC1F,MAAM,iBAAiB,GAAG,YAAY,CAAC,QAAQ,EAAE,CAAC;IAClD,IAAI,kBAAkB,GAAG,iBAAiB,CAAC,CAAC,CAAC,QAAQ,GAAG,GAAG,GAAG,iBAAiB,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC3F,kBAAkB,GAAG,IAAI,CAAC,CAAC,CAAC,kBAAkB,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,kBAAkB,CAAC;IAEjF,OAAO;QACL,QAAQ;QACR,QAAQ;QACR,MAAM;QACN,mBAAmB,EAAE,IAAA,sCAAa,EAAC,kBAAkB,CAAC;QACtD,YAAY;QACZ,kBAAkB;QAClB,6CAA6C;QAC7C,OAAO,EAAE,KAAK;KACf,CAAC;AACJ,CAAC","sourcesContent":["import type { NavigationState, PartialState } from '@react-navigation/native';\n\nimport type { FocusedRouteState } from './router-store';\nimport { INTERNAL_SLOT_NAME } from '../constants';\nimport { appendBaseUrl } from '../fork/getPathFromState-forks';\n\nexport type UrlObject = {\n unstable_globalHref: string;\n pathname: string;\n readonly params: Record<string, string | string[]>;\n searchParams: URLSearchParams;\n segments: string[];\n pathnameWithParams: string;\n isIndex: boolean;\n};\n\nexport const defaultRouteInfo: UrlObject = {\n unstable_globalHref: '',\n searchParams: new URLSearchParams(),\n pathname: '/',\n params: {},\n segments: [],\n pathnameWithParams: '/',\n // TODO: Remove this, it is not used anywhere\n isIndex: false,\n};\n\n/**\n * A better typed version of `FocusedRouteState` that is easier to parse\n */\ntype StrictState = (FocusedRouteState | NavigationState | PartialState<NavigationState>) & {\n routes: {\n key?: string;\n name: string;\n params?: StrictFocusedRouteParams;\n path?: string;\n state?: StrictState;\n }[];\n};\n\ntype StrictFocusedRouteParams =\n | Record<string, string | string[]>\n | {\n screen?: string;\n params?: StrictFocusedRouteParams;\n };\n\nexport function getRouteInfoFromState(state?: StrictState): UrlObject {\n if (!state) return defaultRouteInfo;\n\n let route = state.routes[0];\n if (route.name !== INTERNAL_SLOT_NAME) {\n throw new Error(`Expected the first route to be ${INTERNAL_SLOT_NAME}, but got ${route.name}`);\n }\n\n state = route.state;\n\n const segments: string[] = [];\n const params: UrlObject['params'] = Object.create(null);\n\n while (state) {\n route = state.routes['index' in state && state.index ? state.index : 0];\n\n Object.assign(params, route.params);\n\n let routeName = route.name;\n if (routeName.startsWith('/')) {\n routeName = routeName.slice(1);\n }\n\n segments.push(...routeName.split('/'));\n state = route.state;\n }\n\n /**\n * If React Navigation didn't render the entire tree (e.g it was interrupted in a layout)\n * then the state maybe incomplete. The reset of the path is in the params, instead of being a route\n */\n let routeParams: StrictFocusedRouteParams | undefined = route.params;\n while (routeParams && 'screen' in routeParams) {\n if (typeof routeParams.screen === 'string') {\n const screen = routeParams.screen.startsWith('/')\n ? routeParams.screen.slice(1)\n : routeParams.screen;\n segments.push(...screen.split('/'));\n }\n\n if (typeof routeParams.params === 'object' && !Array.isArray(routeParams.params)) {\n routeParams = routeParams.params;\n } else {\n routeParams = undefined;\n }\n }\n\n if (route.params && 'screen' in route.params && route.params.screen === 'string') {\n const screen = route.params.screen.startsWith('/')\n ? route.params.screen.slice(1)\n : route.params.screen;\n segments.push(...screen.split('/'));\n }\n\n if (segments[segments.length - 1] === 'index') {\n segments.pop();\n }\n\n delete params['screen'];\n delete params['params'];\n\n const pathParams = new Set<string>();\n\n const pathname =\n '/' +\n segments\n .filter((segment) => {\n return !(segment.startsWith('(') && segment.endsWith(')'));\n })\n .flatMap((segment) => {\n if (segment === '+not-found') {\n const notFoundPath = params['not-found'];\n\n pathParams.add('not-found');\n\n if (typeof notFoundPath === 'undefined') {\n // Not founds are optional, do nothing if its not present\n return [];\n } else if (Array.isArray(notFoundPath)) {\n return notFoundPath;\n } else {\n return [notFoundPath];\n }\n } else if (segment.startsWith('[...') && segment.endsWith(']')) {\n let paramName = segment.slice(4, -1);\n\n // Legacy for React Navigation optional params\n if (paramName.endsWith('?')) {\n paramName = paramName.slice(0, -1);\n }\n\n const values = params[paramName];\n pathParams.add(paramName);\n\n // Catchall params are optional\n return values || [];\n } else if (segment.startsWith('[') && segment.endsWith(']')) {\n const paramName = segment.slice(1, -1);\n const value = params[paramName];\n pathParams.add(paramName);\n\n // Optional params are optional\n return value ? [value] : [];\n } else {\n return [segment];\n }\n })\n .join('/');\n\n const searchParams = new URLSearchParams(\n Object.entries(params).flatMap(([key, value]) => {\n // Search params should not include path params\n if (pathParams.has(key)) {\n return [];\n } else if (Array.isArray(value)) {\n return value.map((v) => [key, v]);\n }\n return [[key, value]];\n })\n );\n\n let hash: string | undefined;\n if (searchParams.has('#')) {\n hash = searchParams.get('#') || undefined;\n searchParams.delete('#');\n }\n\n // We cannot use searchParams.size because it is not included in the React Native polyfill\n const searchParamString = searchParams.toString();\n let pathnameWithParams = searchParamString ? pathname + '?' + searchParamString : pathname;\n pathnameWithParams = hash ? pathnameWithParams + '#' + hash : pathnameWithParams;\n\n return {\n segments,\n pathname,\n params,\n unstable_globalHref: appendBaseUrl(pathnameWithParams),\n searchParams,\n pathnameWithParams,\n // TODO: Remove this, it is not used anywhere\n isIndex: false,\n };\n}\n"]}
@@ -12,10 +12,9 @@ export type RouterStore = typeof store;
12
12
  export declare const store: {
13
13
  shouldShowTutorial(): boolean;
14
14
  readonly state: ReactNavigationState | undefined;
15
- readonly focusedState: import("@react-navigation/core/lib/typescript/src/NavigationFocusedRouteStateContext").FocusedRouteState | undefined;
16
15
  readonly navigationRef: NavigationContainerRefWithCurrent<ReactNavigation.RootParamList>;
17
16
  readonly routeNode: RouteNode | null;
18
- getRouteInfo(state?: FocusedRouteState | ReactNavigationState | undefined): UrlObject;
17
+ getRouteInfo(): UrlObject;
19
18
  readonly redirects: StoreRedirects[];
20
19
  readonly rootComponent: ComponentType<any>;
21
20
  readonly linking: ExpoLinkingOptions | undefined;
@@ -26,10 +25,9 @@ export declare const store: {
26
25
  export declare function useStore(context: RequireContext, linkingConfigOptions: LinkingConfigOptions, serverUrl?: string): {
27
26
  shouldShowTutorial(): boolean;
28
27
  readonly state: ReactNavigationState | undefined;
29
- readonly focusedState: import("@react-navigation/core/lib/typescript/src/NavigationFocusedRouteStateContext").FocusedRouteState | undefined;
30
28
  readonly navigationRef: NavigationContainerRefWithCurrent<ReactNavigation.RootParamList>;
31
29
  readonly routeNode: RouteNode | null;
32
- getRouteInfo(state?: FocusedRouteState | ReactNavigationState | undefined): UrlObject;
30
+ getRouteInfo(): UrlObject;
33
31
  readonly redirects: StoreRedirects[];
34
32
  readonly rootComponent: ComponentType<any>;
35
33
  readonly linking: ExpoLinkingOptions | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"router-store.d.ts","sourceRoot":"","sources":["../../src/global-state/router-store.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,iCAAiC,EACjC,eAAe,EACf,YAAY,EAEZ,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,aAAa,EAA6C,MAAM,OAAO,CAAC;AAGjF,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAoB,MAAM,qBA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,aAAa,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAK1C,MAAM,MAAM,cAAc,GAAG,SAAS,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;AACxE,MAAM,MAAM,oBAAoB,GAAG,eAAe,GAAG,YAAY,CAAC,eAAe,CAAC,CAAC;AACnF,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC,CAAC;AAEhF,MAAM,MAAM,WAAW,GAAG,OAAO,KAAK,CAAC;AAsBvC,eAAO,MAAM,KAAK;;;;;oBAaA,SAAS;;;;2BAYF,iBAAiB;;;CAiDzC,CAAC;AAEF,wBAAgB,QAAQ,CACtB,OAAO,EAAE,cAAc,EACvB,oBAAoB,EAAE,oBAAoB,EAC1C,SAAS,CAAC,EAAE,MAAM;;;;;oBAlEF,SAAS;;;;2BAYF,iBAAiB;;;EAsIzC;AAUD,wBAAgB,YAAY,cAE3B"}
@@ -65,25 +65,14 @@ exports.store = {
65
65
  get state() {
66
66
  return storeRef.current.state;
67
67
  },
68
- get focusedState() {
69
- return storeRef.current.focusedState;
70
- },
71
68
  get navigationRef() {
72
69
  return storeRef.current.navigationRef;
73
70
  },
74
71
  get routeNode() {
75
72
  return storeRef.current.routeNode;
76
73
  },
77
- getRouteInfo(state = storeRef.current.focusedState) {
78
- if (!state) {
79
- return routeInfo_1.defaultRouteInfo;
80
- }
81
- let routeInfo = routeInfoCache.get(state);
82
- if (!routeInfo) {
83
- routeInfo = (0, routeInfo_1.getRouteInfoFromState)(state);
84
- routeInfoCache.set(state, routeInfo);
85
- }
86
- return routeInfo;
74
+ getRouteInfo() {
75
+ return storeRef.current.routeInfo || routeInfo_1.defaultRouteInfo;
87
76
  },
88
77
  get redirects() {
89
78
  return storeRef.current.redirects || [];
@@ -95,7 +84,8 @@ exports.store = {
95
84
  return storeRef.current.linking;
96
85
  },
97
86
  setFocusedState(state) {
98
- storeRef.current.focusedState = state;
87
+ const routeInfo = getCachedRouteInfo(state);
88
+ storeRef.current.routeInfo = routeInfo;
99
89
  },
100
90
  onReady() {
101
91
  if (!hasAttemptedToHideSplash) {
@@ -106,8 +96,21 @@ exports.store = {
106
96
  });
107
97
  }
108
98
  storeRef.current.navigationRef.addListener('state', (e) => {
109
- if (e.data.state) {
110
- storeRef.current.state = e.data.state;
99
+ if (!e.data.state) {
100
+ return;
101
+ }
102
+ let isStale = false;
103
+ let state = e.data.state;
104
+ while (!isStale && state) {
105
+ isStale = state.stale;
106
+ state =
107
+ state.routes?.['index' in state && typeof state.index === 'number'
108
+ ? state.index
109
+ : state.routes.length - 1]?.state;
110
+ }
111
+ storeRef.current.state = e.data.state;
112
+ if (!isStale) {
113
+ storeRef.current.routeInfo = getCachedRouteInfo(e.data.state);
111
114
  }
112
115
  for (const callback of routeInfoSubscribers) {
113
116
  callback();
@@ -177,7 +180,7 @@ function useStore(context, linkingConfigOptions, serverUrl) {
177
180
  state: initialState,
178
181
  };
179
182
  if (initialState) {
180
- storeRef.current.focusedState = initialState;
183
+ storeRef.current.routeInfo = getCachedRouteInfo(initialState);
181
184
  }
182
185
  (0, react_1.useEffect)(() => {
183
186
  return () => {
@@ -200,4 +203,22 @@ const routeInfoSubscribe = (callback) => {
200
203
  function useRouteInfo() {
201
204
  return (0, react_1.useSyncExternalStore)(routeInfoSubscribe, exports.store.getRouteInfo, exports.store.getRouteInfo);
202
205
  }
206
+ function getCachedRouteInfo(state) {
207
+ let routeInfo = routeInfoCache.get(state);
208
+ if (!routeInfo) {
209
+ routeInfo = (0, routeInfo_1.getRouteInfoFromState)(state);
210
+ const previousRouteInfo = storeRef.current.routeInfo;
211
+ if (previousRouteInfo) {
212
+ const areEqual = routeInfo.segments.length === previousRouteInfo.segments.length &&
213
+ routeInfo.segments.every((segment, index) => previousRouteInfo.segments[index] === segment) &&
214
+ routeInfo.pathnameWithParams === previousRouteInfo.pathnameWithParams;
215
+ if (areEqual) {
216
+ // If they are equal, keep the previous route info for object reference equality
217
+ routeInfo = previousRouteInfo;
218
+ }
219
+ }
220
+ routeInfoCache.set(state, routeInfo);
221
+ }
222
+ return routeInfo;
223
+ }
203
224
  //# sourceMappingURL=router-store.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"router-store.js","sourceRoot":"","sources":["../../src/global-state/router-store.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2Hb,4BAmFC;AAUD,oCAEC;AAxND,qDAMkC;AAClC,oEAAuC;AACvC,iCAAiF;AACjF,+CAAwC;AAGxC,2EAAqE;AACrE,0DAAiG;AACjG,0EAAiE;AACjE,4CAAyC;AAEzC,2CAAiF;AAEjF,8CAA2D;AAC3D,sCAAoD;AACpD,8DAAgD;AAmBhD,MAAM,QAAQ,GAAG;IACf,OAAO,EAAE,EAAc;CACxB,CAAC;AAEF,MAAM,cAAc,GAAG,IAAI,OAAO,EAAuD,CAAC;AAE1F,IAAI,0BAA8C,CAAC;AACnD,IAAI,wBAAwB,GAAG,KAAK,CAAC;AAExB,QAAA,KAAK,GAAG;IACnB,kBAAkB;QAChB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAC;IAC/E,CAAC;IACD,IAAI,KAAK;QACP,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC;IAChC,CAAC;IACD,IAAI,YAAY;QACd,OAAO,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC;IACvC,CAAC;IACD,IAAI,aAAa;QACf,OAAO,QAAQ,CAAC,OAAO,CAAC,aAAa,CAAC;IACxC,CAAC;IACD,IAAI,SAAS;QACX,OAAO,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC;IACpC,CAAC;IACD,YAAY,CACV,QAA8D,QAAQ,CAAC,OAAO,CAAC,YAAY;QAE3F,IAAI,CAAC,KAAK,EAAE,C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D,oBAAoB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACnC,OAAO,GAAG,EAAE;QACV,oBAAoB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,SAAgB,YAAY;IAC1B,OAAO,IAAA,4BAAoB,EAAC,kBAAkB,EAAE,aAAK,CAAC,YAAY,EAAE,aAAK,CAAC,YAAY,CAAC,CAAC;AAC1F,CAAC","sourcesContent":["'use client';\n\nimport {\n NavigationContainerRefWithCurrent,\n NavigationState,\n PartialState,\n useNavigationContainerRef,\n useStateForPath,\n} from '@react-navigation/native';\nimport Constants from 'expo-constants';\nimport { ComponentType, Fragment, useEffect, useSyncExternalStore } from 'react';\nimport { Platform } from 'react-native';\n\nimport { RouteNode } from '../Route';\nimport { routePatternToRegex } from '../fork/getStateFromPath-forks';\nimport { ExpoLinkingOptions, LinkingConfigOptions, getLinkingConfig } from '../getLinkingConfig';\nimport { parseRouteSegments } from '../getReactNavigationConfig';\nimport { getRoutes } from '../getRoutes';\nimport { RedirectConfig } from '../getRoutesCore';\nimport { defaultRouteInfo, getRouteInfoFromState, UrlObject } from './routeInfo';\nimport { RequireContext } from '../types';\nimport { getQualifiedRouteComponent } from '../useScreens';\nimport { shouldLinkExternally } from '../utils/url';\nimport * as SplashScreen from '../views/Splash';\n\nexport type StoreRedirects = readonly [RegExp, RedirectConfig, boolean];\nexport type ReactNavigationState = NavigationState | PartialState<NavigationState>;\nexport type FocusedRouteState = NonNullable<ReturnType<typeof useStateForPath>>;\n\nexport type RouterStore = typeof store;\n\ntype StoreRef = {\n navigationRef: NavigationContainerRefWithCurrent<ReactNavigation.RootParamList>;\n routeNode: RouteNode | null;\n rootComponent: ComponentType<any>;\n state?: ReactNavigationState;\n focusedState?: FocusedRouteState;\n linking?: ExpoLinkingOptions;\n config: any;\n redirects: StoreRedirects[];\n};\n\nconst storeRef = {\n current: {} as StoreRef,\n};\n\nconst routeInfoCache = new WeakMap<FocusedRouteState | ReactNavigationState, UrlObject>();\n\nlet splashScreenAnimationFrame: number | undefined;\nlet hasAttemptedToHideSplash = false;\n\nexport const store = {\n shouldShowTutorial() {\n return !storeRef.current.routeNode && process.env.NODE_ENV === 'development';\n },\n get state() {\n return storeRef.current.state;\n },\n get focusedState() {\n return storeRef.current.focusedState;\n },\n get navigationRef() {\n return storeRef.current.navigationRef;\n },\n get routeNode() {\n return storeRef.current.routeNode;\n },\n getRouteInfo(\n state: FocusedRouteState | ReactNavigationState | undefined = storeRef.current.focusedState\n ): UrlObject {\n if (!state) {\n return defaultRouteInfo;\n }\n\n let routeInfo = routeInfoCache.get(state);\n\n if (!routeInfo) {\n routeInfo = getRouteInfoFromState(state);\n routeInfoCache.set(state, routeInfo);\n }\n\n return routeInfo;\n },\n get redirects() {\n return storeRef.current.redirects || [];\n },\n get rootComponent() {\n return storeRef.current.rootComponent;\n },\n get linking() {\n return storeRef.current.linking;\n },\n setFocusedState(state: FocusedRouteState) {\n storeRef.current.focusedState = state;\n },\n onReady() {\n if (!hasAttemptedToHideSplash) {\n hasAttemptedToHideSplash = true;\n // NOTE(EvanBacon): `navigationRef.isReady` is sometimes not true when state is called initially.\n splashScreenAnimationFrame = requestAnimationFrame(() => {\n SplashScreen._internal_maybeHideAsync?.();\n });\n }\n\n storeRef.current.navigationRef.addListener('state', (e) => {\n if (e.data.state) {\n storeRef.current.state = e.data.state;\n }\n\n for (const callback of routeInfoSubscribers) {\n callback();\n }\n });\n },\n assertIsReady() {\n if (!storeRef.current.navigationRef.isReady()) {\n throw new Error(\n 'Attempted to navigate before mounting the Root Layout component. Ensure the Root Layout component is rendering a Slot, or other navigator on the first render.'\n );\n }\n },\n};\n\nexport function useStore(\n context: RequireContext,\n linkingConfigOptions: LinkingConfigOptions,\n serverUrl?: string\n) {\n const navigationRef = useNavigationContainerRef();\n const config = Constants.expoConfig?.extra?.router;\n\n let linking: ExpoLinkingOptions | undefined;\n let rootComponent: ComponentType<any> = Fragment;\n let initialState: ReactNavigationState | undefined;\n\n const routeNode = getRoutes(context, {\n ...config,\n ignoreEntryPoints: true,\n platform: Platform.OS,\n });\n\n const redirects: StoreRedirects[] = [config?.redirects, config?.rewrites]\n .filter(Boolean)\n .flat()\n .map((route) => {\n return [\n routePatternToRegex(parseRouteSegments(route.source)),\n route,\n shouldLinkExternally(route.destination),\n ];\n });\n\n if (routeNode) {\n // We have routes, so get the linking config and the root component\n linking = getLinkingConfig(routeNode, context, () => store.getRouteInfo(), {\n metaOnly: linkingConfigOptions.metaOnly,\n serverUrl,\n redirects,\n });\n rootComponent = getQualifiedRouteComponent(routeNode);\n\n // By default React Navigation is async and does not render anything in the first pass as it waits for `getInitialURL`\n // This will cause static rendering to fail, which once performs a single pass.\n // If the initialURL is a string, we can prefetch the state and routeInfo, skipping React Navigation's async behavior.\n const initialURL = linking?.getInitialURL?.();\n if (typeof initialURL === 'string') {\n initialState = linking.getStateFromPath(initialURL, linking.config);\n const initialRouteInfo = getRouteInfoFromState(initialState);\n routeInfoCache.set(initialState as any, initialRouteInfo);\n }\n } else {\n // Only error in production, in development we will show the onboarding screen\n if (process.env.NODE_ENV === 'production') {\n throw new Error('No routes found');\n }\n\n // In development, we will show the onboarding screen\n rootComponent = Fragment;\n }\n\n storeRef.current = {\n navigationRef,\n routeNode,\n config,\n rootComponent,\n linking,\n redirects,\n state: initialState,\n };\n\n if (initialState) {\n storeRef.current.focusedState = initialState as FocusedRouteState;\n }\n\n useEffect(() => {\n return () => {\n // listener();\n\n if (splashScreenAnimationFrame) {\n cancelAnimationFrame(splashScreenAnimationFrame);\n splashScreenAnimationFrame = undefined;\n }\n };\n });\n\n return store;\n}\n\nconst routeInfoSubscribers = new Set<() => void>();\nconst routeInfoSubscribe = (callback: () => void) => {\n routeInfoSubscribers.add(callback);\n return () => {\n routeInfoSubscribers.delete(callback);\n };\n};\n\nexport function useRouteInfo() {\n return useSyncExternalStore(routeInfoSubscribe, store.getRouteInfo, store.getRouteInfo);\n}\n"]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cesContent":["'use client';\n\nimport {\n NavigationContainerRefWithCurrent,\n NavigationState,\n PartialState,\n useNavigationContainerRef,\n useStateForPath,\n} from '@react-navigation/native';\nimport Constants from 'expo-constants';\nimport { ComponentType, Fragment, useEffect, useSyncExternalStore } from 'react';\nimport { Platform } from 'react-native';\n\nimport { RouteNode } from '../Route';\nimport { routePatternToRegex } from '../fork/getStateFromPath-forks';\nimport { ExpoLinkingOptions, LinkingConfigOptions, getLinkingConfig } from '../getLinkingConfig';\nimport { parseRouteSegments } from '../getReactNavigationConfig';\nimport { getRoutes } from '../getRoutes';\nimport { RedirectConfig } from '../getRoutesCore';\nimport { defaultRouteInfo, getRouteInfoFromState, UrlObject } from './routeInfo';\nimport { RequireContext } from '../types';\nimport { getQualifiedRouteComponent } from '../useScreens';\nimport { shouldLinkExternally } from '../utils/url';\nimport * as SplashScreen from '../views/Splash';\n\nexport type StoreRedirects = readonly [RegExp, RedirectConfig, boolean];\nexport type ReactNavigationState = NavigationState | PartialState<NavigationState>;\nexport type FocusedRouteState = NonNullable<ReturnType<typeof useStateForPath>>;\n\nexport type RouterStore = typeof store;\n\ntype StoreRef = {\n navigationRef: NavigationContainerRefWithCurrent<ReactNavigation.RootParamList>;\n routeNode: RouteNode | null;\n rootComponent: ComponentType<any>;\n state?: ReactNavigationState;\n linking?: ExpoLinkingOptions;\n config: any;\n redirects: StoreRedirects[];\n routeInfo?: UrlObject;\n};\n\nconst storeRef = {\n current: {} as StoreRef,\n};\n\nconst routeInfoCache = new WeakMap<FocusedRouteState | ReactNavigationState, UrlObject>();\n\nlet splashScreenAnimationFrame: number | undefined;\nlet hasAttemptedToHideSplash = false;\n\nexport const store = {\n shouldShowTutorial() {\n return !storeRef.current.routeNode && process.env.NODE_ENV === 'development';\n },\n get state() {\n return storeRef.current.state;\n },\n get navigationRef() {\n return storeRef.current.navigationRef;\n },\n get routeNode() {\n return storeRef.current.routeNode;\n },\n getRouteInfo(): UrlObject {\n return storeRef.current.routeInfo || defaultRouteInfo;\n },\n get redirects() {\n return storeRef.current.redirects || [];\n },\n get rootComponent() {\n return storeRef.current.rootComponent;\n },\n get linking() {\n return storeRef.current.linking;\n },\n setFocusedState(state: FocusedRouteState) {\n const routeInfo = getCachedRouteInfo(state);\n storeRef.current.routeInfo = routeInfo;\n },\n onReady() {\n if (!hasAttemptedToHideSplash) {\n hasAttemptedToHideSplash = true;\n // NOTE(EvanBacon): `navigationRef.isReady` is sometimes not true when state is called initially.\n splashScreenAnimationFrame = requestAnimationFrame(() => {\n SplashScreen._internal_maybeHideAsync?.();\n });\n }\n\n storeRef.current.navigationRef.addListener('state', (e) => {\n if (!e.data.state) {\n return;\n }\n\n let isStale: boolean | undefined = false;\n let state: ReactNavigationState | undefined = e.data.state;\n\n while (!isStale && state) {\n isStale = state.stale;\n state =\n state.routes?.[\n 'index' in state && typeof state.index === 'number'\n ? state.index\n : state.routes.length - 1\n ]?.state;\n }\n\n storeRef.current.state = e.data.state;\n\n if (!isStale) {\n storeRef.current.routeInfo = getCachedRouteInfo(e.data.state);\n }\n\n for (const callback of routeInfoSubscribers) {\n callback();\n }\n });\n },\n assertIsReady() {\n if (!storeRef.current.navigationRef.isReady()) {\n throw new Error(\n 'Attempted to navigate before mounting the Root Layout component. Ensure the Root Layout component is rendering a Slot, or other navigator on the first render.'\n );\n }\n },\n};\n\nexport function useStore(\n context: RequireContext,\n linkingConfigOptions: LinkingConfigOptions,\n serverUrl?: string\n) {\n const navigationRef = useNavigationContainerRef();\n const config = Constants.expoConfig?.extra?.router;\n\n let linking: ExpoLinkingOptions | undefined;\n let rootComponent: ComponentType<any> = Fragment;\n let initialState: ReactNavigationState | undefined;\n\n const routeNode = getRoutes(context, {\n ...config,\n ignoreEntryPoints: true,\n platform: Platform.OS,\n });\n\n const redirects: StoreRedirects[] = [config?.redirects, config?.rewrites]\n .filter(Boolean)\n .flat()\n .map((route) => {\n return [\n routePatternToRegex(parseRouteSegments(route.source)),\n route,\n shouldLinkExternally(route.destination),\n ];\n });\n\n if (routeNode) {\n // We have routes, so get the linking config and the root component\n linking = getLinkingConfig(routeNode, context, () => store.getRouteInfo(), {\n metaOnly: linkingConfigOptions.metaOnly,\n serverUrl,\n redirects,\n });\n rootComponent = getQualifiedRouteComponent(routeNode);\n\n // By default React Navigation is async and does not render anything in the first pass as it waits for `getInitialURL`\n // This will cause static rendering to fail, which once performs a single pass.\n // If the initialURL is a string, we can prefetch the state and routeInfo, skipping React Navigation's async behavior.\n const initialURL = linking?.getInitialURL?.();\n if (typeof initialURL === 'string') {\n initialState = linking.getStateFromPath(initialURL, linking.config);\n const initialRouteInfo = getRouteInfoFromState(initialState);\n routeInfoCache.set(initialState as any, initialRouteInfo);\n }\n } else {\n // Only error in production, in development we will show the onboarding screen\n if (process.env.NODE_ENV === 'production') {\n throw new Error('No routes found');\n }\n\n // In development, we will show the onboarding screen\n rootComponent = Fragment;\n }\n\n storeRef.current = {\n navigationRef,\n routeNode,\n config,\n rootComponent,\n linking,\n redirects,\n state: initialState,\n };\n\n if (initialState) {\n storeRef.current.routeInfo = getCachedRouteInfo(initialState);\n }\n\n useEffect(() => {\n return () => {\n // listener();\n\n if (splashScreenAnimationFrame) {\n cancelAnimationFrame(splashScreenAnimationFrame);\n splashScreenAnimationFrame = undefined;\n }\n };\n });\n\n return store;\n}\n\nconst routeInfoSubscribers = new Set<() => void>();\nconst routeInfoSubscribe = (callback: () => void) => {\n routeInfoSubscribers.add(callback);\n return () => {\n routeInfoSubscribers.delete(callback);\n };\n};\n\nexport function useRouteInfo() {\n return useSyncExternalStore(routeInfoSubscribe, store.getRouteInfo, store.getRouteInfo);\n}\n\nfunction getCachedRouteInfo(state: ReactNavigationState) {\n let routeInfo = routeInfoCache.get(state);\n\n if (!routeInfo) {\n routeInfo = getRouteInfoFromState(state);\n\n const previousRouteInfo = storeRef.current.routeInfo;\n if (previousRouteInfo) {\n const areEqual =\n routeInfo.segments.length === previousRouteInfo.segments.length &&\n routeInfo.segments.every(\n (segment, index) => previousRouteInfo.segments[index] === segment\n ) &&\n routeInfo.pathnameWithParams === previousRouteInfo.pathnameWithParams;\n\n if (areEqual) {\n // If they are equal, keep the previous route info for object reference equality\n routeInfo = previousRouteInfo;\n }\n }\n\n routeInfoCache.set(state, routeInfo);\n }\n\n return routeInfo;\n}\n"]}
@@ -1,10 +1,9 @@
1
1
  export declare const StoreContext: import("react").Context<{
2
2
  shouldShowTutorial(): boolean;
3
3
  readonly state: import("./router-store").ReactNavigationState | undefined;
4
- readonly focusedState: import("@react-navigation/core/lib/typescript/src/NavigationFocusedRouteStateContext").FocusedRouteState | undefined;
5
4
  readonly navigationRef: import("@react-navigation/core").NavigationContainerRefWithCurrent<ReactNavigation.RootParamList>;
6
5
  readonly routeNode: import("../Route").RouteNode | null;
7
- getRouteInfo(state?: import("./router-store").FocusedRouteState | import("./router-store").ReactNavigationState | undefined): import("./routeInfo").UrlObject;
6
+ getRouteInfo(): import("./routeInfo").UrlObject;
8
7
  readonly redirects: import("./router-store").StoreRedirects[];
9
8
  readonly rootComponent: import("react").ComponentType<any>;
10
9
  readonly linking: import("../getLinkingConfig").ExpoLinkingOptions | undefined;
@@ -15,10 +14,9 @@ export declare const StoreContext: import("react").Context<{
15
14
  export declare const useExpoRouterStore: () => {
16
15
  shouldShowTutorial(): boolean;
17
16
  readonly state: import("./router-store").ReactNavigationState | undefined;
18
- readonly focusedState: import("@react-navigation/core/lib/typescript/src/NavigationFocusedRouteStateContext").FocusedRouteState | undefined;
19
17
  readonly navigationRef: import("@react-navigation/core").NavigationContainerRefWithCurrent<ReactNavigation.RootParamList>;
20
18
  readonly routeNode: import("../Route").RouteNode | null;
21
- getRouteInfo(state?: import("./router-store").FocusedRouteState | import("./router-store").ReactNavigationState | undefined): import("./routeInfo").UrlObject;
19
+ getRouteInfo(): import("./routeInfo").UrlObject;
22
20
  readonly redirects: import("./router-store").StoreRedirects[];
23
21
  readonly rootComponent: import("react").ComponentType<any>;
24
22
  readonly linking: import("../getLinkingConfig").ExpoLinkingOptions | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"storeContext.d.ts","sourceRoot":"","sources":["../../src/global-state/storeContext.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,YAAY;;;;;;;;;;;;;SAA0C,CAAC;AAEpE,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;CAA2B,CAAC"}
1
+ {"version":3,"file":"storeContext.d.ts","sourceRoot":"","sources":["../../src/global-state/storeContext.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,YAAY;;;;;;;;;;;;SAA0C,CAAC;AAEpE,eAAO,MAAM,kBAAkB;;;;;;;;;;;;CAA2B,CAAC"}
package/build/hooks.js CHANGED
@@ -112,7 +112,7 @@ function useGlobalSearchParams() {
112
112
  return (0, router_store_1.useRouteInfo)().params;
113
113
  }
114
114
  function useLocalSearchParams() {
115
- const params = react_1.default.useContext(Route_1.LocalRouteParamsContext) ?? {};
115
+ const params = react_1.default.use(Route_1.LocalRouteParamsContext) ?? {};
116
116
  return Object.fromEntries(Object.entries(params).map(([key, value]) => {
117
117
  if (Array.isArray(value)) {
118
118
  return [