expo-router 0.0.5 → 0.0.6
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/getLinkingConfig.d.ts.map +1 -1
- package/build/getLinkingConfig.js +67 -1
- package/build/getLinkingConfig.js.map +1 -1
- package/build/useScreens.js +7 -7
- package/build/useScreens.js.map +1 -1
- package/build/views/Directory.d.ts.map +1 -1
- package/build/views/Directory.js +16 -3
- package/build/views/Directory.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLinkingConfig.d.ts","sourceRoot":"","sources":["../src/getLinkingConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"getLinkingConfig.d.ts","sourceRoot":"","sources":["../src/getLinkingConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAYzE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAqBpC,wBAAgB,kCAAkC,CAChD,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,GAAE,MAAM,EAAO,GACrB,aAAa,CAAC,EAAE,CAAC,CAwBnB;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,cAAc,CAAC,EAAE,CAAC,CA0FxE"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as Linking from "expo-linking";
|
|
2
|
+
import Constants, { ExecutionEnvironment } from "expo-constants";
|
|
2
3
|
import { getAllWebRedirects } from "./aasa";
|
|
3
4
|
import getPathFromState from "./fork/getPathFromState";
|
|
4
5
|
import getStateFromPath from "./fork/getStateFromPath";
|
|
@@ -40,10 +41,11 @@ export function treeToReactNavigationLinkingRoutes(nodes, parents = []) {
|
|
|
40
41
|
return firstPass;
|
|
41
42
|
}
|
|
42
43
|
export function getLinkingConfig(routes) {
|
|
44
|
+
const rootURL = Linking.createURL("/");
|
|
43
45
|
return {
|
|
44
46
|
prefixes: [
|
|
45
47
|
/* your linking prefixes */
|
|
46
|
-
|
|
48
|
+
rootURL,
|
|
47
49
|
// This ensures that we can redirect correctly when the user comes from an associated domain
|
|
48
50
|
// i.e. iOS Safari banner.
|
|
49
51
|
...getAllWebRedirects(),
|
|
@@ -51,6 +53,70 @@ export function getLinkingConfig(routes) {
|
|
|
51
53
|
config: {
|
|
52
54
|
screens: treeToReactNavigationLinkingRoutes(routes),
|
|
53
55
|
},
|
|
56
|
+
// A custom getInitialURL is used on native to ensure the app always starts at
|
|
57
|
+
// the root path if it's launched from something other than a deep link.
|
|
58
|
+
// This helps keep the native functionality working like the web functionality.
|
|
59
|
+
// For example, if you had a root navigator where the first screen was `/settings` and the second was `/index`
|
|
60
|
+
// then `/index` would be used on web and `/settings` would be used on native.
|
|
61
|
+
async getInitialURL() {
|
|
62
|
+
const url = await Promise.race([
|
|
63
|
+
(async () => {
|
|
64
|
+
const url = await Linking.getInitialURL();
|
|
65
|
+
// NOTE(EvanBacon): This could probably be wrapped with the development boundary
|
|
66
|
+
// since Expo Go is mostly just used in development.
|
|
67
|
+
// Expo Go is weird and requires the root path to be `/--/`
|
|
68
|
+
if (url &&
|
|
69
|
+
Constants.executionEnvironment === ExecutionEnvironment.StoreClient) {
|
|
70
|
+
const parsed = Linking.parse(url);
|
|
71
|
+
// If the URL is defined (default in Expo Go dev apps) and the URL has no path:
|
|
72
|
+
// `exp://192.168.87.39:19000/` then use the default `exp://192.168.87.39:19000/--/`
|
|
73
|
+
if (parsed.path === null || ["", "/"].includes(parsed.path)) {
|
|
74
|
+
return rootURL;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// The path will be nullish in bare apps when the app is launched from the home screen.
|
|
78
|
+
// TODO(EvanBacon): define some policy around notifications.
|
|
79
|
+
return url ?? rootURL;
|
|
80
|
+
})(),
|
|
81
|
+
new Promise((resolve) =>
|
|
82
|
+
// Timeout in 150ms if `getInitialState` doesn't resolve
|
|
83
|
+
// Workaround for https://github.com/facebook/react-native/issues/25675
|
|
84
|
+
setTimeout(() => resolve(rootURL), 150)),
|
|
85
|
+
]);
|
|
86
|
+
return url;
|
|
87
|
+
},
|
|
88
|
+
subscribe: (listener) => {
|
|
89
|
+
let callback = undefined;
|
|
90
|
+
if (Constants.executionEnvironment === ExecutionEnvironment.StoreClient) {
|
|
91
|
+
// This extra work is only done in the Expo Go app.
|
|
92
|
+
callback = ({ url }) => {
|
|
93
|
+
const parsed = Linking.parse(url);
|
|
94
|
+
// If the URL is defined (default in Expo Go dev apps) and the URL has no path:
|
|
95
|
+
// `exp://192.168.87.39:19000/` then use the default `exp://192.168.87.39:19000/--/`
|
|
96
|
+
if (parsed.path === null || ["", "/"].includes(parsed.path)) {
|
|
97
|
+
listener(rootURL);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
listener(url);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
callback = ({ url }) => listener(url);
|
|
106
|
+
}
|
|
107
|
+
const subscription = Linking.addEventListener("url", callback);
|
|
108
|
+
// Storing this in a local variable stops Jest from complaining about import after teardown
|
|
109
|
+
const removeEventListener = Linking.removeEventListener?.bind(Linking);
|
|
110
|
+
return () => {
|
|
111
|
+
// https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7
|
|
112
|
+
if (subscription?.remove) {
|
|
113
|
+
subscription.remove();
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
removeEventListener?.("url", callback);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
},
|
|
54
120
|
getStateFromPath,
|
|
55
121
|
getPathFromState,
|
|
56
122
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLinkingConfig.js","sourceRoot":"","sources":["../src/getLinkingConfig.ts"],"names":[],"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BACH,CAAC,CAAC;aACH;iBAAM;gBACL,QAAQ,GAAG,CAAC,EAAE,GAAG,EAAmB,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;aACxD;YACD,MAAM,YAAY,GAAG,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE,QAAQ,CAEhD,CAAC;YAEd,2FAA2F;YAC3F,MAAM,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YAEvE,OAAO,GAAG,EAAE;gBACV,2FAA2F;gBAC3F,IAAI,YAAY,EAAE,MAAM,EAAE;oBACxB,YAAY,CAAC,MAAM,EAAE,CAAC;iBACvB;qBAAM;oBACL,mBAAmB,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;iBACxC;YACH,CAAC,CAAC;QACJ,CAAC;QACD,gBAAgB;QAChB,gBAAgB;KACjB,CAAC;AACJ,CAAC","sourcesContent":["import { LinkingOptions, PathConfigMap } from \"@react-navigation/native\";\nimport * as Linking from \"expo-linking\";\n\nimport Constants, { ExecutionEnvironment } from \"expo-constants\";\nimport { getAllWebRedirects } from \"./aasa\";\nimport getPathFromState from \"./fork/getPathFromState\";\nimport getStateFromPath from \"./fork/getStateFromPath\";\nimport {\n matchDeepDynamicRouteName,\n matchDynamicName,\n matchFragmentName,\n} from \"./matchers\";\nimport { RouteNode } from \"./Route\";\n\n// `[page]` -> `:page`\n// `page` -> `page`\nfunction convertDynamicRouteToReactNavigation(name: string) {\n if (matchDeepDynamicRouteName(name)) {\n return \"*\";\n }\n const dynamicName = matchDynamicName(name);\n\n if (dynamicName) {\n return `:${dynamicName}`;\n }\n\n if (name === \"index\" || matchFragmentName(name)) {\n return \"\";\n }\n\n return name;\n}\n\nexport function treeToReactNavigationLinkingRoutes(\n nodes: RouteNode[],\n parents: string[] = []\n): PathConfigMap<{}> {\n // TODO: Intercept errors, strip invalid routes, and warn instead.\n // Our warnings can be more helpful than upstream since we know the associated file name.\n const firstPass = nodes\n .map((node) => {\n const path = convertDynamicRouteToReactNavigation(node.route);\n\n if (!node.children.length) {\n return [node.route, path];\n }\n\n const screens = treeToReactNavigationLinkingRoutes(node.children, [\n ...parents,\n path,\n ]);\n\n return [node.route, { path, screens }] as const;\n })\n .reduce<PathConfigMap<{}>>((acc, [route, current]) => {\n acc[route] = current;\n return acc;\n }, {});\n\n return firstPass;\n}\n\nexport function getLinkingConfig(routes: RouteNode[]): LinkingOptions<{}> {\n const rootURL = Linking.createURL(\"/\");\n\n return {\n prefixes: [\n /* your linking prefixes */\n rootURL,\n\n // This ensures that we can redirect correctly when the user comes from an associated domain\n // i.e. iOS Safari banner.\n ...getAllWebRedirects(),\n ],\n config: {\n screens: treeToReactNavigationLinkingRoutes(routes),\n },\n // A custom getInitialURL is used on native to ensure the app always starts at\n // the root path if it's launched from something other than a deep link.\n // This helps keep the native functionality working like the web functionality.\n // For example, if you had a root navigator where the first screen was `/settings` and the second was `/index`\n // then `/index` would be used on web and `/settings` would be used on native.\n async getInitialURL(): Promise<string> {\n const url = await Promise.race<string>([\n (async () => {\n const url = await Linking.getInitialURL();\n\n // NOTE(EvanBacon): This could probably be wrapped with the development boundary\n // since Expo Go is mostly just used in development.\n\n // Expo Go is weird and requires the root path to be `/--/`\n if (\n url &&\n Constants.executionEnvironment === ExecutionEnvironment.StoreClient\n ) {\n const parsed = Linking.parse(url);\n // If the URL is defined (default in Expo Go dev apps) and the URL has no path:\n // `exp://192.168.87.39:19000/` then use the default `exp://192.168.87.39:19000/--/`\n if (parsed.path === null || [\"\", \"/\"].includes(parsed.path)) {\n return rootURL;\n }\n }\n // The path will be nullish in bare apps when the app is launched from the home screen.\n // TODO(EvanBacon): define some policy around notifications.\n return url ?? rootURL;\n })(),\n new Promise<string>((resolve) =>\n // Timeout in 150ms if `getInitialState` doesn't resolve\n // Workaround for https://github.com/facebook/react-native/issues/25675\n setTimeout(() => resolve(rootURL), 150)\n ),\n ]);\n return url;\n },\n subscribe: (listener) => {\n let callback: (({ url }: { url: string }) => void) | undefined =\n undefined;\n\n if (Constants.executionEnvironment === ExecutionEnvironment.StoreClient) {\n // This extra work is only done in the Expo Go app.\n callback = ({ url }: { url: string }) => {\n const parsed = Linking.parse(url);\n // If the URL is defined (default in Expo Go dev apps) and the URL has no path:\n // `exp://192.168.87.39:19000/` then use the default `exp://192.168.87.39:19000/--/`\n if (parsed.path === null || [\"\", \"/\"].includes(parsed.path)) {\n listener(rootURL);\n } else {\n listener(url);\n }\n };\n } else {\n callback = ({ url }: { url: string }) => listener(url);\n }\n const subscription = Linking.addEventListener(\"url\", callback) as\n | { remove(): void }\n | undefined;\n\n // Storing this in a local variable stops Jest from complaining about import after teardown\n const removeEventListener = Linking.removeEventListener?.bind(Linking);\n\n return () => {\n // https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7\n if (subscription?.remove) {\n subscription.remove();\n } else {\n removeEventListener?.(\"url\", callback);\n }\n };\n },\n getStateFromPath,\n getPathFromState,\n };\n}\n"]}
|
package/build/useScreens.js
CHANGED
|
@@ -11,28 +11,28 @@ export function useScreens() {
|
|
|
11
11
|
}
|
|
12
12
|
function getSortedChildren(children, order) {
|
|
13
13
|
if (!order?.length) {
|
|
14
|
-
return
|
|
14
|
+
return children.sort(sortRoutes).map((route) => ({ route, props: {} }));
|
|
15
15
|
}
|
|
16
|
-
const entries =
|
|
16
|
+
const entries = [...children];
|
|
17
17
|
const ordered = order.map(({ name, initialParams, options }) => {
|
|
18
|
-
if (entries.length
|
|
18
|
+
if (!entries.length) {
|
|
19
19
|
console.warn(`[Layout children]: Too many screens defined. Route "${name}" is extraneous.`);
|
|
20
20
|
return null;
|
|
21
21
|
}
|
|
22
|
-
const matchIndex = entries.findIndex((child) => child
|
|
22
|
+
const matchIndex = entries.findIndex((child) => child.route === name);
|
|
23
23
|
if (matchIndex === -1) {
|
|
24
|
-
console.warn(`[Layout children]: No route named "${name}" exists in nested children:`,
|
|
24
|
+
console.warn(`[Layout children]: No route named "${name}" exists in nested children:`, children.map(({ route }) => route));
|
|
25
25
|
return null;
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
28
|
// Get match and remove from entries
|
|
29
|
-
const
|
|
29
|
+
const match = entries[matchIndex];
|
|
30
30
|
entries.splice(matchIndex, 1);
|
|
31
31
|
return { route: match, props: { initialParams, options } };
|
|
32
32
|
}
|
|
33
33
|
}).filter(Boolean);
|
|
34
34
|
// Add any remaining children
|
|
35
|
-
ordered.push(...entries.
|
|
35
|
+
ordered.push(...entries.sort(sortRoutes).map((route) => ({ route, props: {} })));
|
|
36
36
|
return ordered;
|
|
37
37
|
}
|
|
38
38
|
/**
|
package/build/useScreens.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useScreens.js","sourceRoot":"","sources":["../src/useScreens.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,KAAK,EAAa,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC;;GAEG;AACH,MAAM,UAAU,UAAU;IACtB,MAAM,QAAQ,GAAG,SAAS,EAAE,CAAC;IAC7B,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC1F,CAAC;AASD,SAAS,iBAAiB,CAAC,QAAqB,EAAE,KAAqB;IACnE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE;QAChB,OAAO,
|
|
1
|
+
{"version":3,"file":"useScreens.js","sourceRoot":"","sources":["../src/useScreens.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;A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,OAAO,aAAa,KAAK,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;YAC/F,MAAM,aAAa,GAAG,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;YAChF,OAAO;gBACH,GAAG,YAAY;gBACf,GAAG,aAAa;aACnB,CAAC;QACN,CAAC,CAAC,CAAC,CAAC,aAAa,EACjB,SAAS,EAAE,0BAA0B,CAAC,KAAK,CAAC,GAC9C,CACL,CAAC;AACN,CAAC","sourcesContent":["import React from 'react';\n\nimport { Screen } from './primitives';\nimport { Route, RouteNode, sortRoutes, useRoutes } from './Route';\nimport { Try } from './views/Try';\n\n/**\n * @returns React Navigation screens for the route.\n */\nexport function useScreens(): React.ReactNode[] {\n const children = useRoutes();\n return React.useMemo(() => children.map((value) => routeToScreen(value)), [children]);\n}\n\nexport type ScreenProps<TOptions extends Record<string, any> = Record<string, any>> = {\n /** Name is required when used inside a Layout component. */\n name?: string,\n initialParams?: { [key: string]: any };\n options?: TOptions;\n}\n\nfunction getSortedChildren(children: RouteNode[], order?: ScreenProps[]): { route: RouteNode, props: any }[] {\n if (!order?.length) {\n return children.sort(sortRoutes).map((route) => ({ route, props: {} }));\n }\n const entries = [...children];\n\n const ordered = order.map(({ name, initialParams, options }) => {\n if (!entries.length) {\n console.warn(`[Layout children]: Too many screens defined. Route \"${name}\" is extraneous.`);\n return null;\n }\n const matchIndex = entries.findIndex((child) => child.route === name)\n if (matchIndex === -1) {\n console.warn(`[Layout children]: No route named \"${name}\" exists in nested children:`, children.map(({ route }) => route));\n return null;\n } else {\n // Get match and remove from entries\n const match = entries[matchIndex];\n entries.splice(matchIndex, 1);\n\n return { route: match, props: { initialParams, options } }\n }\n }).filter(Boolean) as {\n route: RouteNode;\n props: Partial<ScreenProps>;\n }[]\n\n // Add any remaining children\n ordered.push(...entries.sort(sortRoutes).map((route) => ({ route, props: {} })));\n\n return ordered;\n}\n\n\n/** \n * @returns React Navigation screens sorted by the `route` property.\n */\nexport function useSortedScreens(order: ScreenProps[]): React.ReactNode[] {\n const children = useRoutes();\n const sorted = getSortedChildren(children, order);\n return React.useMemo(() =>\n sorted.map((value) => routeToScreen(value.route, value.props)), [sorted]);\n}\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. */\nfunction getQualifiedRouteComponent(value: RouteNode) {\n if (qualifiedStore.has(value)) {\n return qualifiedStore.get(value);\n }\n\n const Component = value.getComponent();\n\n const { ErrorBoundary } = value.getExtras();\n\n const QualifiedRoute = React.forwardRef(\n (props: { route: any; navigation: any }, ref: any) => {\n // Surface dynamic name as props to the view\n const children = React.createElement(Component, {\n ...props,\n ref,\n });\n\n const errorBoundary = ErrorBoundary ? (\n <Try catch={ErrorBoundary}>{children}</Try>\n ) : (\n children\n );\n\n return (\n <Route filename={value.contextKey}>\n {errorBoundary}\n </Route>\n );\n }\n );\n\n QualifiedRoute.displayName = `Route(${Component.displayName || Component.name || value.route})`;\n qualifiedStore.set(value, QualifiedRoute);\n return QualifiedRoute;\n}\n\nfunction routeToScreen(route: RouteNode, { options, ...props }: Partial<ScreenProps> = {}) {\n const staticOptions = route.getExtras()?.getNavOptions;\n return (\n // @ts-expect-error: fixme\n <Screen\n {...props}\n name={route.route}\n key={route.route}\n options={options ? (args) => {\n const staticResult = typeof staticOptions === 'function' ? staticOptions(args) : staticOptions;\n const dynamicResult = typeof options === 'function' ? options?.(args) : options;\n return {\n ...staticResult,\n ...dynamicResult,\n };\n } : staticOptions}\n component={getQualifiedRouteComponent(route)}\n />\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Directory.d.ts","sourceRoot":"","sources":["../../src/views/Directory.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"Directory.d.ts","sourceRoot":"","sources":["../../src/views/Directory.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAwE9E,wBAAgB,aAAa,IAAI,4BAA4B,CAqB5D;AAED,wBAAgB,SAAS,gBAmCxB"}
|
package/build/views/Directory.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Image, Pressable, StyleSheet, Text, View } from "@bacons/react-views";
|
|
2
|
+
import { useNavigation } from "@react-navigation/native";
|
|
2
3
|
import React from "react";
|
|
3
|
-
import { ScrollView, StatusBar, useWindowDimensions } from "react-native";
|
|
4
|
+
import { ScrollView, Platform, StatusBar, useWindowDimensions } from "react-native";
|
|
4
5
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
5
6
|
import { useRoutesContext } from "../context";
|
|
6
|
-
import { matchFragmentName } from "../matchers";
|
|
7
|
+
import { matchDeepDynamicRouteName, matchFragmentName } from "../matchers";
|
|
7
8
|
import { Link } from "./Link";
|
|
8
9
|
const INDENT = 18;
|
|
9
10
|
function useSortedRoutes() {
|
|
@@ -101,10 +102,15 @@ export function Directory() {
|
|
|
101
102
|
}
|
|
102
103
|
function FileItem({ route, level = 0, parents = [], }) {
|
|
103
104
|
const disabled = route.children.length > 0;
|
|
105
|
+
const navigation = useNavigation();
|
|
104
106
|
const href = React.useMemo(() => {
|
|
105
107
|
return ("/" +
|
|
106
108
|
[...parents, route.route]
|
|
107
109
|
.map((v) => {
|
|
110
|
+
// add an extra layer of entropy to the url for deep dynamic routes
|
|
111
|
+
if (matchDeepDynamicRouteName(v)) {
|
|
112
|
+
return v + '/' + Date.now();
|
|
113
|
+
}
|
|
108
114
|
// groups and index must be erased
|
|
109
115
|
return !!matchFragmentName(v) || v === "index" ? "" : v;
|
|
110
116
|
})
|
|
@@ -112,7 +118,14 @@ function FileItem({ route, level = 0, parents = [], }) {
|
|
|
112
118
|
.join("/"));
|
|
113
119
|
}, [parents, route.route]);
|
|
114
120
|
return (React.createElement(React.Fragment, null,
|
|
115
|
-
React.createElement(Link, { href: href,
|
|
121
|
+
React.createElement(Link, { href: href, onPress: () => {
|
|
122
|
+
if (Platform.OS !== 'web') {
|
|
123
|
+
// Ensure the modal pops
|
|
124
|
+
navigation.goBack();
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
// @ts-expect-error: disabled not on type
|
|
128
|
+
disabled: disabled, asChild: true },
|
|
116
129
|
React.createElement(Pressable, null, ({ pressed, hovered }) => (React.createElement(View, { style: [
|
|
117
130
|
styles.itemPressable,
|
|
118
131
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Directory.js","sourceRoot":"","sources":["../../src/views/Directory.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE/E,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,MAAM,MAAM,GAAG,EAAE,CAAC;AAElB,SAAS,eAAe;IACpB,MAAM,GAAG,GAAG,gBAAgB,EAAE,CAAC;IAE/B,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CACxB,GAAG,EAAE,CACD,GAAG;SACE,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC;SAClC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACX,2BAA2B;Q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, StyleSheet, Text, View } from \"@bacons/react-views\";\nimport { NativeStackNavigationOptions } from \"@react-navigation/native-stack\";\nimport React from \"react\";\nimport { ScrollView, StatusBar, useWindowDimensions } from \"react-native\";\nimport { useSafeAreaInsets } from \"react-native-safe-area-context\";\n\nimport { useRoutesContext } from \"../context\";\nimport { matchFragmentName } from \"../matchers\";\nimport { RouteNode } from \"../Route\";\nimport { Link } from \"./Link\";\n\nconst INDENT = 18;\n\nfunction useSortedRoutes() {\n const ctx = useRoutesContext();\n\n const routes = React.useMemo(\n () =>\n ctx\n .filter((route) => !route.internal)\n .sort((a, b) => {\n // Emulate vscode's sorting\n if (a.route < b.route) {\n return -1;\n }\n if (a.route > b.route) {\n return 1;\n }\n return 0;\n }),\n [ctx]\n );\n return routes;\n}\n\nconst styles = StyleSheet.create({\n container: {\n backgroundColor: \"black\",\n flex: 1,\n alignItems: \"stretch\",\n },\n main: {\n marginHorizontal: \"auto\",\n flex: 1,\n\n alignItems: \"stretch\",\n },\n scroll: {\n padding: 12,\n flex: 1,\n // paddingTop: top + 12,\n alignItems: \"stretch\",\n },\n itemContainer: {\n borderWidth: 1,\n borderColor: \"#323232\",\n borderRadius: 19,\n marginBottom: 12,\n overflow: \"hidden\",\n },\n itemPressable: {\n paddingHorizontal: INDENT,\n paddingVertical: 16,\n flexDirection: \"row\",\n justifyContent: \"space-between\",\n alignItems: \"center\",\n transitionDuration: \"100ms\",\n },\n filename: { color: \"white\", fontSize: 20, marginLeft: 12 },\n virtual: { textAlign: \"right\", color: \"white\" },\n image: { width: 24, height: 24, resizeMode: \"contain\" },\n});\n\nexport function getNavOptions(): NativeStackNavigationOptions {\n return {\n title: \"Index\",\n headerShown: true,\n presentation: \"modal\",\n animation: \"default\",\n headerLargeTitle: true,\n headerTitleStyle: {\n color: \"white\",\n },\n\n headerTintColor: \"white\",\n headerLargeTitleStyle: {\n color: \"white\",\n },\n headerStyle: {\n backgroundColor: \"black\",\n // @ts-expect-error: mistyped\n borderBottomColor: \"#323232\",\n },\n }\n}\n\nexport function Directory() {\n const routes = useSortedRoutes();\n const { bottom } = useSafeAreaInsets();\n const { width } = useWindowDimensions();\n return (\n <View style={styles.container}>\n\n <StatusBar barStyle=\"light-content\" />\n <View\n style={[\n styles.main,\n {\n minWidth: Math.min(960, width * 0.9),\n },\n ]}\n >\n <ScrollView\n contentInsetAdjustmentBehavior=\"automatic\"\n contentContainerStyle={[\n styles.scroll,\n {\n paddingBottom: bottom + 12,\n },\n ]}\n style={{ flex: 1 }}\n >\n {routes.map((child) => (\n <View key={child.contextKey} style={styles.itemContainer}>\n <FileItem route={child} />\n </View>\n ))}\n </ScrollView>\n </View>\n </View>\n );\n}\n\nfunction FileItem({\n route,\n level = 0,\n parents = [],\n}: {\n route: RouteNode;\n level?: number;\n parents?: string[];\n}) {\n const disabled = route.children.length > 0;\n\n const href = React.useMemo(() => {\n return (\n \"/\" +\n [...parents, route.route]\n .map((v) => {\n // groups and index must be erased\n return !!matchFragmentName(v) || v === \"index\" ? \"\" : v;\n })\n .filter(Boolean)\n .join(\"/\")\n );\n }, [parents, route.route]);\n\n return (\n <>\n {/* @ts-expect-error: disabled not on type */}\n <Link href={href} disabled={disabled} asChild>\n <Pressable>\n {({ pressed, hovered }) => (\n <View\n style={[\n styles.itemPressable,\n {\n paddingLeft: INDENT + level * INDENT,\n backgroundColor: hovered\n ? \"rgba(255,255,255,0.1)\"\n : \"transparent\",\n },\n pressed && { backgroundColor: \"#323232\" },\n disabled && { opacity: 0.4 },\n ]}\n >\n <View style={{ flexDirection: \"row\", alignItems: \"center\" }}>\n {route.children.length ? <PkgIcon /> : <FileIcon />}\n <Text style={styles.filename}>{route.contextKey}</Text>\n </View>\n\n {!disabled && <ForwardIcon />}\n {route.generated && <Text style={styles.virtual}>Virtual</Text>}\n </View>\n )}\n </Pressable>\n </Link>\n {route.children.map((child, index) => (\n <FileItem\n key={child.contextKey}\n route={child}\n parents={[...parents, route.route]}\n level={level + 1}\n />\n ))}\n </>\n );\n}\n\nfunction FileIcon() {\n return (\n <Image\n style={styles.image}\n source={require(\"expo-router/assets/file.png\")}\n />\n );\n}\n\nfunction PkgIcon() {\n return (\n <Image\n style={styles.image}\n source={require(\"expo-router/assets/pkg.png\")}\n />\n );\n}\n\nfunction ForwardIcon() {\n return (\n <Image\n style={styles.image}\n source={require(\"expo-router/assets/forward.png\")}\n />\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Directory.js","sourceRoot":"","sources":["../../src/views/Directory.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE3E,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,MAAM,MAAM,GAAG,EAAE,CAAC;AAElB,SAAS,eAAe;IACpB,MAAM,GAAG,GAAG,gBAAgB,EAAE,CAAC;IAE/B,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CACxB,GAAG,EAAE,CACD,GAAG;SACE,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC;SAClC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACX,2BAA2B;QAC3B,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,EAAE;YACnB,OAAO,CAAC,CAAC,CAAC;SACb;QAC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EACnB,MAAM,EAAE,OAAO,CAAC,4BAA4B,CAAC,GAC/C,CACL,CAAC;AACN,CAAC;AAED,SAAS,WAAW;IAChB,OAAO,CACH,oBAAC,KAAK,IACF,KAAK,EAAE,MAAM,CAAC,KAAK,EACnB,MAAM,EAAE,OAAO,CAAC,gCAAgC,CAAC,GACnD,CACL,CAAC;AACN,CAAC","sourcesContent":["import { Image, Pressable, StyleSheet, Text, View } from \"@bacons/react-views\";\nimport { useNavigation } from \"@react-navigation/native\";\nimport { NativeStackNavigationOptions } from \"@react-navigation/native-stack\";\nimport React from \"react\";\nimport { ScrollView, Platform, StatusBar, useWindowDimensions } from \"react-native\";\nimport { useSafeAreaInsets } from \"react-native-safe-area-context\";\n\nimport { useRoutesContext } from \"../context\";\nimport { matchDeepDynamicRouteName, matchFragmentName } from \"../matchers\";\nimport { RouteNode } from \"../Route\";\nimport { Link } from \"./Link\";\n\nconst INDENT = 18;\n\nfunction useSortedRoutes() {\n const ctx = useRoutesContext();\n\n const routes = React.useMemo(\n () =>\n ctx\n .filter((route) => !route.internal)\n .sort((a, b) => {\n // Emulate vscode's sorting\n if (a.route < b.route) {\n return -1;\n }\n if (a.route > b.route) {\n return 1;\n }\n return 0;\n }),\n [ctx]\n );\n return routes;\n}\n\nconst styles = StyleSheet.create({\n container: {\n backgroundColor: \"black\",\n flex: 1,\n alignItems: \"stretch\",\n },\n main: {\n marginHorizontal: \"auto\",\n flex: 1,\n\n alignItems: \"stretch\",\n },\n scroll: {\n padding: 12,\n flex: 1,\n // paddingTop: top + 12,\n alignItems: \"stretch\",\n },\n itemContainer: {\n borderWidth: 1,\n borderColor: \"#323232\",\n borderRadius: 19,\n marginBottom: 12,\n overflow: \"hidden\",\n },\n itemPressable: {\n paddingHorizontal: INDENT,\n paddingVertical: 16,\n flexDirection: \"row\",\n justifyContent: \"space-between\",\n alignItems: \"center\",\n transitionDuration: \"100ms\",\n },\n filename: { color: \"white\", fontSize: 20, marginLeft: 12 },\n virtual: { textAlign: \"right\", color: \"white\" },\n image: { width: 24, height: 24, resizeMode: \"contain\" },\n});\n\nexport function getNavOptions(): NativeStackNavigationOptions {\n return {\n title: \"Index\",\n headerShown: true,\n presentation: \"modal\",\n animation: \"default\",\n headerLargeTitle: true,\n headerTitleStyle: {\n color: \"white\",\n },\n\n headerTintColor: \"white\",\n headerLargeTitleStyle: {\n color: \"white\",\n },\n headerStyle: {\n backgroundColor: \"black\",\n // @ts-expect-error: mistyped\n borderBottomColor: \"#323232\",\n },\n }\n}\n\nexport function Directory() {\n const routes = useSortedRoutes();\n const { bottom } = useSafeAreaInsets();\n const { width } = useWindowDimensions();\n return (\n <View style={styles.container}>\n\n <StatusBar barStyle=\"light-content\" />\n <View\n style={[\n styles.main,\n {\n minWidth: Math.min(960, width * 0.9),\n },\n ]}\n >\n <ScrollView\n contentInsetAdjustmentBehavior=\"automatic\"\n contentContainerStyle={[\n styles.scroll,\n {\n paddingBottom: bottom + 12,\n },\n ]}\n style={{ flex: 1 }}\n >\n {routes.map((child) => (\n <View key={child.contextKey} style={styles.itemContainer}>\n <FileItem route={child} />\n </View>\n ))}\n </ScrollView>\n </View>\n </View>\n );\n}\n\nfunction FileItem({\n route,\n level = 0,\n parents = [],\n}: {\n route: RouteNode;\n level?: number;\n parents?: string[];\n}) {\n const disabled = route.children.length > 0;\n\n const navigation = useNavigation();\n const href = React.useMemo(() => {\n return (\n \"/\" +\n [...parents, route.route]\n .map((v) => {\n // add an extra layer of entropy to the url for deep dynamic routes\n if (matchDeepDynamicRouteName(v)) {\n return v + '/' + Date.now()\n }\n // groups and index must be erased\n return !!matchFragmentName(v) || v === \"index\" ? \"\" : v;\n })\n .filter(Boolean)\n .join(\"/\")\n );\n }, [parents, route.route]);\n\n return (\n <>\n <Link href={href} onPress={() => {\n if (Platform.OS !== 'web') {\n // Ensure the modal pops\n navigation.goBack();\n }\n }}\n // @ts-expect-error: disabled not on type\n disabled={disabled} asChild>\n <Pressable>\n {({ pressed, hovered }) => (\n <View\n style={[\n styles.itemPressable,\n {\n paddingLeft: INDENT + level * INDENT,\n backgroundColor: hovered\n ? \"rgba(255,255,255,0.1)\"\n : \"transparent\",\n },\n pressed && { backgroundColor: \"#323232\" },\n disabled && { opacity: 0.4 },\n ]}\n >\n <View style={{ flexDirection: \"row\", alignItems: \"center\" }}>\n {route.children.length ? <PkgIcon /> : <FileIcon />}\n <Text style={styles.filename}>{route.contextKey}</Text>\n </View>\n\n {!disabled && <ForwardIcon />}\n {route.generated && <Text style={styles.virtual}>Virtual</Text>}\n </View>\n )}\n </Pressable>\n </Link>\n {route.children.map((child, index) => (\n <FileItem\n key={child.contextKey}\n route={child}\n parents={[...parents, route.route]}\n level={level + 1}\n />\n ))}\n </>\n );\n}\n\nfunction FileIcon() {\n return (\n <Image\n style={styles.image}\n source={require(\"expo-router/assets/file.png\")}\n />\n );\n}\n\nfunction PkgIcon() {\n return (\n <Image\n style={styles.image}\n source={require(\"expo-router/assets/pkg.png\")}\n />\n );\n}\n\nfunction ForwardIcon() {\n return (\n <Image\n style={styles.image}\n source={require(\"expo-router/assets/forward.png\")}\n />\n );\n}\n"]}
|