expo-router 5.0.2-preview.6 → 5.0.2
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.
- package/build/ExpoRoot.d.ts.map +1 -1
- package/build/ExpoRoot.js +19 -18
- package/build/ExpoRoot.js.map +1 -1
- package/build/constants.d.ts +2 -0
- package/build/constants.d.ts.map +1 -0
- package/build/constants.js +5 -0
- package/build/constants.js.map +1 -0
- package/build/{link/useDomComponentNavigation.d.ts → domComponents/emitDomEvent.d.ts} +2 -4
- package/build/domComponents/emitDomEvent.d.ts.map +1 -0
- package/build/domComponents/emitDomEvent.js +32 -0
- package/build/domComponents/emitDomEvent.js.map +1 -0
- package/build/domComponents/events.d.ts +6 -0
- package/build/domComponents/events.d.ts.map +1 -0
- package/build/domComponents/events.js +9 -0
- package/build/domComponents/events.js.map +1 -0
- package/build/domComponents/useDomComponentNavigation.d.ts +2 -0
- package/build/domComponents/useDomComponentNavigation.d.ts.map +1 -0
- package/build/domComponents/useDomComponentNavigation.js +37 -0
- package/build/domComponents/useDomComponentNavigation.js.map +1 -0
- package/build/fork/getStateFromPath.d.ts +1 -2
- package/build/fork/getStateFromPath.d.ts.map +1 -1
- package/build/fork/getStateFromPath.js +11 -5
- package/build/fork/getStateFromPath.js.map +1 -1
- package/build/getLinkingConfig.d.ts +6 -7
- package/build/getLinkingConfig.d.ts.map +1 -1
- package/build/getLinkingConfig.js +10 -9
- package/build/getLinkingConfig.js.map +1 -1
- package/build/getRoutesRedirects.d.ts +2 -0
- package/build/getRoutesRedirects.d.ts.map +1 -1
- package/build/getRoutesRedirects.js +56 -0
- package/build/getRoutesRedirects.js.map +1 -1
- package/build/global-state/routeInfo.d.ts +29 -4
- package/build/global-state/routeInfo.d.ts.map +1 -1
- package/build/global-state/routeInfo.js +124 -55
- package/build/global-state/routeInfo.js.map +1 -1
- package/build/global-state/router-store.d.ts +35 -83
- package/build/global-state/router-store.d.ts.map +1 -1
- package/build/global-state/router-store.js +138 -238
- package/build/global-state/router-store.js.map +1 -1
- package/build/global-state/routing.d.ts +13 -14
- package/build/global-state/routing.d.ts.map +1 -1
- package/build/global-state/routing.js +32 -30
- package/build/global-state/routing.js.map +1 -1
- package/build/global-state/storeContext.d.ts +29 -0
- package/build/global-state/storeContext.d.ts.map +1 -0
- package/build/global-state/storeContext.js +9 -0
- package/build/global-state/storeContext.js.map +1 -0
- package/build/hooks.d.ts +13 -4
- package/build/hooks.d.ts.map +1 -1
- package/build/hooks.js +13 -23
- package/build/hooks.js.map +1 -1
- package/build/imperative-api.d.ts.map +1 -1
- package/build/imperative-api.js +13 -13
- package/build/imperative-api.js.map +1 -1
- package/build/layouts/DrawerClient.d.ts +3 -2
- package/build/layouts/DrawerClient.d.ts.map +1 -1
- package/build/layouts/StackClient.d.ts +5 -2
- package/build/layouts/StackClient.d.ts.map +1 -1
- package/build/layouts/StackClient.js +2 -0
- package/build/layouts/StackClient.js.map +1 -1
- package/build/layouts/TabsClient.d.ts +3 -2
- package/build/layouts/TabsClient.d.ts.map +1 -1
- package/build/layouts/withLayoutContext.d.ts +6 -1
- package/build/layouts/withLayoutContext.d.ts.map +1 -1
- package/build/layouts/withLayoutContext.js +28 -20
- package/build/layouts/withLayoutContext.js.map +1 -1
- package/build/link/linking.d.ts +2 -2
- package/build/link/linking.d.ts.map +1 -1
- package/build/link/linking.js +5 -4
- package/build/link/linking.js.map +1 -1
- package/build/link/useLinkToPathProps.d.ts.map +1 -1
- package/build/link/useLinkToPathProps.js +4 -5
- package/build/link/useLinkToPathProps.js.map +1 -1
- package/build/link/useLoadedNavigation.d.ts.map +1 -1
- package/build/link/useLoadedNavigation.js +2 -3
- package/build/link/useLoadedNavigation.js.map +1 -1
- package/build/primitives.d.ts.map +1 -1
- package/build/primitives.js +1 -0
- package/build/primitives.js.map +1 -1
- package/build/testing-library/index.d.ts +3 -3
- package/build/testing-library/index.d.ts.map +1 -1
- package/build/testing-library/index.js +5 -10
- package/build/testing-library/index.js.map +1 -1
- package/build/ui/common.d.ts.map +1 -1
- package/build/ui/common.js +4 -3
- package/build/ui/common.js.map +1 -1
- package/build/useNavigation.d.ts.map +1 -1
- package/build/useNavigation.js +47 -56
- package/build/useNavigation.js.map +1 -1
- package/build/useScreens.d.ts +2 -2
- package/build/useScreens.d.ts.map +1 -1
- package/build/useScreens.js +18 -3
- package/build/useScreens.js.map +1 -1
- package/build/views/Navigator.d.ts.map +1 -1
- package/build/views/Navigator.js +4 -4
- package/build/views/Navigator.js.map +1 -1
- package/build/views/Protected.d.ts +8 -0
- package/build/views/Protected.d.ts.map +1 -0
- package/build/views/Protected.js +11 -0
- package/build/views/Protected.js.map +1 -0
- package/build/views/Screen.d.ts +4 -0
- package/build/views/Screen.d.ts.map +1 -1
- package/build/views/Screen.js +52 -4
- package/build/views/Screen.js.map +1 -1
- package/build/views/Sitemap.js +5 -2
- package/build/views/Sitemap.js.map +1 -1
- package/package.json +3 -3
- package/build/link/useDomComponentNavigation.d.ts.map +0 -1
- package/build/link/useDomComponentNavigation.js +0 -68
- package/build/link/useDomComponentNavigation.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing-library/index.tsx"],"names":[],"mappings":"AAAA,OAAO,UAAU,CAAC;AAClB,OAAO,SAAS,CAAC;AAEjB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing-library/index.tsx"],"names":[],"mappings":"AAAA,OAAO,UAAU,CAAC;AAClB,OAAO,SAAS,CAAC;AAEjB,OAAO,EAAO,MAAM,EAAwB,MAAM,+BAA+B,CAAC;AAGlF,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAS,MAAM,8BAA8B,CAAC;AAI3E,cAAc,+BAA+B,CAAC;AA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D;gBACxC,MAAM;IAOlB,qEAAqE;;IAIrE,wEAAwE;sBACtD,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,SAAS,MAAM;IAMvD,qEAAqE;;CAItE,CAAC"}
|
|
@@ -27,14 +27,10 @@ const mock_config_1 = require("./mock-config");
|
|
|
27
27
|
Object.defineProperty(exports, "getMockConfig", { enumerable: true, get: function () { return mock_config_1.getMockConfig; } });
|
|
28
28
|
Object.defineProperty(exports, "getMockContext", { enumerable: true, get: function () { return mock_config_1.getMockContext; } });
|
|
29
29
|
const ExpoRoot_1 = require("../ExpoRoot");
|
|
30
|
-
const getPathFromState_1 = require("../fork/getPathFromState");
|
|
31
30
|
const router_store_1 = require("../global-state/router-store");
|
|
32
31
|
const imperative_api_1 = require("../imperative-api");
|
|
33
32
|
// re-export everything
|
|
34
33
|
__exportStar(require("@testing-library/react-native"), exports);
|
|
35
|
-
afterAll(() => {
|
|
36
|
-
router_store_1.store.cleanup();
|
|
37
|
-
});
|
|
38
34
|
function renderRouter(context = './app', { initialUrl = '/', linking, ...options } = {}) {
|
|
39
35
|
jest.useFakeTimers();
|
|
40
36
|
const mockContext = (0, mock_config_1.getMockContext)(context);
|
|
@@ -46,22 +42,21 @@ function renderRouter(context = './app', { initialUrl = '/', linking, ...options
|
|
|
46
42
|
* Some updates are async and we need to wait for them to complete, otherwise will we get a false positive.
|
|
47
43
|
* (that the app will briefly be in the right state, but then update to an invalid state)
|
|
48
44
|
*/
|
|
49
|
-
router_store_1.store.subscribeToRootState(() => jest.runOnlyPendingTimers());
|
|
50
45
|
return Object.assign(result, {
|
|
51
46
|
getPathname() {
|
|
52
|
-
return router_store_1.store.
|
|
47
|
+
return router_store_1.store.getRouteInfo().pathname;
|
|
53
48
|
},
|
|
54
49
|
getSegments() {
|
|
55
|
-
return router_store_1.store.
|
|
50
|
+
return router_store_1.store.getRouteInfo().segments;
|
|
56
51
|
},
|
|
57
52
|
getSearchParams() {
|
|
58
|
-
return router_store_1.store.
|
|
53
|
+
return router_store_1.store.getRouteInfo().params;
|
|
59
54
|
},
|
|
60
55
|
getPathnameWithParams() {
|
|
61
|
-
return
|
|
56
|
+
return router_store_1.store.getRouteInfo().pathnameWithParams;
|
|
62
57
|
},
|
|
63
58
|
getRouterState() {
|
|
64
|
-
return router_store_1.store.
|
|
59
|
+
return router_store_1.store.state;
|
|
65
60
|
},
|
|
66
61
|
});
|
|
67
62
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing-library/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing-library/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AA0CA,oCAsCC;AAhFD,oBAAkB;AAClB,mBAAiB;AAEjB,gEAAkF;AAClF,kDAA0B;AAE1B,+CAAiF;AAkCrD,8FAlCA,2BAAa,OAkCA;AAAE,+FAlCA,4BAAc,OAkCA;AAjCzD,0CAAuC;AAEvC,+DAA2E;AAC3E,sDAA2C;AAE3C,uBAAuB;AACvB,gEAA8C;AA6B9C,SAAgB,YAAY,CAC1B,UAA6B,OAAO,EACpC,EAAE,UAAU,GAAG,GAAG,EAAE,OAAO,EAAE,GAAG,OAAO,KAA0B,EAAE;IAEnE,IAAI,CAAC,aAAa,EAAE,CAAC;IAErB,MAAM,WAAW,GAAG,IAAA,4BAAc,EAAC,OAAO,CAAC,CAAC;IAE5C,qCAAqC;IACrC,OAAO,CAAC,GAAG,CAAC,uBAAuB,GAAG,MAAM,CAAC;IAE7C,MAAM,MAAM,GAAG,IAAA,qBAAM,EACnB,CAAC,mBAAQ,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,EAAG,EAC1E,OAAO,CACR,CAAC;IAEF;;;;OAIG;IACH,OAAO,MAAM,CAAC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BAAG,EAAC,GAAG,EAAE,CAAC,uBAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QACzB,IAAI,IAAI,EAAE,CAAC;YACT,MAAM,CAAC,qBAAM,CAAC,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IACD,qEAAqE;IACrE,SAAS;QACP,OAAO,uBAAM,CAAC,SAAS,EAAE,CAAC;IAC5B,CAAC;IACD,wEAAwE;IACxE,SAAS,CAAC,MAA8B,EAAE,IAAa;QACrD,uBAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACzB,IAAI,IAAI,EAAE,CAAC;YACT,MAAM,CAAC,qBAAM,CAAC,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IACD,qEAAqE;IACrE,UAAU;QACR,IAAA,kBAAG,EAAC,GAAG,EAAE,CAAC,uBAAM,CAAC,UAAU,EAAE,CAAC,CAAC;IACjC,CAAC;CACF,CAAC","sourcesContent":["import './expect';\nimport './mocks';\n\nimport { act, render, RenderResult, screen } from '@testing-library/react-native';\nimport React from 'react';\n\nimport { MockContextConfig, getMockConfig, getMockContext } from './mock-config';\nimport { ExpoRoot } from '../ExpoRoot';\nimport { ExpoLinkingOptions } from '../getLinkingConfig';\nimport { ReactNavigationState, store } from '../global-state/router-store';\nimport { router } from '../imperative-api';\n\n// re-export everything\nexport * from '@testing-library/react-native';\n\nexport type RenderRouterOptions = Parameters<typeof render>[1] & {\n initialUrl?: any;\n linking?: Partial<ExpoLinkingOptions>;\n};\n\ntype Result = ReturnType<typeof render> & {\n getPathname(): string;\n getPathnameWithParams(): string;\n getSegments(): string[];\n getSearchParams(): Record<string, string | string[]>;\n getRouterState(): ReactNavigationState | undefined;\n};\n\ndeclare global {\n namespace jest {\n interface Matchers<R> {\n toHavePathname(pathname: string): R;\n toHavePathnameWithParams(pathname: string): R;\n toHaveSegments(segments: string[]): R;\n toHaveSearchParams(params: Record<string, string | string[]>): R;\n getRouterState(): ReactNavigationState | undefined;\n }\n }\n}\n\nexport { MockContextConfig, getMockConfig, getMockContext };\n\nexport function renderRouter(\n context: MockContextConfig = './app',\n { initialUrl = '/', linking, ...options }: RenderRouterOptions = {}\n): Result {\n jest.useFakeTimers();\n\n const mockContext = getMockContext(context);\n\n // Force the render to be synchronous\n process.env.EXPO_ROUTER_IMPORT_MODE = 'sync';\n\n const result = render(\n <ExpoRoot context={mockContext} location={initialUrl} linking={linking} />,\n options\n );\n\n /**\n * This is a hack to ensure that React Navigation's state updates are processed before we run assertions.\n * Some updates are async and we need to wait for them to complete, otherwise will we get a false positive.\n * (that the app will briefly be in the right state, but then update to an invalid state)\n */\n return Object.assign(result, {\n getPathname(this: RenderResult): string {\n return store.getRouteInfo().pathname;\n },\n getSegments(this: RenderResult): string[] {\n return store.getRouteInfo().segments;\n },\n getSearchParams(this: RenderResult): Record<string, string | string[]> {\n return store.getRouteInfo().params;\n },\n getPathnameWithParams(this: RenderResult): string {\n return store.getRouteInfo().pathnameWithParams;\n },\n getRouterState(this: RenderResult) {\n return store.state;\n },\n });\n}\n\nexport const testRouter = {\n /** Navigate to the provided pathname and the pathname */\n navigate(path: string) {\n act(() => router.navigate(path));\n expect(screen).toHavePathnameWithParams(path);\n },\n /** Push the provided pathname and assert the pathname */\n push(path: string) {\n act(() => router.push(path));\n expect(screen).toHavePathnameWithParams(path);\n },\n /** Replace with provided pathname and assert the pathname */\n replace(path: string) {\n act(() => router.replace(path));\n expect(screen).toHavePathnameWithParams(path);\n },\n /** Go back in history and asset the new pathname */\n back(path?: string) {\n expect(router.canGoBack()).toBe(true);\n act(() => router.back());\n if (path) {\n expect(screen).toHavePathnameWithParams(path);\n }\n },\n /** If there's history that supports invoking the `back` function. */\n canGoBack() {\n return router.canGoBack();\n },\n /** Update the current route query params and assert the new pathname */\n setParams(params: Record<string, string>, path?: string) {\n router.setParams(params);\n if (path) {\n expect(screen).toHavePathnameWithParams(path);\n }\n },\n /** If there's history that supports invoking the `back` function. */\n dismissAll() {\n act(() => router.dismissAll());\n },\n};\n"]}
|
package/build/ui/common.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/ui/common.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAC9F,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAKhC,eAAO,MAAM,QAAQ,EAAW,KAAK,CAAC,yBAAyB,CAC7D,SAAS,GAAG,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CACtC,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAW,KAAK,CAAC,yBAAyB,CACrE,SAAS,GAAG,KAAK,CAAC,aAAa,CAAC,YAAY,CAAC,CAC9C,CAAC;AAEF,MAAM,MAAM,aAAa,GACrB;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,GACD;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEN,KAAK,sBAAsB,GAAG,OAAO,CAAC,iBAAiB,EAAE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC,CAAC;AAC9E,KAAK,aAAa,GACd;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAA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ACrB;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,GACD;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEN,KAAK,sBAAsB,GAAG,OAAO,CAAC,iBAAiB,EAAE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC,CAAC;AAC9E,KAAK,aAAa,GACd;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,sBAAsB,CAAC;CAChC,GACD;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAErD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAE3E,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,aAAa,EAAE,EACzB,eAAe,EAAE,SAAS,EAC1B,OAAO,EAAE,cAAc,CAAC,aAAa,CAAC,EACtC,gBAAgB,EAAE,SAAS,GAAG,MAAM,EACpC,gBAAgB,EAAE,UAAU,EAC5B,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,MAAM;;;EAyInB;AAED,wBAAgB,aAAa,CAC3B,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,GAAG,SAAS,EAClE,YAAY,CAAC,EAAE,MAAM,GACpB,sBAAsB,CAsCxB"}
|
package/build/ui/common.js
CHANGED
|
@@ -45,11 +45,11 @@ function triggersToScreens(triggers, layoutRouteNode, linking, initialRouteName,
|
|
|
45
45
|
continue;
|
|
46
46
|
}
|
|
47
47
|
let routeState = state;
|
|
48
|
+
const targetStateName = layoutRouteNode.route || '__root';
|
|
48
49
|
// The state object is the current state from the rootNavigator
|
|
49
50
|
// We need to work out the state for just this trigger
|
|
50
51
|
while (state?.state) {
|
|
51
|
-
|
|
52
|
-
if (previousState.name === layoutRouteNode.route)
|
|
52
|
+
if (state.name === targetStateName)
|
|
53
53
|
break;
|
|
54
54
|
state = state.state.routes[state.state.index ?? state.state.routes.length - 1];
|
|
55
55
|
}
|
|
@@ -113,7 +113,8 @@ function triggersToScreens(triggers, layoutRouteNode, linking, initialRouteName,
|
|
|
113
113
|
function stateToAction(state, startAtRoute) {
|
|
114
114
|
const rootPayload = {};
|
|
115
115
|
let payload = rootPayload;
|
|
116
|
-
|
|
116
|
+
startAtRoute = startAtRoute === '' ? '__root' : startAtRoute;
|
|
117
|
+
let foundStartingPoint = startAtRoute === undefined || !state?.state;
|
|
117
118
|
while (state) {
|
|
118
119
|
if (foundStartingPoint) {
|
|
119
120
|
if (payload === rootPayload) {
|
package/build/ui/common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/ui/common.tsx"],"names":[],"mappings":";;;AA8CA,8CA8IC;AAED,sCAuCC;AA/ND,uCAA0E;AAC1E,8CAAsD;AAEtD,8CAA8C;AAC9C,iCAA8B;AAE9B,mFAAmF;AACtE,QAAA,QAAQ,GAAG,WAEvB,CAAC;AAEW,QAAA,gBAAgB,GAAG,WAE/B,CAAC;AA2BF,SAAgB,iBAAiB,CAC/B,QAAyB,EACzB,eAA0B,EAC1B,OAAsC,EACtC,gBAAoC,EACpC,gBAA4B,EAC5B,SAAoB,EACpB,UAAkB;IAElB,MAAM,OAAO,GAAoB,EAAE,CAAC;IAEpC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,OAAO,CAAC,IAAI,IAAI,gBAAgB,EAAE,CAAC;YACrC,MAAM,aAAa,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,CAAC;YAC9B,CAAC;YACD,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAEzD,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAE5D,IAAI,KAAK,EAAE,CAAC;gBACV,OAAO,CAAC,MAAM,KAAK,EAAE,CAAC;gBACtB,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;YAC3B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;gBAChC,kBAAkB,GAAG,IAAI,CAAC;YAC5B,CAAC;YACD,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YACtE,IAAI,SAAS,EAAE,CAAC;gBACd,KAAK,GAAG,SAAS,CAAC;YACpB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,WAAW;KACrB,CAAC;AACJ,CAAC","sourcesContent":["import { LinkingOptions, ParamListBase, PartialRoute, Route } from '@react-navigation/native';\nimport { ViewProps, View, SafeAreaView } from 'react-native';\n\nimport type { ExpoTabActionType } from './TabRouter';\nimport { UrlObject } from '../LocationProvider';\nimport { RouteNode } from '../Route';\nimport { resolveHref, resolveHrefStringWithSegments } from '../link/href';\nimport { sortRoutesWithInitial } from '../sortRoutes';\nimport { Href } from '../types';\nimport { routeToScreen } from '../useScreens';\nimport { Slot } from './Slot';\n\n// Fix the TypeScript types for <Slot />. It complains about the ViewProps[\"style\"]\nexport const ViewSlot = Slot as React.ForwardRefExoticComponent<\n ViewProps & React.RefAttributes<View>\n>;\n\nexport const SafeAreaViewSlot = Slot as React.ForwardRefExoticComponent<\n ViewProps & React.RefAttributes<SafeAreaView>\n>;\n\nexport type ScreenTrigger =\n | {\n type: 'internal';\n href: Href;\n name: string;\n }\n | {\n type: 'external';\n name: string;\n href: string;\n };\n\ntype JumpToNavigationAction = Extract<ExpoTabActionType, { type: 'JUMP_TO' }>;\ntype TriggerConfig =\n | {\n type: 'internal';\n name: string;\n href: string;\n routeNode: RouteNode;\n action: JumpToNavigationAction;\n }\n | { type: 'external'; name: string; href: string };\n\nexport type TriggerMap = Record<string, TriggerConfig & { index: number }>;\n\nexport function triggersToScreens(\n triggers: ScreenTrigger[],\n layoutRouteNode: RouteNode,\n linking: LinkingOptions<ParamListBase>,\n initialRouteName: undefined | string,\n parentTriggerMap: TriggerMap,\n routeInfo: UrlObject,\n contextKey: string\n) {\n const configs: TriggerConfig[] = [];\n\n for (const trigger of triggers) {\n if (trigger.name in parentTriggerMap) {\n const parentTrigger = parentTriggerMap[trigger.name];\n throw new Error(\n `Trigger ${JSON.stringify({\n name: trigger.name,\n href: trigger.href,\n })} has the same name as parent trigger ${JSON.stringify({\n name: parentTrigger.name,\n href: parentTrigger.href,\n })}. Triggers must have unique names.`\n );\n }\n\n if (trigger.type === 'external') {\n configs.push(trigger);\n continue;\n }\n\n let resolvedHref = resolveHref(trigger.href);\n\n if (resolvedHref.startsWith('../')) {\n throw new Error('Trigger href cannot link to a parent directory');\n }\n\n const segmentsWithoutGroups = contextKey.split('/').filter((segment) => {\n return !(segment.startsWith('(') && segment.endsWith(')'));\n });\n\n resolvedHref = resolveHrefStringWithSegments(\n resolvedHref,\n {\n ...routeInfo,\n segments: segmentsWithoutGroups,\n },\n { relativeToDirectory: true }\n );\n\n let state = linking.getStateFromPath?.(resolvedHref, linking.config)?.routes[0];\n\n if (!state) {\n // This shouldn't occur, as you should get the global +not-found\n console.warn(\n `Unable to find screen for trigger ${JSON.stringify(trigger)}. Does this point to a valid screen?`\n );\n continue;\n }\n\n let routeState = state;\n\n // The state object is the current state from the rootNavigator\n // We need to work out the state for just this trigger\n while (state?.state) {\n const previousState = state;\n if (previousState.name === layoutRouteNode.route) break;\n state = state.state.routes[state.state.index ?? state.state.routes.length - 1];\n }\n routeState = state.state?.routes[state.state.index ?? state.state.routes.length - 1] || state;\n\n const routeNode = layoutRouteNode.children.find((child) => child.route === routeState?.name);\n if (!routeNode) {\n console.warn(\n `Unable to find routeNode for trigger ${JSON.stringify(trigger)}. This might be a bug with Expo Router`\n );\n continue;\n }\n\n if (routeNode.generated && routeNode.internal && routeNode.route.includes('+not-found')) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n `Tab trigger '${trigger.name}' has the href '${trigger.href}' which points to a +not-found route.`\n );\n }\n continue;\n }\n\n const duplicateTrigger =\n trigger.type === 'internal' &&\n configs.find((config): config is Extract<TriggerConfig, { type: 'internal' }> => {\n if (config.type === 'external') {\n return false;\n }\n\n return config.routeNode.route === routeNode.route;\n });\n\n if (duplicateTrigger) {\n const duplicateTriggerText = `${JSON.stringify({ name: duplicateTrigger.name, href: duplicateTrigger.href })} and ${JSON.stringify({ name: trigger.name, href: trigger.href })}`;\n\n throw new Error(\n `A navigator cannot contain multiple trigger components that map to the same sub-segment. Consider adding a shared group and assigning a group to each trigger. Conflicting triggers:\\n\\t${duplicateTriggerText}.\\nBoth triggers map to route ${routeNode.route}.`\n );\n }\n\n configs.push({\n ...trigger,\n href: resolvedHref,\n routeNode,\n action: stateToAction(state, layoutRouteNode.route),\n });\n }\n\n const sortFn = sortRoutesWithInitial(initialRouteName);\n\n const sortedConfigs = configs.sort((a, b) => {\n // External routes should be last. They will eventually be dropped\n if (a.type === 'external' && b.type === 'external') {\n return 0;\n } else if (a.type === 'external') {\n return 1;\n } else if (b.type === 'external') {\n return -1;\n }\n\n return sortFn(a.routeNode, b.routeNode);\n });\n\n const children: React.JSX.Element[] = [];\n const triggerMap: TriggerMap = { ...parentTriggerMap };\n\n for (const [index, config] of sortedConfigs.entries()) {\n triggerMap[config.name] = { ...config, index };\n\n if (config.type === 'internal') {\n children.push(routeToScreen(config.routeNode));\n }\n }\n return {\n children,\n triggerMap,\n };\n}\n\nexport function stateToAction(\n state: PartialRoute<Route<string, object | undefined>> | undefined,\n startAtRoute?: string\n): JumpToNavigationAction {\n const rootPayload: any = {};\n let payload = rootPayload;\n\n let foundStartingPoint = !startAtRoute || !state?.state;\n\n while (state) {\n if (foundStartingPoint) {\n if (payload === rootPayload) {\n payload.name = state.name;\n } else {\n payload.screen = state.name;\n }\n payload.params = state.params ? { ...state.params } : {};\n\n state = state.state?.routes[state.state?.routes.length - 1];\n\n if (state) {\n payload.params ??= {};\n payload = payload.params;\n }\n } else {\n if (state.name === startAtRoute) {\n foundStartingPoint = true;\n }\n const nextState = state.state?.routes[state.state?.routes.length - 1];\n if (nextState) {\n state = nextState;\n }\n }\n }\n\n return {\n type: 'JUMP_TO',\n payload: rootPayload,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/ui/common.tsx"],"names":[],"mappings":";;;AA8CA,8CAgJC;AAED,sCAyCC;AAnOD,uCAA0E;AAC1E,8CAAsD;AAEtD,8CAA8C;AAC9C,iCAA8B;AAE9B,mFAAmF;AACtE,QAAA,QAAQ,GAAG,WAEvB,CAAC;AAEW,QAAA,gBAAgB,GAAG,WAE/B,CAAC;AA2BF,SAAgB,iBAAiB,CAC/B,QAAyB,EACzB,eAA0B,EAC1B,OAAsC,EACtC,gBAAoC,EACpC,gBAA4B,EAC5B,SAAoB,EACpB,UAAkB;IAElB,MAAM,OAAO,GAAoB,EAAE,CAAC;IAEpC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,OAAO,CAAC,IAAI,IAAI,gBAAgB,EAAE,CAAC;YACrC,MAAM,aAAa,GAAG,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACrD,MAAM,IAAI,KAAK,CACb,WAAW,IAAI,CAAC,S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AK,CAAC,IAAI,CAAC;YAC9B,CAAC;YACD,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAEzD,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAE5D,IAAI,KAAK,EAAE,CAAC;gBACV,OAAO,CAAC,MAAM,KAAK,EAAE,CAAC;gBACtB,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;YAC3B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;gBAChC,kBAAkB,GAAG,IAAI,CAAC;YAC5B,CAAC;YACD,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YACtE,IAAI,SAAS,EAAE,CAAC;gBACd,KAAK,GAAG,SAAS,CAAC;YACpB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,WAAW;KACrB,CAAC;AACJ,CAAC","sourcesContent":["import { LinkingOptions, ParamListBase, PartialRoute, Route } from '@react-navigation/native';\nimport { ViewProps, View, SafeAreaView } from 'react-native';\n\nimport type { ExpoTabActionType } from './TabRouter';\nimport { UrlObject } from '../LocationProvider';\nimport { RouteNode } from '../Route';\nimport { resolveHref, resolveHrefStringWithSegments } from '../link/href';\nimport { sortRoutesWithInitial } from '../sortRoutes';\nimport { Href } from '../types';\nimport { routeToScreen } from '../useScreens';\nimport { Slot } from './Slot';\n\n// Fix the TypeScript types for <Slot />. It complains about the ViewProps[\"style\"]\nexport const ViewSlot = Slot as React.ForwardRefExoticComponent<\n ViewProps & React.RefAttributes<View>\n>;\n\nexport const SafeAreaViewSlot = Slot as React.ForwardRefExoticComponent<\n ViewProps & React.RefAttributes<SafeAreaView>\n>;\n\nexport type ScreenTrigger =\n | {\n type: 'internal';\n href: Href;\n name: string;\n }\n | {\n type: 'external';\n name: string;\n href: string;\n };\n\ntype JumpToNavigationAction = Extract<ExpoTabActionType, { type: 'JUMP_TO' }>;\ntype TriggerConfig =\n | {\n type: 'internal';\n name: string;\n href: string;\n routeNode: RouteNode;\n action: JumpToNavigationAction;\n }\n | { type: 'external'; name: string; href: string };\n\nexport type TriggerMap = Record<string, TriggerConfig & { index: number }>;\n\nexport function triggersToScreens(\n triggers: ScreenTrigger[],\n layoutRouteNode: RouteNode,\n linking: LinkingOptions<ParamListBase>,\n initialRouteName: undefined | string,\n parentTriggerMap: TriggerMap,\n routeInfo: UrlObject,\n contextKey: string\n) {\n const configs: TriggerConfig[] = [];\n\n for (const trigger of triggers) {\n if (trigger.name in parentTriggerMap) {\n const parentTrigger = parentTriggerMap[trigger.name];\n throw new Error(\n `Trigger ${JSON.stringify({\n name: trigger.name,\n href: trigger.href,\n })} has the same name as parent trigger ${JSON.stringify({\n name: parentTrigger.name,\n href: parentTrigger.href,\n })}. Triggers must have unique names.`\n );\n }\n\n if (trigger.type === 'external') {\n configs.push(trigger);\n continue;\n }\n\n let resolvedHref = resolveHref(trigger.href);\n\n if (resolvedHref.startsWith('../')) {\n throw new Error('Trigger href cannot link to a parent directory');\n }\n\n const segmentsWithoutGroups = contextKey.split('/').filter((segment) => {\n return !(segment.startsWith('(') && segment.endsWith(')'));\n });\n\n resolvedHref = resolveHrefStringWithSegments(\n resolvedHref,\n {\n ...routeInfo,\n segments: segmentsWithoutGroups,\n },\n { relativeToDirectory: true }\n );\n\n let state = linking.getStateFromPath?.(resolvedHref, linking.config)?.routes[0];\n\n if (!state) {\n // This shouldn't occur, as you should get the global +not-found\n console.warn(\n `Unable to find screen for trigger ${JSON.stringify(trigger)}. Does this point to a valid screen?`\n );\n continue;\n }\n\n let routeState = state;\n\n const targetStateName = layoutRouteNode.route || '__root';\n\n // The state object is the current state from the rootNavigator\n // We need to work out the state for just this trigger\n while (state?.state) {\n if (state.name === targetStateName) break;\n state = state.state.routes[state.state.index ?? state.state.routes.length - 1];\n }\n routeState = state.state?.routes[state.state.index ?? state.state.routes.length - 1] || state;\n\n const routeNode = layoutRouteNode.children.find((child) => child.route === routeState?.name);\n\n if (!routeNode) {\n console.warn(\n `Unable to find routeNode for trigger ${JSON.stringify(trigger)}. This might be a bug with Expo Router`\n );\n continue;\n }\n\n if (routeNode.generated && routeNode.internal && routeNode.route.includes('+not-found')) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n `Tab trigger '${trigger.name}' has the href '${trigger.href}' which points to a +not-found route.`\n );\n }\n continue;\n }\n\n const duplicateTrigger =\n trigger.type === 'internal' &&\n configs.find((config): config is Extract<TriggerConfig, { type: 'internal' }> => {\n if (config.type === 'external') {\n return false;\n }\n\n return config.routeNode.route === routeNode.route;\n });\n\n if (duplicateTrigger) {\n const duplicateTriggerText = `${JSON.stringify({ name: duplicateTrigger.name, href: duplicateTrigger.href })} and ${JSON.stringify({ name: trigger.name, href: trigger.href })}`;\n\n throw new Error(\n `A navigator cannot contain multiple trigger components that map to the same sub-segment. Consider adding a shared group and assigning a group to each trigger. Conflicting triggers:\\n\\t${duplicateTriggerText}.\\nBoth triggers map to route ${routeNode.route}.`\n );\n }\n\n configs.push({\n ...trigger,\n href: resolvedHref,\n routeNode,\n action: stateToAction(state, layoutRouteNode.route),\n });\n }\n\n const sortFn = sortRoutesWithInitial(initialRouteName);\n\n const sortedConfigs = configs.sort((a, b) => {\n // External routes should be last. They will eventually be dropped\n if (a.type === 'external' && b.type === 'external') {\n return 0;\n } else if (a.type === 'external') {\n return 1;\n } else if (b.type === 'external') {\n return -1;\n }\n\n return sortFn(a.routeNode, b.routeNode);\n });\n\n const children: React.JSX.Element[] = [];\n const triggerMap: TriggerMap = { ...parentTriggerMap };\n\n for (const [index, config] of sortedConfigs.entries()) {\n triggerMap[config.name] = { ...config, index };\n\n if (config.type === 'internal') {\n children.push(routeToScreen(config.routeNode));\n }\n }\n return {\n children,\n triggerMap,\n };\n}\n\nexport function stateToAction(\n state: PartialRoute<Route<string, object | undefined>> | undefined,\n startAtRoute?: string\n): JumpToNavigationAction {\n const rootPayload: any = {};\n let payload = rootPayload;\n\n startAtRoute = startAtRoute === '' ? '__root' : startAtRoute;\n\n let foundStartingPoint = startAtRoute === undefined || !state?.state;\n\n while (state) {\n if (foundStartingPoint) {\n if (payload === rootPayload) {\n payload.name = state.name;\n } else {\n payload.screen = state.name;\n }\n payload.params = state.params ? { ...state.params } : {};\n\n state = state.state?.routes[state.state?.routes.length - 1];\n\n if (state) {\n payload.params ??= {};\n payload = payload.params;\n }\n } else {\n if (state.name === startAtRoute) {\n foundStartingPoint = true;\n }\n const nextState = state.state?.routes[state.state?.routes.length - 1];\n if (nextState) {\n state = nextState;\n }\n }\n }\n\n return {\n type: 'JUMP_TO',\n payload: rootPayload,\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNavigation.d.ts","sourceRoot":"","sources":["../src/useNavigation.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,cAAc,EACd,eAAe,
|
|
1
|
+
{"version":3,"file":"useNavigation.d.ts","sourceRoot":"","sources":["../src/useNavigation.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,cAAc,EACd,eAAe,EAEhB,MAAM,0BAA0B,CAAC;AAIlC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wBAAgB,aAAa,CAC3B,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,aAAa,CAAC,EAAE,UAAU,CAAC,GAAG;IACpE,QAAQ,IAAI,eAAe,GAAG,SAAS,CAAC;CACzC,EACD,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,CAAC,CA6E3B"}
|
package/build/useNavigation.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
'use client';
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
4
|
exports.useNavigation = useNavigation;
|
|
8
5
|
const native_1 = require("@react-navigation/native");
|
|
9
|
-
const
|
|
10
|
-
const router_store_1 = require("./global-state/router-store");
|
|
11
|
-
const hooks_1 = require("./hooks");
|
|
6
|
+
const constants_1 = require("./constants");
|
|
12
7
|
const href_1 = require("./link/href");
|
|
13
8
|
/**
|
|
14
9
|
* Returns the underlying React Navigation [`navigation` object](https://reactnavigation.org/docs/navigation-object)
|
|
@@ -64,64 +59,60 @@ const href_1 = require("./link/href");
|
|
|
64
59
|
*/
|
|
65
60
|
function useNavigation(parent) {
|
|
66
61
|
let navigation = (0, native_1.useNavigation)();
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
let contextKey = '';
|
|
62
|
+
let state = (0, native_1.useStateForPath)();
|
|
63
|
+
// Check for the top-level navigator - we cannot fetch anything higher!
|
|
64
|
+
const currentId = navigation.getId();
|
|
65
|
+
if (currentId === '' || currentId === `/expo-router/build/views/Navigator`) {
|
|
66
|
+
return navigation;
|
|
67
|
+
}
|
|
68
|
+
if (typeof parent === 'object') {
|
|
69
|
+
parent = (0, href_1.resolveHref)(parent);
|
|
70
|
+
}
|
|
71
|
+
if (parent === '/') {
|
|
72
|
+
// This is the root navigator
|
|
73
|
+
return navigation.getParent(`/expo-router/build/views/Navigator`) ?? navigation.getParent(``);
|
|
74
|
+
}
|
|
75
|
+
else if (parent?.startsWith('../')) {
|
|
82
76
|
const names = [];
|
|
83
77
|
while (state) {
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
78
|
+
const route = state.routes[0];
|
|
79
|
+
state = route.state;
|
|
80
|
+
// Don't include the last router, as thats the current route
|
|
81
|
+
if (state) {
|
|
88
82
|
names.push(route.name);
|
|
89
|
-
if (parent === contextKey) {
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
state = route.state;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
break;
|
|
96
83
|
}
|
|
97
84
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
85
|
+
// Removing the trailing slash to make splitting easier
|
|
86
|
+
const originalParent = parent;
|
|
87
|
+
if (parent.endsWith('/')) {
|
|
88
|
+
parent = parent.slice(0, -1);
|
|
89
|
+
}
|
|
90
|
+
const segments = parent.split('/');
|
|
91
|
+
if (!segments.every((segment) => segment === '..')) {
|
|
92
|
+
throw new Error(`Invalid parent path "${originalParent}". Only "../" segments are allowed when using relative paths.`);
|
|
93
|
+
}
|
|
94
|
+
const levels = segments.length;
|
|
95
|
+
const index = names.length - 1 - levels;
|
|
96
|
+
if (index < 0) {
|
|
97
|
+
throw new Error(`Invalid parent path "${originalParent}". Cannot go up ${levels} levels from the current route.`);
|
|
98
|
+
}
|
|
99
|
+
parent = names[index];
|
|
100
|
+
// Expo Router navigators use the context key as the name which has a leading `/`
|
|
101
|
+
// The exception to this is the INTERNAL_SLOT_NAME, and the root navigator which uses ''
|
|
102
|
+
if (parent && parent !== constants_1.INTERNAL_SLOT_NAME) {
|
|
103
|
+
parent = `/${parent}`;
|
|
109
104
|
}
|
|
110
|
-
return contextKey;
|
|
111
|
-
}, [segments, parent]);
|
|
112
|
-
// Remove the root Slot to generate the correct context key
|
|
113
|
-
targetNavigatorContextKey = targetNavigatorContextKey?.replace('/__root', '');
|
|
114
|
-
if (targetNavigatorContextKey !== undefined) {
|
|
115
|
-
navigation = navigation.getParent(targetNavigatorContextKey);
|
|
116
105
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
navigation
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
106
|
+
navigation = navigation.getParent(parent);
|
|
107
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
108
|
+
if (!navigation) {
|
|
109
|
+
const ids = [];
|
|
110
|
+
while (navigation) {
|
|
111
|
+
ids.push(navigation.getId() || '/');
|
|
112
|
+
navigation = navigation.getParent();
|
|
113
|
+
}
|
|
114
|
+
throw new Error(`Could not find parent navigation with route "${parent}". Available routes are: '${ids.join("', '")}'`);
|
|
123
115
|
}
|
|
124
|
-
throw new Error(`Could not find parent navigation with route "${parent}". Available routes are: '${ids.join("', '")}'`);
|
|
125
116
|
}
|
|
126
117
|
return navigation;
|
|
127
118
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNavigation.js","sourceRoot":"","sources":["../src/useNavigation.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC
|
|
1
|
+
{"version":3,"file":"useNavigation.js","sourceRoot":"","sources":["../src/useNavigation.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AAgEb,sCAiFC;AAhJD,qDAKkC;AAElC,2CAAiD;AACjD,sCAA0C;AAG1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,SAAgB,aAAa,CAI3B,MAAsB;IACtB,IAAI,UAAU,GAAG,IAAA,sBAAqB,GAAO,CAAC;IAC9C,IAAI,KAAK,GAAG,IAAA,wBAAe,GAAE,CAAC;IAE9B,uEAAuE;IACvE,MAAM,SAAS,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC;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,QAAQ,CAAC,MAAM,CAAC;QAC/B,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC;QAExC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CACb,wBAAwB,cAAc,mBAAmB,MAAM,iCAAiC,CACjG,CAAC;QACJ,CAAC;QAED,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QAEtB,iFAAiF;QACjF,wFAAwF;QACxF,IAAI,MAAM,IAAI,MAAM,KAAK,8BAAkB,EAAE,CAAC;YAC5C,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QACxB,CAAC;IACH,CAAC;IAED,UAAU,GAAG,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAE1C,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;QAC1C,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,GAAG,GAA2B,EAAE,CAAC;YACvC,OAAO,UAAU,EAAE,CAAC;gBAClB,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC;gBACpC,UAAU,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC;YACtC,CAAC;YAED,MAAM,IAAI,KAAK,CACb,gDAAgD,MAAM,6BAA6B,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CACvG,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["'use client';\nimport {\n useNavigation as useUpstreamNavigation,\n NavigationProp,\n NavigationState,\n useStateForPath,\n} from '@react-navigation/native';\n\nimport { INTERNAL_SLOT_NAME } from './constants';\nimport { resolveHref } from './link/href';\nimport { Href } from './types';\n\n/**\n * Returns the underlying React Navigation [`navigation` object](https://reactnavigation.org/docs/navigation-object)\n * to imperatively access layout-specific functionality like `navigation.openDrawer()` in a\n * [Drawer](/router/advanced/drawer/) layout.\n *\n * @example\n * ```tsx app/index.tsx\n * import { useNavigation } from 'expo-router';\n *\n * export default function Route() {\n * // Access the current navigation object for the current route.\n * const navigation = useNavigation();\n *\n * return (\n * <View>\n * <Text onPress={() => {\n * // Open the drawer view.\n * navigation.openDrawer();\n * }}>\n * Open Drawer\n * </Text>\n * </View>\n * );\n * }\n * ```\n *\n * When using nested layouts, you can access higher-order layouts by passing a secondary argument denoting the layout route.\n * For example, `/menu/_layout.tsx` is nested inside `/app/orders/`, you can use `useNavigation('/orders/menu/')`.\n *\n * @example\n * ```tsx app/orders/menu/index.tsx\n * import { useNavigation } from 'expo-router';\n *\n * export default function MenuRoute() {\n * const rootLayout = useNavigation('/');\n * const ordersLayout = useNavigation('/orders');\n *\n * // Same as the default results of `useNavigation()` when invoked in this route.\n * const parentLayout = useNavigation('/orders/menu');\n * }\n * ```\n *\n * If you attempt to access a layout that doesn't exist, an error such as\n * `Could not find parent navigation with route \"/non-existent\"` is thrown.\n *\n *\n * @param parent Provide an absolute path such as `/(root)` to the parent route or a relative path like `../../` to the parent route.\n * @returns The navigation object for the current route.\n *\n * @see React Navigation documentation on [navigation dependent functions](https://reactnavigation.org/docs/navigation-object/#navigator-dependent-functions)\n * for more information.\n */\nexport function useNavigation<\n T = Omit<NavigationProp<ReactNavigation.RootParamList>, 'getState'> & {\n getState(): NavigationState | undefined;\n },\n>(parent?: string | Href): T {\n let navigation = useUpstreamNavigation<any>();\n let state = useStateForPath();\n\n // Check for the top-level navigator - we cannot fetch anything higher!\n const currentId = navigation.getId();\n if (currentId === '' || currentId === `/expo-router/build/views/Navigator`) {\n return navigation;\n }\n\n if (typeof parent === 'object') {\n parent = resolveHref(parent);\n }\n\n if (parent === '/') {\n // This is the root navigator\n return navigation.getParent(`/expo-router/build/views/Navigator`) ?? navigation.getParent(``);\n } else if (parent?.startsWith('../')) {\n const names: string[] = [];\n\n while (state) {\n const route = state.routes[0];\n state = route.state;\n // Don't include the last router, as thats the current route\n if (state) {\n names.push(route.name);\n }\n }\n\n // Removing the trailing slash to make splitting easier\n const originalParent = parent;\n if (parent.endsWith('/')) {\n parent = parent.slice(0, -1);\n }\n\n const segments = parent.split('/');\n if (!segments.every((segment) => segment === '..')) {\n throw new Error(\n `Invalid parent path \"${originalParent}\". Only \"../\" segments are allowed when using relative paths.`\n );\n }\n\n const levels = segments.length;\n const index = names.length - 1 - levels;\n\n if (index < 0) {\n throw new Error(\n `Invalid parent path \"${originalParent}\". Cannot go up ${levels} levels from the current route.`\n );\n }\n\n parent = names[index];\n\n // Expo Router navigators use the context key as the name which has a leading `/`\n // The exception to this is the INTERNAL_SLOT_NAME, and the root navigator which uses ''\n if (parent && parent !== INTERNAL_SLOT_NAME) {\n parent = `/${parent}`;\n }\n }\n\n navigation = navigation.getParent(parent);\n\n if (process.env.NODE_ENV !== 'production') {\n if (!navigation) {\n const ids: (string | undefined)[] = [];\n while (navigation) {\n ids.push(navigation.getId() || '/');\n navigation = navigation.getParent();\n }\n\n throw new Error(\n `Could not find parent navigation with route \"${parent}\". Available routes are: '${ids.join(\"', '\")}'`\n );\n }\n }\n\n return navigation;\n}\n"]}
|
package/build/useScreens.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type EventMapBase, type NavigationState, type ParamListBase, type RouteProp, type ScreenListeners } from '@react-navigation/native';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { RouteNode } from './Route';
|
|
4
4
|
import { UnknownOutputParams } from './types';
|
|
@@ -28,7 +28,7 @@ export type SingularOptions = boolean | ((name: string, params: UnknownOutputPar
|
|
|
28
28
|
/**
|
|
29
29
|
* @returns React Navigation screens sorted by the `route` property.
|
|
30
30
|
*/
|
|
31
|
-
export declare function useSortedScreens(order: ScreenProps[]): React.ReactNode[];
|
|
31
|
+
export declare function useSortedScreens(order: ScreenProps[], protectedScreens: Set<string>): React.ReactNode[];
|
|
32
32
|
/** Wrap the component with various enhancements and add access to child routes. */
|
|
33
33
|
export declare function getQualifiedRouteComponent(value: RouteNode): React.ComponentType<any> | {
|
|
34
34
|
({ route, navigation, ...props }: any): React.JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useScreens.d.ts","sourceRoot":"","sources":["../src/useScreens.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"useScreens.d.ts","sourceRoot":"","sources":["../src/useScreens.tsx"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,eAAe,EACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAsB,SAAS,EAAuC,MAAM,SAAS,CAAC;AAI7F,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAK9C,MAAM,MAAM,WAAW,CACrB,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC1D,MAAM,SAAS,eAAe,GAAG,eAAe,EAChD,SAAS,SAAS,YAAY,GAAG,YAAY,IAC3C;IACF,4DAA4D;IAC5D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACpC,OAAO,CAAC,EACJ,QAAQ,GACR,CAAC,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,SAAS,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;QAAC,UAAU,EAAE,GAAG,CAAA;KAAE,KAAK,QAAQ,CAAC,CAAC;IAEvF,SAAS,CAAC,EACN,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,GAClC,CAAC,CAAC,IAAI,EAAE;QACN,KAAK,EAAE,SAA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ports.screenOptionsFactory = screenOptionsFactory;
|
|
10
10
|
exports.routeToScreen = routeToScreen;
|
|
11
11
|
exports.getSingularId = getSingularId;
|
|
12
|
+
const native_1 = require("@react-navigation/native");
|
|
12
13
|
const react_1 = __importDefault(require("react"));
|
|
13
14
|
const Route_1 = require("./Route");
|
|
15
|
+
const storeContext_1 = require("./global-state/storeContext");
|
|
14
16
|
const import_mode_1 = __importDefault(require("./import-mode"));
|
|
15
17
|
const primitives_1 = require("./primitives");
|
|
16
18
|
const EmptyRoute_1 = require("./views/EmptyRoute");
|
|
17
19
|
const SuspenseFallback_1 = require("./views/SuspenseFallback");
|
|
18
20
|
const Try_1 = require("./views/Try");
|
|
19
|
-
function getSortedChildren(children, order, initialRouteName) {
|
|
21
|
+
function getSortedChildren(children, order = [], initialRouteName) {
|
|
20
22
|
if (!order?.length) {
|
|
21
23
|
return children
|
|
22
24
|
.sort((0, Route_1.sortRoutesWithInitial)(initialRouteName))
|
|
@@ -77,12 +79,16 @@ function getSortedChildren(children, order, initialRouteName) {
|
|
|
77
79
|
/**
|
|
78
80
|
* @returns React Navigation screens sorted by the `route` property.
|
|
79
81
|
*/
|
|
80
|
-
function useSortedScreens(order) {
|
|
82
|
+
function useSortedScreens(order, protectedScreens) {
|
|
81
83
|
const node = (0, Route_1.useRouteNode)();
|
|
82
84
|
const sorted = node?.children?.length
|
|
83
85
|
? getSortedChildren(node.children, order, node.initialRouteName)
|
|
84
86
|
: [];
|
|
85
|
-
return react_1.default.useMemo(() => sorted
|
|
87
|
+
return react_1.default.useMemo(() => sorted
|
|
88
|
+
.filter((item) => !protectedScreens.has(item.route.route))
|
|
89
|
+
.map((value) => {
|
|
90
|
+
return routeToScreen(value.route, value.props);
|
|
91
|
+
}), [sorted, protectedScreens]);
|
|
86
92
|
}
|
|
87
93
|
function fromImport(value, { ErrorBoundary, ...component }) {
|
|
88
94
|
// If possible, add a more helpful display name for the component stack to improve debugging of React errors such as `Text strings must be rendered within a <Text> component.`.
|
|
@@ -148,6 +154,15 @@ function getQualifiedRouteComponent(value) {
|
|
|
148
154
|
route, navigation,
|
|
149
155
|
// Pass all other props to the component
|
|
150
156
|
...props }) {
|
|
157
|
+
const stateForPath = (0, native_1.useStateForPath)();
|
|
158
|
+
const isFocused = (0, native_1.useIsFocused)();
|
|
159
|
+
const store = (0, storeContext_1.useExpoRouterStore)();
|
|
160
|
+
if (isFocused) {
|
|
161
|
+
const state = navigation.getState();
|
|
162
|
+
const isLeaf = !('state' in state.routes[state.index]);
|
|
163
|
+
if (isLeaf && stateForPath)
|
|
164
|
+
store.setFocusedState(stateForPath);
|
|
165
|
+
}
|
|
151
166
|
return (<Route_1.Route node={value} route={route}>
|
|
152
167
|
<react_1.default.Suspense fallback={<SuspenseFallback_1.SuspenseFallback route={value}/>}>
|
|
153
168
|
<ScreenComponent {...props}
|
package/build/useScreens.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useScreens.js","sourceRoot":"","sources":["../src/useScreens.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;AAgJb,4CAUC;AAmDD,gEAsDC;AAED,oDAwBC;AAED,sCAcC;AAED,sCAgBC;AAtTD,kDAA0B;AAE1B,mCAA6F;AAC7F,gEAAoD;AACpD,6CAAsC;AAEtC,mDAAgD;AAChD,+DAA4D;AAC5D,qCAAkC;AAmClC,SAAS,iBAAiB,CACxB,QAAqB,EACrB,KAAqB,EACrB,gBAAyB;IAEzB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;QACnB,OAAO,QAAQ;aACZ,IAAI,CAAC,IAAA,6BAAqB,EAAC,gBAAgB,CAAC,CAAC;aAC7C,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IAC5C,CAAC;IACD,MAAM,OAAO,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC;IAE9B,MAAM,OAAO,GA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AG,CAAC,IAAI,OAAO,CAAC;QACtE,CAAC;aAAM,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACnC,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC;QAC3D,CAAC;aAAM,CAAC;YACN,OAAO,OAAO,CAAC;QACjB,CAAC;IACH,CAAC,CAAC;SACD,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC","sourcesContent":["'use client';\n\nimport type {\n EventMapBase,\n NavigationState,\n ParamListBase,\n RouteProp,\n ScreenListeners,\n} from '@react-navigation/native';\nimport React from 'react';\n\nimport { LoadedRoute, Route, RouteNode, sortRoutesWithInitial, useRouteNode } from './Route';\nimport EXPO_ROUTER_IMPORT_MODE from './import-mode';\nimport { Screen } from './primitives';\nimport { UnknownOutputParams } from './types';\nimport { EmptyRoute } from './views/EmptyRoute';\nimport { SuspenseFallback } from './views/SuspenseFallback';\nimport { Try } from './views/Try';\n\nexport type ScreenProps<\n TOptions extends Record<string, any> = Record<string, any>,\n TState extends NavigationState = NavigationState,\n TEventMap extends EventMapBase = EventMapBase,\n> = {\n /** Name is required when used inside a Layout component. */\n name?: string;\n /**\n * Redirect to the nearest sibling route.\n * If all children are `redirect={true}`, the layout will render `null` as there are no children to render.\n */\n redirect?: boolean;\n initialParams?: Record<string, any>;\n options?:\n | TOptions\n | ((prop: { route: RouteProp<ParamListBase, string>; navigation: any }) => TOptions);\n\n listeners?:\n | ScreenListeners<TState, TEventMap>\n | ((prop: {\n route: RouteProp<ParamListBase, string>;\n navigation: any;\n }) => ScreenListeners<TState, TEventMap>);\n\n getId?: ({ params }: { params?: Record<string, any> }) => string | undefined;\n\n dangerouslySingular?: SingularOptions;\n};\n\nexport type SingularOptions =\n | boolean\n | ((name: string, params: UnknownOutputParams) => string | undefined);\n\nfunction getSortedChildren(\n children: RouteNode[],\n order?: ScreenProps[],\n initialRouteName?: string\n): { route: RouteNode; props: Partial<ScreenProps> }[] {\n if (!order?.length) {\n return children\n .sort(sortRoutesWithInitial(initialRouteName))\n .map((route) => ({ route, props: {} }));\n }\n const entries = [...children];\n\n const ordered = order\n .map(\n ({\n name,\n redirect,\n initialParams,\n listeners,\n options,\n getId,\n dangerouslySingular: singular,\n }) => {\n if (!entries.length) {\n console.warn(\n `[Layout children]: Too many screens defined. Route \"${name}\" is extraneous.`\n );\n return null;\n }\n const matchIndex = entries.findIndex((child) => child.route === name);\n if (matchIndex === -1) {\n console.warn(\n `[Layout children]: No route named \"${name}\" exists in nested children:`,\n children.map(({ route }) => route)\n );\n return null;\n } else {\n // Get match and remove from entries\n const match = entries[matchIndex];\n entries.splice(matchIndex, 1);\n\n // Ensure to return null after removing from entries.\n if (redirect) {\n if (typeof redirect === 'string') {\n throw new Error(`Redirecting to a specific route is not supported yet.`);\n }\n return null;\n }\n\n if (getId) {\n console.warn(\n `Deprecated: prop 'getId' on screen ${name} is deprecated. Please rename the prop to 'dangerouslySingular'`\n );\n if (singular) {\n console.warn(\n `Screen ${name} cannot use both getId and dangerouslySingular together.`\n );\n }\n } else if (singular) {\n // If singular is set, use it as the getId function.\n if (typeof singular === 'string') {\n getId = () => singular;\n } else if (typeof singular === 'function' && name) {\n getId = (options) => singular(name, options.params || {});\n } else if (singular === true && name) {\n getId = (options) => getSingularId(name, options);\n }\n }\n\n return {\n route: match,\n props: { initialParams, listeners, options, getId },\n };\n }\n }\n )\n .filter(Boolean) as {\n route: RouteNode;\n props: Partial<ScreenProps>;\n }[];\n\n // Add any remaining children\n ordered.push(\n ...entries.sort(sortRoutesWithInitial(initialRouteName)).map((route) => ({ route, props: {} }))\n );\n\n return ordered;\n}\n\n/**\n * @returns React Navigation screens sorted by the `route` property.\n */\nexport function useSortedScreens(order: ScreenProps[]): React.ReactNode[] {\n const node = useRouteNode();\n\n const sorted = node?.children?.length\n ? getSortedChildren(node.children, order, node.initialRouteName)\n : [];\n return React.useMemo(\n () => sorted.map((value) => routeToScreen(value.route, value.props)),\n [sorted]\n );\n}\n\nfunction fromImport(value: RouteNode, { ErrorBoundary, ...component }: LoadedRoute) {\n // If possible, add a more helpful display name for the component stack to improve debugging of React errors such as `Text strings must be rendered within a <Text> component.`.\n if (component?.default && __DEV__) {\n component.default.displayName ??= `${component.default.name ?? 'Route'}(${value.contextKey})`;\n }\n\n if (ErrorBoundary) {\n const Wrapped = React.forwardRef((props: any, ref: any) => {\n const children = React.createElement(component.default || EmptyRoute, {\n ...props,\n ref,\n });\n return <Try catch={ErrorBoundary}>{children}</Try>;\n });\n\n if (__DEV__) {\n Wrapped.displayName = `ErrorBoundary(${value.contextKey})`;\n }\n\n return {\n default: Wrapped,\n };\n }\n if (process.env.NODE_ENV !== 'production') {\n if (\n typeof component.default === 'object' &&\n component.default &&\n Object.keys(component.default).length === 0\n ) {\n return { default: EmptyRoute };\n }\n }\n\n return { default: component.default };\n}\n\nfunction fromLoadedRoute(value: RouteNode, res: LoadedRoute) {\n if (!(res instanceof Promise)) {\n return fromImport(value, res);\n }\n\n return res.then(fromImport.bind(null, value));\n}\n\n// TODO: Maybe there's a more React-y way to do this?\n// Without this store, the process enters a recursive loop.\nconst qualifiedStore = new WeakMap<RouteNode, React.ComponentType<any>>();\n\n/** Wrap the component with various enhancements and add access to child routes. */\nexport function getQualifiedRouteComponent(value: RouteNode) {\n if (qualifiedStore.has(value)) {\n return qualifiedStore.get(value)!;\n }\n\n let ScreenComponent:\n | React.ForwardRefExoticComponent<React.RefAttributes<unknown>>\n | React.ComponentType<any>;\n\n // TODO: This ensures sync doesn't use React.lazy, but it's not ideal.\n if (EXPO_ROUTER_IMPORT_MODE === 'lazy') {\n ScreenComponent = React.lazy(async () => {\n const res = value.loadRoute();\n return fromLoadedRoute(value, res) as Promise<{\n default: React.ComponentType<any>;\n }>;\n });\n\n if (__DEV__) {\n ScreenComponent.displayName = `AsyncRoute(${value.route})`;\n }\n } else {\n const res = value.loadRoute();\n ScreenComponent = fromImport(value, res).default!;\n }\n function BaseRoute({\n // Remove these React Navigation props to\n // enforce usage of expo-router hooks (where the query params are correct).\n route,\n navigation,\n\n // Pass all other props to the component\n ...props\n }: any) {\n return (\n <Route node={value} route={route}>\n <React.Suspense fallback={<SuspenseFallback route={value} />}>\n <ScreenComponent\n {...props}\n // Expose the template segment path, e.g. `(home)`, `[foo]`, `index`\n // the intention is to make it possible to deduce shared routes.\n segment={value.route}\n />\n </React.Suspense>\n </Route>\n );\n }\n\n if (__DEV__) {\n BaseRoute.displayName = `Route(${value.route})`;\n }\n\n qualifiedStore.set(value, BaseRoute);\n return BaseRoute;\n}\n\nexport function screenOptionsFactory(\n route: RouteNode,\n options?: ScreenProps['options']\n): ScreenProps['options'] {\n return (args) => {\n // Only eager load generated components\n const staticOptions = route.generated ? route.loadRoute()?.getNavOptions : null;\n const staticResult = typeof staticOptions === 'function' ? staticOptions(args) : staticOptions;\n const dynamicResult = typeof options === 'function' ? options?.(args) : options;\n const output = {\n ...staticResult,\n ...dynamicResult,\n };\n\n // Prevent generated screens from showing up in the tab bar.\n if (route.generated) {\n output.tabBarItemStyle = { display: 'none' };\n output.tabBarButton = () => null;\n // TODO: React Navigation doesn't provide a way to prevent rendering the drawer item.\n output.drawerItemStyle = { height: 0, display: 'none' };\n }\n\n return output;\n };\n}\n\nexport function routeToScreen(\n route: RouteNode,\n { options, getId, ...props }: Partial<ScreenProps> = {}\n) {\n return (\n <Screen\n {...props}\n name={route.route}\n key={route.route}\n getId={getId}\n options={screenOptionsFactory(route, options)}\n getComponent={() => getQualifiedRouteComponent(route)}\n />\n );\n}\n\nexport function getSingularId(\n name: string,\n options: { params?: Record<string, any> | undefined } = {}\n) {\n return name\n .split('/')\n .map((segment) => {\n if (segment.startsWith('[...')) {\n return options.params?.[segment.slice(4, -1)]?.join('/') || segment;\n } else if (segment.startsWith('[')) {\n return options.params?.[segment.slice(1, -1)] || segment;\n } else {\n return segment;\n }\n })\n .join('/');\n}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AE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC;QACtE,CAAC;aAAM,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACnC,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC;QAC3D,CAAC;aAAM,CAAC;YACN,OAAO,OAAO,CAAC;QACjB,CAAC;IACH,CAAC,CAAC;SACD,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC","sourcesContent":["'use client';\n\nimport {\n useIsFocused,\n useStateForPath,\n type EventMapBase,\n type NavigationState,\n type ParamListBase,\n type RouteProp,\n type ScreenListeners,\n} from '@react-navigation/native';\nimport React from 'react';\n\nimport { LoadedRoute, Route, RouteNode, sortRoutesWithInitial, useRouteNode } from './Route';\nimport { useExpoRouterStore } from './global-state/storeContext';\nimport EXPO_ROUTER_IMPORT_MODE from './import-mode';\nimport { Screen } from './primitives';\nimport { UnknownOutputParams } from './types';\nimport { EmptyRoute } from './views/EmptyRoute';\nimport { SuspenseFallback } from './views/SuspenseFallback';\nimport { Try } from './views/Try';\n\nexport type ScreenProps<\n TOptions extends Record<string, any> = Record<string, any>,\n TState extends NavigationState = NavigationState,\n TEventMap extends EventMapBase = EventMapBase,\n> = {\n /** Name is required when used inside a Layout component. */\n name?: string;\n /**\n * Redirect to the nearest sibling route.\n * If all children are `redirect={true}`, the layout will render `null` as there are no children to render.\n */\n redirect?: boolean;\n initialParams?: Record<string, any>;\n options?:\n | TOptions\n | ((prop: { route: RouteProp<ParamListBase, string>; navigation: any }) => TOptions);\n\n listeners?:\n | ScreenListeners<TState, TEventMap>\n | ((prop: {\n route: RouteProp<ParamListBase, string>;\n navigation: any;\n }) => ScreenListeners<TState, TEventMap>);\n\n getId?: ({ params }: { params?: Record<string, any> }) => string | undefined;\n\n dangerouslySingular?: SingularOptions;\n};\n\nexport type SingularOptions =\n | boolean\n | ((name: string, params: UnknownOutputParams) => string | undefined);\n\nfunction getSortedChildren(\n children: RouteNode[],\n order: ScreenProps[] = [],\n initialRouteName?: string\n): { route: RouteNode; props: Partial<ScreenProps> }[] {\n if (!order?.length) {\n return children\n .sort(sortRoutesWithInitial(initialRouteName))\n .map((route) => ({ route, props: {} }));\n }\n const entries = [...children];\n\n const ordered = order\n .map(\n ({\n name,\n redirect,\n initialParams,\n listeners,\n options,\n getId,\n dangerouslySingular: singular,\n }) => {\n if (!entries.length) {\n console.warn(\n `[Layout children]: Too many screens defined. Route \"${name}\" is extraneous.`\n );\n return null;\n }\n const matchIndex = entries.findIndex((child) => child.route === name);\n if (matchIndex === -1) {\n console.warn(\n `[Layout children]: No route named \"${name}\" exists in nested children:`,\n children.map(({ route }) => route)\n );\n return null;\n } else {\n // Get match and remove from entries\n const match = entries[matchIndex];\n entries.splice(matchIndex, 1);\n\n // Ensure to return null after removing from entries.\n if (redirect) {\n if (typeof redirect === 'string') {\n throw new Error(`Redirecting to a specific route is not supported yet.`);\n }\n return null;\n }\n\n if (getId) {\n console.warn(\n `Deprecated: prop 'getId' on screen ${name} is deprecated. Please rename the prop to 'dangerouslySingular'`\n );\n if (singular) {\n console.warn(\n `Screen ${name} cannot use both getId and dangerouslySingular together.`\n );\n }\n } else if (singular) {\n // If singular is set, use it as the getId function.\n if (typeof singular === 'string') {\n getId = () => singular;\n } else if (typeof singular === 'function' && name) {\n getId = (options) => singular(name, options.params || {});\n } else if (singular === true && name) {\n getId = (options) => getSingularId(name, options);\n }\n }\n\n return {\n route: match,\n props: { initialParams, listeners, options, getId },\n };\n }\n }\n )\n .filter(Boolean) as {\n route: RouteNode;\n props: Partial<ScreenProps>;\n }[];\n\n // Add any remaining children\n ordered.push(\n ...entries.sort(sortRoutesWithInitial(initialRouteName)).map((route) => ({ route, props: {} }))\n );\n\n return ordered;\n}\n\n/**\n * @returns React Navigation screens sorted by the `route` property.\n */\nexport function useSortedScreens(\n order: ScreenProps[],\n protectedScreens: Set<string>\n): React.ReactNode[] {\n const node = useRouteNode();\n\n const sorted = node?.children?.length\n ? getSortedChildren(node.children, order, node.initialRouteName)\n : [];\n return React.useMemo(\n () =>\n sorted\n .filter((item) => !protectedScreens.has(item.route.route))\n .map((value) => {\n return routeToScreen(value.route, value.props);\n }),\n [sorted, protectedScreens]\n );\n}\n\nfunction fromImport(value: RouteNode, { ErrorBoundary, ...component }: LoadedRoute) {\n // If possible, add a more helpful display name for the component stack to improve debugging of React errors such as `Text strings must be rendered within a <Text> component.`.\n if (component?.default && __DEV__) {\n component.default.displayName ??= `${component.default.name ?? 'Route'}(${value.contextKey})`;\n }\n\n if (ErrorBoundary) {\n const Wrapped = React.forwardRef((props: any, ref: any) => {\n const children = React.createElement(component.default || EmptyRoute, {\n ...props,\n ref,\n });\n return <Try catch={ErrorBoundary}>{children}</Try>;\n });\n\n if (__DEV__) {\n Wrapped.displayName = `ErrorBoundary(${value.contextKey})`;\n }\n\n return {\n default: Wrapped,\n };\n }\n if (process.env.NODE_ENV !== 'production') {\n if (\n typeof component.default === 'object' &&\n component.default &&\n Object.keys(component.default).length === 0\n ) {\n return { default: EmptyRoute };\n }\n }\n\n return { default: component.default };\n}\n\nfunction fromLoadedRoute(value: RouteNode, res: LoadedRoute) {\n if (!(res instanceof Promise)) {\n return fromImport(value, res);\n }\n\n return res.then(fromImport.bind(null, value));\n}\n\n// TODO: Maybe there's a more React-y way to do this?\n// Without this store, the process enters a recursive loop.\nconst qualifiedStore = new WeakMap<RouteNode, React.ComponentType<any>>();\n\n/** Wrap the component with various enhancements and add access to child routes. */\nexport function getQualifiedRouteComponent(value: RouteNode) {\n if (qualifiedStore.has(value)) {\n return qualifiedStore.get(value)!;\n }\n\n let ScreenComponent:\n | React.ForwardRefExoticComponent<React.RefAttributes<unknown>>\n | React.ComponentType<any>;\n\n // TODO: This ensures sync doesn't use React.lazy, but it's not ideal.\n if (EXPO_ROUTER_IMPORT_MODE === 'lazy') {\n ScreenComponent = React.lazy(async () => {\n const res = value.loadRoute();\n return fromLoadedRoute(value, res) as Promise<{\n default: React.ComponentType<any>;\n }>;\n });\n\n if (__DEV__) {\n ScreenComponent.displayName = `AsyncRoute(${value.route})`;\n }\n } else {\n const res = value.loadRoute();\n ScreenComponent = fromImport(value, res).default!;\n }\n function BaseRoute({\n // Remove these React Navigation props to\n // enforce usage of expo-router hooks (where the query params are correct).\n route,\n navigation,\n\n // Pass all other props to the component\n ...props\n }: any) {\n const stateForPath = useStateForPath();\n const isFocused = useIsFocused();\n const store = useExpoRouterStore();\n\n if (isFocused) {\n const state = navigation.getState();\n const isLeaf = !('state' in state.routes[state.index]);\n if (isLeaf && stateForPath) store.setFocusedState(stateForPath);\n }\n\n return (\n <Route node={value} route={route}>\n <React.Suspense fallback={<SuspenseFallback route={value} />}>\n <ScreenComponent\n {...props}\n // Expose the template segment path, e.g. `(home)`, `[foo]`, `index`\n // the intention is to make it possible to deduce shared routes.\n segment={value.route}\n />\n </React.Suspense>\n </Route>\n );\n }\n\n if (__DEV__) {\n BaseRoute.displayName = `Route(${value.route})`;\n }\n\n qualifiedStore.set(value, BaseRoute);\n return BaseRoute;\n}\n\nexport function screenOptionsFactory(\n route: RouteNode,\n options?: ScreenProps['options']\n): ScreenProps['options'] {\n return (args) => {\n // Only eager load generated components\n const staticOptions = route.generated ? route.loadRoute()?.getNavOptions : null;\n const staticResult = typeof staticOptions === 'function' ? staticOptions(args) : staticOptions;\n const dynamicResult = typeof options === 'function' ? options?.(args) : options;\n const output = {\n ...staticResult,\n ...dynamicResult,\n };\n\n // Prevent generated screens from showing up in the tab bar.\n if (route.generated) {\n output.tabBarItemStyle = { display: 'none' };\n output.tabBarButton = () => null;\n // TODO: React Navigation doesn't provide a way to prevent rendering the drawer item.\n output.drawerItemStyle = { height: 0, display: 'none' };\n }\n\n return output;\n };\n}\n\nexport function routeToScreen(\n route: RouteNode,\n { options, getId, ...props }: Partial<ScreenProps> = {}\n) {\n return (\n <Screen\n {...props}\n name={route.route}\n key={route.route}\n getId={getId}\n options={screenOptionsFactory(route, options)}\n getComponent={() => getQualifiedRouteComponent(route)}\n />\n );\n}\n\nexport function getSingularId(\n name: string,\n options: { params?: Record<string, any> | undefined } = {}\n) {\n return name\n .split('/')\n .map((segment) => {\n if (segment.startsWith('[...')) {\n return options.params?.[segment.slice(4, -1)]?.join('/') || segment;\n } else if (segment.startsWith('[')) {\n return options.params?.[segment.slice(1, -1)] || segment;\n } else {\n return segment;\n }\n })\n .join('/');\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Navigator.d.ts","sourceRoot":"","sources":["../../src/views/Navigator.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAIrD,MAAM,MAAM,qBAAqB,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,GAAG;IAC5E,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;CACtC,CAAC;AAEF,eAAO,MAAM,gBAAgB,6CAA0D,CAAC;AAMxF,KAAK,0BAA0B,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7E,KAAK,2BAA2B,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;AAE9E,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,0BAA0B,IAAI;IACjE,gBAAgB,CAAC,EAAE,2BAA2B,CAAC,kBAAkB,CAAC,CAAC;IACnE,aAAa,CAAC,EAAE,2BAA2B,CAAC,eAAe,CAAC,CAAC;IAC7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2BAA2B,CAAC,UAAU,CAAC,CAAC;IACnD,MAAM,CAAC,EAAE,CAAC,CAAC;IACX,aAAa,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC;CAC5D,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,0BAA0B,GAAG,OAAO,WAAW,EAAE,EACnF,gBAAgB,EAChB,aAAa,EACb,QAAQ,EACR,MAAM,EACN,aAAa,GACd,EAAE,cAAc,CAAC,CAAC,CAAC,4BA0CnB;yBAhDe,SAAS;;;;;AAkDzB;;GAEG;AACH,wBAAgB,mBAAmB,0BAMlC;AAqBD;;;;;;;;;;GAUG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,qBAchE;AAED;;GAEG;AACH,iBAAS,aAAa,sBAMrB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,sBAM/B"}
|
package/build/views/Navigator.js
CHANGED
|
@@ -60,11 +60,11 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
60
60
|
function Navigator({ initialRouteName, screenOptions, children, router, routerOptions, }) {
|
|
61
61
|
const contextKey = (0, Route_1.useContextKey)();
|
|
62
62
|
// A custom navigator can have a mix of Screen and other components (like a Slot inside a View)
|
|
63
|
-
const { screens, children: nonScreenChildren } = (0, withLayoutContext_1.useFilterScreenChildren)(children, {
|
|
63
|
+
const { screens, children: nonScreenChildren, protectedScreens, } = (0, withLayoutContext_1.useFilterScreenChildren)(children, {
|
|
64
64
|
isCustomNavigator: true,
|
|
65
65
|
contextKey,
|
|
66
66
|
});
|
|
67
|
-
const sortedScreens = (0, useScreens_1.useSortedScreens)(screens ?? []);
|
|
67
|
+
const sortedScreens = (0, useScreens_1.useSortedScreens)(screens ?? [], protectedScreens);
|
|
68
68
|
router ||= StackClient_1.StackRouter;
|
|
69
69
|
const navigation = (0, native_1.useNavigationBuilder)(router, {
|
|
70
70
|
// Used for getting the parent with navigation.getParent('/normalized/path')
|
|
@@ -100,13 +100,13 @@ function useNavigatorContext() {
|
|
|
100
100
|
function SlotNavigator(props) {
|
|
101
101
|
const contextKey = (0, Route_1.useContextKey)();
|
|
102
102
|
// Allows adding Screen components as children to configure routes.
|
|
103
|
-
const { screens } = (0, withLayoutContext_1.useFilterScreenChildren)([], {
|
|
103
|
+
const { screens, protectedScreens } = (0, withLayoutContext_1.useFilterScreenChildren)([], {
|
|
104
104
|
contextKey,
|
|
105
105
|
});
|
|
106
106
|
const { state, descriptors, NavigationContent } = (0, native_1.useNavigationBuilder)(StackClient_1.StackRouter, {
|
|
107
107
|
...props,
|
|
108
108
|
id: contextKey,
|
|
109
|
-
children: (0, useScreens_1.useSortedScreens)(screens ?? []),
|
|
109
|
+
children: (0, useScreens_1.useSortedScreens)(screens ?? [], protectedScreens),
|
|
110
110
|
});
|
|
111
111
|
return (<NavigationContent>{descriptors[state.routes[state.index].key].render()}</NavigationContent>);
|
|
112
112
|
}
|