expo-router 0.0.28 → 0.0.29
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/Route.d.ts.map +1 -1
- package/build/Route.js +8 -5
- package/build/Route.js.map +1 -1
- package/build/exports.d.ts +1 -0
- package/build/exports.d.ts.map +1 -1
- package/build/exports.js +1 -0
- package/build/exports.js.map +1 -1
- package/build/layouts/withLayoutContext.d.ts.map +1 -1
- package/build/layouts/withLayoutContext.js +3 -1
- package/build/layouts/withLayoutContext.js.map +1 -1
- package/build/useNavigation.d.ts +9 -0
- package/build/useNavigation.d.ts.map +1 -0
- package/build/useNavigation.js +66 -0
- package/build/useNavigation.js.map +1 -0
- package/build/views/Layout.d.ts.map +1 -1
- package/build/views/Layout.js +2 -0
- package/build/views/Layout.js.map +1 -1
- package/build/views/Screen.d.ts +16 -5
- package/build/views/Screen.d.ts.map +1 -1
- package/build/views/Screen.js +2 -6
- package/build/views/Screen.js.map +1 -1
- package/package.json +1 -1
package/build/Route.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Route.d.ts","sourceRoot":"","sources":["../src/Route.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAc,MAAM,OAAO,CAAC;AAKrD,yFAAyF;AACzF,oBAAY,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GACxD,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAEtB,oBAAY,SAAS,GAAG;IACtB,oBAAoB;IACpB,QAAQ,EAAE,SAAS,EAAE,CAAC;IACtB,qCAAqC;IACrC,YAAY,EAAE,MAAM,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAC7C,kCAAkC;IAClC,OAAO,EAAE,IAAI,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;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AG,CAAC,CAAC;IACrC,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,UAAU,EAAE,MAAM,CAAC;IACnB,sBAAsB;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,wFAAwF;IACxF,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAWF,sDAAsD;AACtD,wBAAgB,SAAS,IAAI,SAAS,EAAE,CAEvC;AAED,wBAAgB,aAAa,IAAI,MAAM,CAMtC;AAED,iEAAiE;AACjE,wBAAgB,KAAK,CAAC,EACpB,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,SAAS,CAAC;CACrB,eAqBA;AA8BD,wBAAgB,UAAU,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,GAAG,MAAM,CA4B7D"}
|
package/build/Route.js
CHANGED
|
@@ -13,19 +13,22 @@ export function useRoutes() {
|
|
|
13
13
|
}
|
|
14
14
|
export function useContextKey() {
|
|
15
15
|
const filename = useContext(CurrentRoutePathContext);
|
|
16
|
-
if (
|
|
16
|
+
if (filename == null) {
|
|
17
17
|
throw new Error("No filename found. This is likely a bug in expo-router.");
|
|
18
18
|
}
|
|
19
19
|
return filename;
|
|
20
20
|
}
|
|
21
21
|
/** Provides the matching routes and filename to the children. */
|
|
22
22
|
export function Route({ filename, children, }) {
|
|
23
|
-
const
|
|
24
|
-
|
|
23
|
+
const normalName = React.useMemo(() => getNameFromFilePath(filename), [filename]);
|
|
24
|
+
const routes = useRoutesAtPath(normalName);
|
|
25
|
+
return (React.createElement(CurrentRoutePathContext.Provider, { value:
|
|
26
|
+
// The root path is `` (empty string) so always prepend `/` to ensure
|
|
27
|
+
// there is some value.
|
|
28
|
+
"/" + normalName },
|
|
25
29
|
React.createElement(CurrentRouteContext.Provider, { value: routes }, children)));
|
|
26
30
|
}
|
|
27
|
-
function useRoutesAtPath(
|
|
28
|
-
const normalName = React.useMemo(() => getNameFromFilePath(filename), [filename]);
|
|
31
|
+
function useRoutesAtPath(normalName) {
|
|
29
32
|
const routes = useContext(RoutesContext);
|
|
30
33
|
const keys = React.useMemo(() => routes.keys(), [routes]);
|
|
31
34
|
const family = React.useMemo(() => {
|
package/build/Route.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Route.js","sourceRoot":"","sources":["../src/Route.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAa,UAAU,EAAE,MAAM,OAAO,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AA0BpE,MAAM,uBAAuB,GAAG,KAAK,CAAC,aAAa,CAAgB,IAAI,CAAC,CAAC;AAEzE,MAAM,mBAAmB,GAAG,KAAK,CAAC,aAAa,CAAc,EAAE,CAAC,CAAC;AAEjE,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;IACzC,uBAAuB,CAAC,WAAW,GAAG,WAAW,CAAC;IAClD,mBAAmB,CAAC,WAAW,GAAG,OAAO,CAAC;CAC3C;AAED,sDAAsD;AACtD,MAAM,UAAU,SAAS;IACvB,OAAO,UAAU,CAAC,mBAAmB,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,MAAM,QAAQ,GAAG,UAAU,CAAC,uBAAuB,CAAC,CAAC;IACrD,IAAI,
|
|
1
|
+
{"version":3,"file":"Route.js","sourceRoot":"","sources":["../src/Route.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAa,UAAU,EAAE,MAAM,OAAO,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AA0BpE,MAAM,uBAAuB,GAAG,K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C,CAAC,CAAC;SACX;QACD,OAAO,CAAC,CAAC;KACV;IAED,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,KAAK,OAAO,IAAI,iBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;IACzE,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,KAAK,OAAO,IAAI,iBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;IAEzE,IAAI,MAAM,IAAI,CAAC,MAAM,EAAE;QACrB,OAAO,CAAC,CAAC,CAAC;KACX;IACD,IAAI,CAAC,MAAM,IAAI,MAAM,EAAE;QACrB,OAAO,CAAC,CAAC;KACV;IAED,OAAO,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC;AACzC,CAAC","sourcesContent":["import React, { ReactNode, useContext } from \"react\";\n\nimport { RoutesContext } from \"./context\";\nimport { getNameFromFilePath, matchFragmentName } from \"./matchers\";\n\n/** The list of input keys will become optional, everything else will remain the same. */\nexport type PickPartial<T, K extends keyof T> = Omit<T, K> &\n Partial<Pick<T, K>>;\n\nexport type RouteNode = {\n /** nested routes */\n children: RouteNode[];\n /** Lazily get the React component */\n getComponent: () => React.ComponentType<any>;\n /** Is the route a dynamic path */\n dynamic: null | { name: string; deep: boolean };\n /** All static exports from the file. */\n getExtras: () => Record<string, any>;\n /** `index`, `error-boundary`, etc. */\n route: string;\n /** require.context key, used for matching children. */\n contextKey: string;\n /** Added in-memory */\n generated?: boolean;\n\n /** Internal screens like the directory or the auto 404 should be marked as internal. */\n internal?: boolean;\n};\n\nconst CurrentRoutePathContext = React.createContext<string | null>(null);\n\nconst CurrentRouteContext = React.createContext<RouteNode[]>([]);\n\nif (process.env.NODE_ENV !== \"production\") {\n CurrentRoutePathContext.displayName = \"RoutePath\";\n CurrentRouteContext.displayName = \"Route\";\n}\n\n/** Return all the routes for the current boundary. */\nexport function useRoutes(): RouteNode[] {\n return useContext(CurrentRouteContext);\n}\n\nexport function useContextKey(): string {\n const filename = useContext(CurrentRoutePathContext);\n if (filename == null) {\n throw new Error(\"No filename found. This is likely a bug in expo-router.\");\n }\n return filename;\n}\n\n/** Provides the matching routes and filename to the children. */\nexport function Route({\n filename,\n children,\n}: {\n filename: string;\n children: ReactNode;\n}) {\n const normalName = React.useMemo(\n () => getNameFromFilePath(filename),\n [filename]\n );\n\n const routes = useRoutesAtPath(normalName);\n\n return (\n <CurrentRoutePathContext.Provider\n value={\n // The root path is `` (empty string) so always prepend `/` to ensure\n // there is some value.\n \"/\" + normalName\n }\n >\n <CurrentRouteContext.Provider value={routes}>\n {children}\n </CurrentRouteContext.Provider>\n </CurrentRoutePathContext.Provider>\n );\n}\n\nfunction useRoutesAtPath(normalName: string): RouteNode[] {\n const routes = useContext(RoutesContext);\n const keys = React.useMemo(() => routes.keys(), [routes]);\n\n const family = React.useMemo(() => {\n let children: RouteNode[] = routes;\n\n // Skip root directory\n if (normalName) {\n // split and search\n const parts = normalName.split(\"/\");\n for (const part of parts) {\n const next = children.find(({ route }) => route === part);\n\n if (!next?.children) {\n return [];\n }\n\n children = next?.children;\n }\n }\n\n return children.sort(sortRoutes);\n }, [normalName, keys]);\n\n return family;\n}\n\nexport function sortRoutes(a: RouteNode, b: RouteNode): number {\n if (a.dynamic && !b.dynamic) {\n return 1;\n }\n if (!a.dynamic && b.dynamic) {\n return -1;\n }\n if (a.dynamic && b.dynamic) {\n if (a.dynamic.deep && !b.dynamic.deep) {\n return 1;\n }\n if (!a.dynamic.deep && b.dynamic.deep) {\n return -1;\n }\n return 0;\n }\n\n const aIndex = a.route === \"index\" || matchFragmentName(a.route) != null;\n const bIndex = b.route === \"index\" || matchFragmentName(b.route) != null;\n\n if (aIndex && !bIndex) {\n return -1;\n }\n if (!aIndex && bIndex) {\n return 1;\n }\n\n return a.route.length - b.route.length;\n}\n"]}
|
package/build/exports.d.ts
CHANGED
|
@@ -11,4 +11,5 @@ export { RootContainer } from "./ContextNavigationContainer";
|
|
|
11
11
|
export * as Linking from "./link/linking";
|
|
12
12
|
export { SplashScreen } from "./views/Splash";
|
|
13
13
|
export { useHref } from "./link/useHref";
|
|
14
|
+
export { useNavigation } from "./useNavigation";
|
|
14
15
|
//# sourceMappingURL=exports.d.ts.map
|
package/build/exports.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../src/exports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAK1C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../src/exports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,O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CAAuC;AACvC,6CAA6C;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["export { useFocusEffect } from \"@react-navigation/native\";\nexport { ErrorBoundaryProps } from \"./views/Try\";\n\nexport { withLayoutContext } from \"./layouts/withLayoutContext\";\n\nexport { ExpoRoot } from \"./views/Root\";\nexport { Unmatched } from \"./views/Unmatched\";\nexport { ErrorBoundary } from \"./views/ErrorBoundary\";\n\nexport { Layout, Children } from \"./views/Layout\";\nexport { Link, Redirect } from \"./link/Link\";\nexport { useLink } from \"./link/useLink\";\nexport { RootContainer } from \"./ContextNavigationContainer\";\n\nexport * as Linking from \"./link/linking\";\n\n// export { useRoutes } from \"./Route\";\n// export { useScreens } from \"./useScreens\";\n\nexport { SplashScreen } from \"./views/Splash\";\nexport { useHref } from \"./link/useHref\";\n"]}
|
|
1
|
+
{"version":3,"file":"exports.js","sourceRoot":"","sources":["../src/exports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;2BAEpC,gBAAgB;sBAA7B,OAAO;AAEnB,uCAAuC;AACvC,6CAA6C;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC","sourcesContent":["export { useFocusEffect } from \"@react-navigation/native\";\nexport { ErrorBoundaryProps } from \"./views/Try\";\n\nexport { withLayoutContext } from \"./layouts/withLayoutContext\";\n\nexport { ExpoRoot } from \"./views/Root\";\nexport { Unmatched } from \"./views/Unmatched\";\nexport { ErrorBoundary } from \"./views/ErrorBoundary\";\n\nexport { Layout, Children } from \"./views/Layout\";\nexport { Link, Redirect } from \"./link/Link\";\nexport { useLink } from \"./link/useLink\";\nexport { RootContainer } from \"./ContextNavigationContainer\";\n\nexport * as Linking from \"./link/linking\";\n\n// export { useRoutes } from \"./Route\";\n// export { useScreens } from \"./useScreens\";\n\nexport { SplashScreen } from \"./views/Splash\";\nexport { useHref } from \"./link/useHref\";\nexport { useNavigation } from \"./useNavigation\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withLayoutContext.d.ts","sourceRoot":"","sources":["../../src/layouts/withLayoutContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"withLayoutContext.d.ts","sourceRoot":"","sources":["../../src/layouts/withLayoutContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAoB,WAAW,EAAE,MAAM,eAAe,CAAC;AAG9D,aAAK,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAE1E,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,EAAE,iBAAiB,EAAE,GAAE;IAAE,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAAO;;;EAgD5D;AAED,2JAA2J;AAC3J,wBAAgB,iBAAiB,CAC/B,QAAQ,SAAS,MAAM,EACvB,CAAC,SAAS,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,EAElC,GAAG,EAAE,CAAC,EACN,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,QAAQ,CAAC,EAAE,KAAK,WAAW,CAAC,QAAQ,CAAC,EAAE,GACxE,KAAK,CAAC,yBAAyB,CAChC,KAAK,CAAC,eAAe,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,GACrE,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAC/B,GAAG;IACF,MAAM,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC;CAChD,CAiCA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { useContextKey } from "../Route";
|
|
2
3
|
import { useSortedScreens } from "../useScreens";
|
|
3
4
|
import { Screen } from "../views/Screen";
|
|
4
5
|
export function useFilterScreenChildren(children, { isCustomNavigator } = {}) {
|
|
@@ -42,6 +43,7 @@ export function useFilterScreenChildren(children, { isCustomNavigator } = {}) {
|
|
|
42
43
|
/** Return a navigator that automatically injects matched routes and renders nothing when there are no children. Return type with children prop optional */
|
|
43
44
|
export function withLayoutContext(Nav, processor) {
|
|
44
45
|
const Navigator = React.forwardRef(({ children: userDefinedChildren, ...props }, ref) => {
|
|
46
|
+
const contextKey = useContextKey();
|
|
45
47
|
const { screens } = useFilterScreenChildren(userDefinedChildren);
|
|
46
48
|
const processed = processor ? processor(screens ?? []) : screens;
|
|
47
49
|
const sorted = useSortedScreens(processed ?? []);
|
|
@@ -51,7 +53,7 @@ export function withLayoutContext(Nav, processor) {
|
|
|
51
53
|
}
|
|
52
54
|
return (
|
|
53
55
|
// @ts-expect-error
|
|
54
|
-
React.createElement(Nav, { ...props, ref: ref, children: sorted }));
|
|
56
|
+
React.createElement(Nav, { ...props, id: contextKey, ref: ref, children: sorted }));
|
|
55
57
|
});
|
|
56
58
|
// @ts-expect-error
|
|
57
59
|
Navigator.Screen = Screen;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withLayoutContext.js","sourceRoot":"","sources":["../../src/layouts/withLayoutContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,gBAAgB,EAAe,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAIzC,MAAM,UAAU,uBAAuB,CACrC,QAAyB,EACzB,EAAE,iBAAiB,KAAsC,EAAE;IAE3D,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACxB,MAAM,cAAc,GAAU,EAAE,CAAC;QACjC,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;YACrD,IAAI,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE;gBACjE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE;oBACrB,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAC;iBACH;gBACD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;oBACzC,IACE,CAAC,UAAU,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC,IAAI,CAC5C,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,KAAK,CAAC,KAAK,CAC5B,EACD;wBACA,MAAM,IAAI,KAAK,CACb,mGAAmG,CACpG,CAAC;qBACH;iBACF;gBACD,OAAO,KAAK,CAAC,KAAK,CAAC;aACpB;iBAAM;gBACL,IAAI,iBAAiB,EAAE;oBACrB,cAAc,C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AAE,QAAQ,EAAE,MAAM,GAAI,CAC/D,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,mBAAmB;IACnB,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC;IAC1B,mBAAmB;IACnB,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import React from \"react\";\n\nimport { useContextKey } from \"../Route\";\nimport { useSortedScreens, ScreenProps } from \"../useScreens\";\nimport { Screen } from \"../views/Screen\";\n\ntype PickPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\n\nexport function useFilterScreenChildren(\n children: React.ReactNode,\n { isCustomNavigator }: { isCustomNavigator?: boolean } = {}\n) {\n return React.useMemo(() => {\n const customChildren: any[] = [];\n const screens = React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child && child.type === Screen) {\n if (!child.props.name) {\n throw new Error(\n \"Screen must have a name prop when used as a child of a Layout\"\n );\n }\n if (process.env.NODE_ENV !== \"production\") {\n if (\n [\"children\", \"component\", \"getComponent\"].some(\n (key) => key in child.props\n )\n ) {\n throw new Error(\n \"Screen must not have a children, component, or getComponent prop when used as a child of a Layout\"\n );\n }\n }\n return child.props;\n } else {\n if (isCustomNavigator) {\n customChildren.push(child);\n } else {\n console.warn(\n \"Layout children must be of type Screen, all other children are ignored. To use custom children, create a custom <Layout />.\"\n );\n }\n }\n });\n\n // Add an assertion for development\n if (process.env.NODE_ENV !== \"production\") {\n // Assert if names are not unique\n const names = screens?.map((screen) => screen.name);\n if (names && new Set(names).size !== names.length) {\n throw new Error(\"Screen names must be unique: \" + names);\n }\n }\n\n return {\n screens,\n children: customChildren,\n };\n }, [children]);\n}\n\n/** Return a navigator that automatically injects matched routes and renders nothing when there are no children. Return type with children prop optional */\nexport function withLayoutContext<\n TOptions extends object,\n T extends React.ComponentType<any>\n>(\n Nav: T,\n processor?: (options: ScreenProps<TOptions>[]) => ScreenProps<TOptions>[]\n): React.ForwardRefExoticComponent<\n React.PropsWithoutRef<PickPartial<React.ComponentProps<T>, \"children\">> &\n React.RefAttributes<unknown>\n> & {\n Screen: (props: ScreenProps<TOptions>) => null;\n} {\n const Navigator = React.forwardRef(\n (\n {\n children: userDefinedChildren,\n ...props\n }: PickPartial<React.ComponentProps<T>, \"children\">,\n ref\n ) => {\n const contextKey = useContextKey();\n\n const { screens } = useFilterScreenChildren(userDefinedChildren);\n\n const processed = processor ? processor(screens ?? []) : screens;\n\n const sorted = useSortedScreens(processed ?? []);\n\n // Prevent throwing an error when there are no screens.\n if (!sorted.length) {\n return null;\n }\n\n return (\n // @ts-expect-error\n <Nav {...props} id={contextKey} ref={ref} children={sorted} />\n );\n }\n );\n\n // @ts-expect-error\n Navigator.Screen = Screen;\n // @ts-expect-error\n return Navigator;\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NavigationProp } from "@react-navigation/native";
|
|
2
|
+
/**
|
|
3
|
+
* Return the navigation object for the current route.
|
|
4
|
+
* @param parent Provide an absolute path like `/(root)` to the parent route or a relative path like `../../` to the parent route.
|
|
5
|
+
* @returns the navigation object for the provided route.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useNavigation(parent?: string): NavigationProp<ReactNavigation.RootParamList>;
|
|
8
|
+
export declare function resolveParentId(contextKey: string, parentId?: string | null): string | null;
|
|
9
|
+
//# sourceMappingURL=useNavigation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNavigation.d.ts","sourceRoot":"","sources":["../src/useNavigation.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACf,MAAM,0BAA0B,CAAC;AAMlC;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,MAAM,CAAC,EAAE,MAAM,GACd,cAAc,CAAC,eAAe,CAAC,aAAa,CAAC,CAiC/C;AAED,wBAAgB,eAAe,CAC7B,UAAU,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GACvB,MAAM,GAAG,IAAI,CASf"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { useNavigation as useUpstreamNavigation, } from "@react-navigation/native";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { useContextKey } from "./Route";
|
|
4
|
+
import { getNameFromFilePath } from "./matchers";
|
|
5
|
+
/**
|
|
6
|
+
* Return the navigation object for the current route.
|
|
7
|
+
* @param parent Provide an absolute path like `/(root)` to the parent route or a relative path like `../../` to the parent route.
|
|
8
|
+
* @returns the navigation object for the provided route.
|
|
9
|
+
*/
|
|
10
|
+
export function useNavigation(parent) {
|
|
11
|
+
// TODO: Maybe disable all this hook stuff when name is defined.
|
|
12
|
+
const navigation = useUpstreamNavigation();
|
|
13
|
+
const contextKey = useContextKey();
|
|
14
|
+
const normalizedParent = React.useMemo(() => {
|
|
15
|
+
if (!parent) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const normalized = getNameFromFilePath(parent);
|
|
19
|
+
if (parent.startsWith(".")) {
|
|
20
|
+
return relativePaths(contextKey, parent);
|
|
21
|
+
}
|
|
22
|
+
return normalized;
|
|
23
|
+
}, [contextKey, parent]);
|
|
24
|
+
if (normalizedParent != null) {
|
|
25
|
+
const parentNavigation = navigation.getParent(normalizedParent);
|
|
26
|
+
// TODO: Maybe print a list of parents...
|
|
27
|
+
if (!parentNavigation) {
|
|
28
|
+
throw new Error(`Could not find parent navigation with route "${parent}".` +
|
|
29
|
+
(normalizedParent !== parent
|
|
30
|
+
? ` (normalized: ${normalizedParent})`
|
|
31
|
+
: ""));
|
|
32
|
+
}
|
|
33
|
+
return parentNavigation;
|
|
34
|
+
}
|
|
35
|
+
return navigation;
|
|
36
|
+
}
|
|
37
|
+
export function resolveParentId(contextKey, parentId) {
|
|
38
|
+
if (!parentId) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
if (parentId.startsWith(".")) {
|
|
42
|
+
return getNameFromFilePath(relativePaths(contextKey, parentId));
|
|
43
|
+
}
|
|
44
|
+
return getNameFromFilePath(parentId);
|
|
45
|
+
}
|
|
46
|
+
// Resolve a path like `../` relative to a path like `/foo/bar`
|
|
47
|
+
function relativePaths(from, to) {
|
|
48
|
+
const fromParts = from.split("/").filter(Boolean);
|
|
49
|
+
const toParts = to.split("/").filter(Boolean);
|
|
50
|
+
for (const part of toParts) {
|
|
51
|
+
if (part === "..") {
|
|
52
|
+
if (fromParts.length === 0) {
|
|
53
|
+
throw new Error(`Cannot resolve path "${to}" relative to "${from}"`);
|
|
54
|
+
}
|
|
55
|
+
fromParts.pop();
|
|
56
|
+
}
|
|
57
|
+
else if (part === ".") {
|
|
58
|
+
// Ignore
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
fromParts.push(part);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return "/" + fromParts.join("/");
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=useNavigation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNavigation.js","sourceRoot":"","sources":["../src/useNavigation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,IAAI,qBAAqB,GAEvC,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAC3B,MAAe;IAEf,gEAAgE;IAChE,MAAM,UAAU,GAAG,qBAAqB,EAAO,CAAC;IAEhD,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IACnC,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QAC1C,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,IAAI,CAAC;SACb;QACD,MAAM,UAAU,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;QAE/C,IAAI,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE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AC1B,MAAM,IAAI,KAAK,CAAC,wBAAwB,EAAE,kBAAkB,IAAI,GAAG,CAAC,CAAC;aACtE;YACD,SAAS,CAAC,GAAG,EAAE,CAAC;SACjB;aAAM,IAAI,IAAI,KAAK,GAAG,EAAE;YACvB,SAAS;SACV;aAAM;YACL,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACtB;KACF;IAED,OAAO,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACnC,CAAC","sourcesContent":["import {\n useNavigation as useUpstreamNavigation,\n NavigationProp,\n} from \"@react-navigation/native\";\nimport React from \"react\";\n\nimport { useContextKey } from \"./Route\";\nimport { getNameFromFilePath } from \"./matchers\";\n\n/**\n * Return the navigation object for the current route.\n * @param parent Provide an absolute path like `/(root)` to the parent route or a relative path like `../../` to the parent route.\n * @returns the navigation object for the provided route.\n */\nexport function useNavigation(\n parent?: string\n): NavigationProp<ReactNavigation.RootParamList> {\n // TODO: Maybe disable all this hook stuff when name is defined.\n const navigation = useUpstreamNavigation<any>();\n\n const contextKey = useContextKey();\n const normalizedParent = React.useMemo(() => {\n if (!parent) {\n return null;\n }\n const normalized = getNameFromFilePath(parent);\n\n if (parent.startsWith(\".\")) {\n return relativePaths(contextKey, parent);\n }\n return normalized;\n }, [contextKey, parent]);\n\n if (normalizedParent != null) {\n const parentNavigation = navigation.getParent(normalizedParent);\n\n // TODO: Maybe print a list of parents...\n\n if (!parentNavigation) {\n throw new Error(\n `Could not find parent navigation with route \"${parent}\".` +\n (normalizedParent !== parent\n ? ` (normalized: ${normalizedParent})`\n : \"\")\n );\n }\n return parentNavigation;\n }\n return navigation;\n}\n\nexport function resolveParentId(\n contextKey: string,\n parentId?: string | null\n): string | null {\n if (!parentId) {\n return null;\n }\n\n if (parentId.startsWith(\".\")) {\n return getNameFromFilePath(relativePaths(contextKey, parentId));\n }\n return getNameFromFilePath(parentId);\n}\n\n// Resolve a path like `../` relative to a path like `/foo/bar`\nfunction relativePaths(from: string, to: string): string {\n const fromParts = from.split(\"/\").filter(Boolean);\n const toParts = to.split(\"/\").filter(Boolean);\n\n for (const part of toParts) {\n if (part === \"..\") {\n if (fromParts.length === 0) {\n throw new Error(`Cannot resolve path \"${to}\" relative to \"${from}\"`);\n }\n fromParts.pop();\n } else if (part === \".\") {\n // Ignore\n } else {\n fromParts.push(part);\n }\n }\n\n return \"/\" + fromParts.join(\"/\");\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Layout.d.ts","sourceRoot":"","sources":["../../src/views/Layout.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,oBAAoB,EACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAQ/B,eAAO,MAAM,aAAa;gBACZ,MAAM;WACX,GAAG;gBACE,GAAG;iBACF,GAAG;YACR,cAAc,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;SACvB,CAAC;AAMhB,oBAAY,WAAW,GAAG;IACxB,gBAAgB,CAAC,EAAE,UAAU,CAC3B,OAAO,oBAAoB,CAC5B,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC;IACzB,aAAa,CAAC,EAAE,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;IAC5E,QAAQ,CAAC,EAAE,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IAClE,MAAM,CAAC,EAAE,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;CACrD,CAAC;AAEF,+DAA+D;AAC/D,wBAAgB,MAAM,CAAC,EACrB,gBAAgB,EAChB,aAAa,EACb,QAAQ,EACR,MAAoB,GACrB,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"Layout.d.ts","sourceRoot":"","sources":["../../src/views/Layout.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,oBAAoB,EACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAQ/B,eAAO,MAAM,aAAa;gBACZ,MAAM;WACX,GAAG;gBACE,GAAG;iBACF,GAAG;YACR,cAAc,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;SACvB,CAAC;AAMhB,oBAAY,WAAW,GAAG;IACxB,gBAAgB,CAAC,EAAE,UAAU,CAC3B,OAAO,oBAAoB,CAC5B,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC;IACzB,aAAa,CAAC,EAAE,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;IAC5E,QAAQ,CAAC,EAAE,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IAClE,MAAM,CAAC,EAAE,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;CACrD,CAAC;AAEF,+DAA+D;AAC/D,wBAAgB,MAAM,CAAC,EACrB,gBAAgB,EAChB,aAAa,EACb,QAAQ,EACR,MAAoB,GACrB,EAAE,WAAW,eAiCb;yBAtCe,MAAM;;;;;AAwCtB,wBAAgB,gBAAgB;;;;;;EAM/B;AAED,wBAAgB,QAAQ,QAcvB;AAED,8CAA8C;AAC9C,wBAAgB,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,eAc5D;AAED,wBAAgB,eAAe,QAE9B;AAED,wBAAgB,aAAa,gBAM5B"}
|
package/build/views/Layout.js
CHANGED
|
@@ -16,6 +16,8 @@ export function Layout({ initialRouteName, screenOptions, children, router = Sta
|
|
|
16
16
|
const { screens, children: otherChildren } = useFilterScreenChildren(children, { isCustomNavigator: true });
|
|
17
17
|
const sorted = useSortedScreens(screens ?? []);
|
|
18
18
|
const { state, navigation, descriptors, NavigationContent } = useNavigationBuilder(router, {
|
|
19
|
+
// Used for getting the parent with navigation.getParent('/normalized/path')
|
|
20
|
+
id: contextKey,
|
|
19
21
|
children: sorted,
|
|
20
22
|
screenOptions,
|
|
21
23
|
initialRouteName,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Layout.js","sourceRoot":"","sources":["../../src/views/Layout.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,qFAAqF;AACrF,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC,aAAa,CAMtC,IAAI,CAAC,CAAC;AAEhB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;IACzC,aAAa,CAAC,WAAW,GAAG,eAAe,CAAC;CAC7C;AAWD,+DAA+D;AAC/D,MAAM,UAAU,MAAM,CAAC,EACrB,gBAAgB,EAChB,aAAa,EACb,QAAQ,EACR,MAAM,GAAG,WAAW,GACR;IACZ,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IAEnC,mEAAmE;IACnE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,GAAG,uBAAuB,CAClE,QAAQ,EACR,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAC5B,CAAC;IAEF,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAE/C,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,iBAAiB,EAAE,GACzD,oBAAoB,CAAC,MA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AC,eAAe,OAAG,CACZ,CACV,CAAC;KACH;IAED,OAAO,oBAAC,eAAe,OAAG,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,OAAO,QAAQ,EAAE,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,OAAO,CACL,oBAAC,MAAM;QACL,oBAAC,eAAe,OAAG,CACZ,CACV,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAC3B,MAAM,CAAC,UAAU,GAAG,gBAAgB,CAAC;AAErC,wCAAwC;AACxC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC","sourcesContent":["import {\n RouterFactory,\n StackRouter,\n useNavigationBuilder,\n} from \"@react-navigation/native\";\nimport * as React from \"react\";\n\nimport { useContextKey } from \"../Route\";\nimport { useFilterScreenChildren } from \"../layouts/withLayoutContext\";\nimport { useSortedScreens } from \"../useScreens\";\nimport { Screen } from \"./Screen\";\n\n// TODO: This might already exist upstream, maybe something like `useCurrentRender` ?\nexport const LayoutContext = React.createContext<{\n contextKey: string;\n state: any;\n navigation: any;\n descriptors: any;\n router: RouterFactory<any, any, any>;\n} | null>(null);\n\nif (process.env.NODE_ENV !== \"production\") {\n LayoutContext.displayName = \"LayoutContext\";\n}\n\nexport type LayoutProps = {\n initialRouteName?: Parameters<\n typeof useNavigationBuilder\n >[1][\"initialRouteName\"];\n screenOptions?: Parameters<typeof useNavigationBuilder>[1][\"screenOptions\"];\n children?: Parameters<typeof useNavigationBuilder>[1][\"children\"];\n router?: Parameters<typeof useNavigationBuilder>[0];\n};\n\n/** An unstyled custom navigator. Good for basic web layouts */\nexport function Layout({\n initialRouteName,\n screenOptions,\n children,\n router = StackRouter,\n}: LayoutProps) {\n const contextKey = useContextKey();\n\n // Allows adding Screen components as children to configure routes.\n const { screens, children: otherChildren } = useFilterScreenChildren(\n children,\n { isCustomNavigator: true }\n );\n\n const sorted = useSortedScreens(screens ?? []);\n\n const { state, navigation, descriptors, NavigationContent } =\n useNavigationBuilder(router, {\n children: sorted,\n screenOptions,\n initialRouteName,\n });\n\n return (\n <LayoutContext.Provider\n value={{\n contextKey,\n state,\n navigation,\n descriptors,\n router,\n }}\n >\n <NavigationContent>{otherChildren}</NavigationContent>\n </LayoutContext.Provider>\n );\n}\n\nexport function useLayoutContext() {\n const context = React.useContext(LayoutContext);\n if (!context) {\n throw new Error(\"useLayoutContext must be used within a <Layout />\");\n }\n return context;\n}\n\nexport function useChild() {\n const context = useLayoutContext();\n\n const { state, descriptors } = context;\n\n const current = state.routes.find((route, i) => {\n return state.index === i;\n });\n\n if (!current) {\n return null;\n }\n\n return descriptors[current.key]?.render() ?? null;\n}\n\n/** Renders the currently selected content. */\nexport function Children(props: Omit<LayoutProps, \"children\">) {\n const contextKey = useContextKey();\n const context = React.useContext(LayoutContext);\n // Ensure the context is for the current contextKey\n if (context?.contextKey !== contextKey) {\n // Qualify the content and re-export.\n return (\n <Layout {...props}>\n <TrustedChildren />\n </Layout>\n );\n }\n\n return <TrustedChildren />;\n}\n\nexport function TrustedChildren() {\n return useChild();\n}\n\nexport function DefaultLayout() {\n return (\n <Layout>\n <TrustedChildren />\n </Layout>\n );\n}\n\nLayout.Children = Children;\nLayout.useContext = useLayoutContext;\n\n/** Used to configure route settings. */\nLayout.Screen = Screen;\n"]}
|
|
1
|
+
{"version":3,"file":"Layout.js","sourceRoot":"","sources":["../../src/views/Layout.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,qFAAqF;AACr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,EAAE,CAAC;IAEnC,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAEvC,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;QAC7C,OAAO,KAAK,CAAC,KAAK,KAAK,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,IAAI,CAAC;KACb;IAED,OAAO,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,IAAI,IAAI,CAAC;AACpD,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,QAAQ,CAAC,KAAoC;IAC3D,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IACnC,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IAChD,mDAAmD;IACnD,IAAI,OAAO,EAAE,UAAU,KAAK,UAAU,EAAE;QACtC,qCAAqC;QACrC,OAAO,CACL,oBAAC,MAAM,OAAK,KAAK;YACf,oBAAC,eAAe,OAAG,CACZ,CACV,CAAC;KACH;IAED,OAAO,oBAAC,eAAe,OAAG,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,OAAO,QAAQ,EAAE,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,OAAO,CACL,oBAAC,MAAM;QACL,oBAAC,eAAe,OAAG,CACZ,CACV,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAC3B,MAAM,CAAC,UAAU,GAAG,gBAAgB,CAAC;AAErC,wCAAwC;AACxC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC","sourcesContent":["import {\n RouterFactory,\n StackRouter,\n useNavigationBuilder,\n} from \"@react-navigation/native\";\nimport * as React from \"react\";\n\nimport { useContextKey } from \"../Route\";\nimport { useFilterScreenChildren } from \"../layouts/withLayoutContext\";\nimport { useSortedScreens } from \"../useScreens\";\nimport { Screen } from \"./Screen\";\n\n// TODO: This might already exist upstream, maybe something like `useCurrentRender` ?\nexport const LayoutContext = React.createContext<{\n contextKey: string;\n state: any;\n navigation: any;\n descriptors: any;\n router: RouterFactory<any, any, any>;\n} | null>(null);\n\nif (process.env.NODE_ENV !== \"production\") {\n LayoutContext.displayName = \"LayoutContext\";\n}\n\nexport type LayoutProps = {\n initialRouteName?: Parameters<\n typeof useNavigationBuilder\n >[1][\"initialRouteName\"];\n screenOptions?: Parameters<typeof useNavigationBuilder>[1][\"screenOptions\"];\n children?: Parameters<typeof useNavigationBuilder>[1][\"children\"];\n router?: Parameters<typeof useNavigationBuilder>[0];\n};\n\n/** An unstyled custom navigator. Good for basic web layouts */\nexport function Layout({\n initialRouteName,\n screenOptions,\n children,\n router = StackRouter,\n}: LayoutProps) {\n const contextKey = useContextKey();\n\n // Allows adding Screen components as children to configure routes.\n const { screens, children: otherChildren } = useFilterScreenChildren(\n children,\n { isCustomNavigator: true }\n );\n\n const sorted = useSortedScreens(screens ?? []);\n\n const { state, navigation, descriptors, NavigationContent } =\n useNavigationBuilder(router, {\n // Used for getting the parent with navigation.getParent('/normalized/path')\n id: contextKey,\n children: sorted,\n screenOptions,\n initialRouteName,\n });\n\n return (\n <LayoutContext.Provider\n value={{\n contextKey,\n state,\n navigation,\n descriptors,\n router,\n }}\n >\n <NavigationContent>{otherChildren}</NavigationContent>\n </LayoutContext.Provider>\n );\n}\n\nexport function useLayoutContext() {\n const context = React.useContext(LayoutContext);\n if (!context) {\n throw new Error(\"useLayoutContext must be used within a <Layout />\");\n }\n return context;\n}\n\nexport function useChild() {\n const context = useLayoutContext();\n\n const { state, descriptors } = context;\n\n const current = state.routes.find((route, i) => {\n return state.index === i;\n });\n\n if (!current) {\n return null;\n }\n\n return descriptors[current.key]?.render() ?? null;\n}\n\n/** Renders the currently selected content. */\nexport function Children(props: Omit<LayoutProps, \"children\">) {\n const contextKey = useContextKey();\n const context = React.useContext(LayoutContext);\n // Ensure the context is for the current contextKey\n if (context?.contextKey !== contextKey) {\n // Qualify the content and re-export.\n return (\n <Layout {...props}>\n <TrustedChildren />\n </Layout>\n );\n }\n\n return <TrustedChildren />;\n}\n\nexport function TrustedChildren() {\n return useChild();\n}\n\nexport function DefaultLayout() {\n return (\n <Layout>\n <TrustedChildren />\n </Layout>\n );\n}\n\nLayout.Children = Children;\nLayout.useContext = useLayoutContext;\n\n/** Used to configure route settings. */\nLayout.Screen = Screen;\n"]}
|
package/build/views/Screen.d.ts
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export declare type ScreenProps<TOptions extends Record<string, any> = Record<string, any>> = {
|
|
2
|
+
/**
|
|
3
|
+
* Name is required when used inside a Layout component.
|
|
4
|
+
*
|
|
5
|
+
* When used in a route, this can be an absolute path like `/(root)` to the parent route or a relative path like `../../` to the parent route.
|
|
6
|
+
* This should not be used inside of a Layout component.
|
|
7
|
+
* @example `/(root)` maps to a layout route `/app/(root).tsx`.
|
|
8
|
+
*/
|
|
3
9
|
name?: string;
|
|
4
|
-
redirect
|
|
5
|
-
|
|
10
|
+
/** Should redirect away from this screen. */
|
|
11
|
+
redirect?: boolean;
|
|
12
|
+
initialParams?: {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
};
|
|
6
15
|
options?: TOptions;
|
|
7
|
-
}
|
|
16
|
+
};
|
|
17
|
+
/** Component for setting the current screen's options dynamically. */
|
|
18
|
+
export declare function Screen<TOptions extends object = object>({ name, redirect, options, }: ScreenProps<TOptions>): null;
|
|
8
19
|
//# sourceMappingURL=Screen.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Screen.d.ts","sourceRoot":"","sources":["../../src/views/Screen.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Screen.d.ts","sourceRoot":"","sources":["../../src/views/Screen.tsx"],"names":[],"mappings":"AAIA,oBAAY,WAAW,CACrB,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IACxD;IACF;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,aAAa,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;IACvC,OAAO,CAAC,EAAE,QAAQ,CAAC;CACpB,CAAC;AAEF,sEAAsE;AACtE,wBAAgB,MAAM,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,EAAE,EACvD,IAAI,EACJ,QAAQ,EACR,OAAO,GACR,EAAE,WAAW,CAAC,QAAQ,CAAC,QAmBvB"}
|
package/build/views/Screen.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import { useNavigation } from "@react-navigation/native";
|
|
2
1
|
import React from "react";
|
|
2
|
+
import { useNavigation } from "../useNavigation";
|
|
3
3
|
/** Component for setting the current screen's options dynamically. */
|
|
4
4
|
export function Screen({ name, redirect, options, }) {
|
|
5
|
-
|
|
6
|
-
const navigation = useNavigation();
|
|
5
|
+
const navigation = useNavigation(name);
|
|
7
6
|
React.useLayoutEffect(() => {
|
|
8
7
|
navigation.setOptions(options ?? {});
|
|
9
8
|
}, [navigation, options]);
|
|
10
9
|
if (process.env.NODE_ENV !== "production") {
|
|
11
10
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
12
11
|
React.useEffect(() => {
|
|
13
|
-
if (name != null) {
|
|
14
|
-
throw new Error("Screen components should only use the `name` prop when nested directly inside a Layout component. When a Screen is used for dynamic options it uses the nearest navigation context.");
|
|
15
|
-
}
|
|
16
12
|
if (redirect != null) {
|
|
17
13
|
throw new Error("Screen components should only use the `redirect` prop when nested directly inside a Layout component.");
|
|
18
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Screen.js","sourceRoot":"","sources":["../../src/views/Screen.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Screen.js","sourceRoot":"","sources":["../../src/views/Screen.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAqBjD,sEAAsE;AACtE,MAAM,UAAU,MAAM,CAAmC,EACvD,IAAI,EACJ,QAAQ,EACR,OAAO,GACe;IACtB,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IAEvC,KAAK,CAAC,eAAe,CAAC,GAAG,EAAE;QACzB,UAAU,CAAC,UAAU,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;IAE1B,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACzC,sDAAsD;QACtD,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;YACnB,IAAI,QAAQ,IAAI,IAAI,EAAE;gBACpB,MAAM,IAAI,KAAK,CACb,uGAAuG,CACxG,CAAC;aACH;QACH,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;KACtB;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import React from \"react\";\n\nimport { useNavigation } from \"../useNavigation\";\n\nexport type ScreenProps<\n TOptions extends Record<string, any> = Record<string, any>\n> = {\n /**\n * Name is required when used inside a Layout component.\n *\n * When used in a route, this can be an absolute path like `/(root)` to the parent route or a relative path like `../../` to the parent route.\n * This should not be used inside of a Layout component.\n * @example `/(root)` maps to a layout route `/app/(root).tsx`.\n */\n name?: string;\n\n /** Should redirect away from this screen. */\n redirect?: boolean;\n\n initialParams?: { [key: string]: any };\n options?: TOptions;\n};\n\n/** Component for setting the current screen's options dynamically. */\nexport function Screen<TOptions extends object = object>({\n name,\n redirect,\n options,\n}: ScreenProps<TOptions>) {\n const navigation = useNavigation(name);\n\n React.useLayoutEffect(() => {\n navigation.setOptions(options ?? {});\n }, [navigation, options]);\n\n if (process.env.NODE_ENV !== \"production\") {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (redirect != null) {\n throw new Error(\n \"Screen components should only use the `redirect` prop when nested directly inside a Layout component.\"\n );\n }\n }, [name, redirect]);\n }\n\n return null;\n}\n"]}
|