expo-router 5.0.7 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/assets/arrow_down.png +0 -0
  2. package/build/ExpoRoot.js +1 -0
  3. package/build/ExpoRoot.js.map +1 -1
  4. package/build/exports.d.ts +1 -0
  5. package/build/exports.d.ts.map +1 -1
  6. package/build/exports.js +3 -1
  7. package/build/exports.js.map +1 -1
  8. package/build/fork/getPathFromState-forks.js +1 -4
  9. package/build/fork/getPathFromState-forks.js.map +1 -1
  10. package/build/fork/getStateFromPath-forks.d.ts +2 -0
  11. package/build/fork/getStateFromPath-forks.d.ts.map +1 -1
  12. package/build/fork/getStateFromPath-forks.js +18 -2
  13. package/build/fork/getStateFromPath-forks.js.map +1 -1
  14. package/build/getReactNavigationConfig.d.ts.map +1 -1
  15. package/build/getReactNavigationConfig.js +8 -7
  16. package/build/getReactNavigationConfig.js.map +1 -1
  17. package/build/getRoutes.d.ts +1 -1
  18. package/build/getRoutes.d.ts.map +1 -1
  19. package/build/getRoutes.js +14 -6
  20. package/build/getRoutes.js.map +1 -1
  21. package/build/getRoutesCore.d.ts +7 -2
  22. package/build/getRoutesCore.d.ts.map +1 -1
  23. package/build/getRoutesCore.js +92 -68
  24. package/build/getRoutesCore.js.map +1 -1
  25. package/build/getRoutesRedirects.d.ts +2 -2
  26. package/build/getRoutesRedirects.d.ts.map +1 -1
  27. package/build/getRoutesRedirects.js +33 -33
  28. package/build/getRoutesRedirects.js.map +1 -1
  29. package/build/getRoutesSSR.d.ts +1 -1
  30. package/build/getRoutesSSR.d.ts.map +1 -1
  31. package/build/getRoutesSSR.js +2 -3
  32. package/build/getRoutesSSR.js.map +1 -1
  33. package/build/global-state/routeInfo.d.ts.map +1 -1
  34. package/build/global-state/routeInfo.js +21 -1
  35. package/build/global-state/routeInfo.js.map +1 -1
  36. package/build/global-state/router-store.d.ts.map +1 -1
  37. package/build/global-state/router-store.js +7 -1
  38. package/build/global-state/router-store.js.map +1 -1
  39. package/build/global-state/routing.js +3 -2
  40. package/build/global-state/routing.js.map +1 -1
  41. package/build/layouts/StackClient.d.ts.map +1 -1
  42. package/build/layouts/StackClient.js +152 -65
  43. package/build/layouts/StackClient.js.map +1 -1
  44. package/build/layouts/TabsClient.d.ts +3 -1
  45. package/build/layouts/TabsClient.d.ts.map +1 -1
  46. package/build/layouts/TabsClient.js +2 -0
  47. package/build/layouts/TabsClient.js.map +1 -1
  48. package/build/link/Link.d.ts +1 -56
  49. package/build/link/Link.d.ts.map +1 -1
  50. package/build/link/Link.js +3 -39
  51. package/build/link/Link.js.map +1 -1
  52. package/build/link/Redirect.d.ts +59 -0
  53. package/build/link/Redirect.d.ts.map +1 -0
  54. package/build/link/Redirect.js +43 -0
  55. package/build/link/Redirect.js.map +1 -0
  56. package/build/matchers.d.ts +6 -3
  57. package/build/matchers.d.ts.map +1 -1
  58. package/build/matchers.js +15 -11
  59. package/build/matchers.js.map +1 -1
  60. package/build/rsc/middleware.d.ts.map +1 -1
  61. package/build/rsc/middleware.js +15 -27
  62. package/build/rsc/middleware.js.map +1 -1
  63. package/build/useFocusEffect.d.ts +2 -2
  64. package/build/useFocusEffect.d.ts.map +1 -1
  65. package/build/useFocusEffect.js +7 -5
  66. package/build/useFocusEffect.js.map +1 -1
  67. package/build/useScreens.d.ts +1 -3
  68. package/build/useScreens.d.ts.map +1 -1
  69. package/build/useScreens.js +2 -2
  70. package/build/useScreens.js.map +1 -1
  71. package/build/utils/stack.d.ts +5 -0
  72. package/build/utils/stack.d.ts.map +1 -0
  73. package/build/utils/stack.js +10 -0
  74. package/build/utils/stack.js.map +1 -0
  75. package/build/views/Navigator.d.ts.map +1 -1
  76. package/build/views/Navigator.js +5 -2
  77. package/build/views/Navigator.js.map +1 -1
  78. package/build/views/Screen.d.ts.map +1 -1
  79. package/build/views/Screen.js +13 -40
  80. package/build/views/Screen.js.map +1 -1
  81. package/build/views/Sitemap.d.ts.map +1 -1
  82. package/build/views/Sitemap.js +56 -72
  83. package/build/views/Sitemap.js.map +1 -1
  84. package/build/views/Unmatched.d.ts.map +1 -1
  85. package/build/views/Unmatched.js +9 -3
  86. package/build/views/Unmatched.js.map +1 -1
  87. package/build/views/useSafeLayoutEffect.d.ts +3 -0
  88. package/build/views/useSafeLayoutEffect.d.ts.map +1 -0
  89. package/build/views/useSafeLayoutEffect.js +6 -0
  90. package/build/views/useSafeLayoutEffect.js.map +1 -0
  91. package/build/views/useSitemap.d.ts +12 -0
  92. package/build/views/useSitemap.d.ts.map +1 -0
  93. package/build/views/useSitemap.js +50 -0
  94. package/build/views/useSitemap.js.map +1 -0
  95. package/package.json +3 -3
  96. package/plugin/options.json +29 -1
  97. package/_async-server-import.js +0 -21
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.StackRouter = exports.stackRouterOverride = void 0;
5
5
  const native_1 = require("@react-navigation/native");
6
6
  const native_stack_1 = require("@react-navigation/native-stack");
7
+ const non_secure_1 = require("nanoid/non-secure");
7
8
  const withLayoutContext_1 = require("./withLayoutContext");
8
9
  const useScreens_1 = require("../useScreens");
9
10
  const Protected_1 = require("../views/Protected");
@@ -39,7 +40,7 @@ const stackRouterOverride = (original) => {
39
40
  ? action.payload.singular
40
41
  : undefined;
41
42
  // Handle if 'getID' or 'singular' is set.
42
- function getIdFunction(fn) {
43
+ function getIdFunction() {
43
44
  // Actions can be fired by the user, so we do need to validate their structure.
44
45
  if (!('payload' in action) ||
45
46
  !action.payload ||
@@ -47,68 +48,158 @@ const stackRouterOverride = (original) => {
47
48
  typeof action.payload.name !== 'string') {
48
49
  return;
49
50
  }
50
- const name = action.payload.name;
51
+ const actionName = action.payload.name;
51
52
  return (
52
53
  // The dynamic singular added to an action, `router.push('screen', { singular: () => 'id' })`
53
- getActionSingularIdFn(actionSingularOptions, name) ||
54
+ getActionSingularIdFn(actionSingularOptions, actionName) ||
54
55
  // The static getId added as a prop to `<Screen singular />` or `<Screen getId={} />`
55
- options.routeGetIdList[name] ||
56
- // The custom singular added by Expo Router to support its concept of `navigate`
57
- fn);
56
+ options.routeGetIdList[actionName]);
58
57
  }
58
+ const { routeParamList } = options;
59
59
  switch (action.type) {
60
- case 'PUSH': {
61
- /**
62
- * PUSH should always push
63
- *
64
- * If 'getID' or 'singular' is set and a match is found, instead of pushing a new screen,
65
- * the existing screen will be moved to the HEAD of the stack. If there are multiple matches, the rest will be removed.
66
- */
67
- const nextState = original.getStateForAction(state, action, {
68
- ...options,
69
- routeGetIdList: {
70
- ...options.routeGetIdList,
71
- [action.payload.name]: getIdFunction(),
72
- },
73
- });
74
- /**
75
- * React Navigation doesn't support dynamic getId function on the action. Because of this,
76
- * can you enter a state where the screen is pushed multiple times but the normal getStateForAction
77
- * doesn't remove the duplicates. We need to filter the state to only have singular screens.
78
- */
79
- return actionSingularOptions
80
- ? filterSingular(nextState, actionSingularOptions)
81
- : nextState;
82
- }
60
+ case 'PUSH':
83
61
  case 'NAVIGATE': {
84
- /**
85
- * NAVIGATE should push unless the current name & route params of the current and target screen match.
86
- * Search params and hashes should be ignored.
87
- *
88
- * If the name, route params & search params match, no action is taken.
89
- * If both the name and route params match, the screen is replaced.
90
- * If the name / route params do not match, the screen is pushed.
91
- *
92
- * If 'getID' or 'singular' is set and a match is found, instead of pushing a new screen,
93
- * the existing screen will be moved to the HEAD of the stack. If there are multiple matches, the rest will be removed.
94
- */
95
- const nextState = original.getStateForAction(state, action, {
96
- ...options,
97
- routeGetIdList: {
98
- ...options.routeGetIdList,
99
- [action.payload.name]: getIdFunction((options) => {
100
- return (0, useScreens_1.getSingularId)(action.payload.name, options);
101
- }),
102
- },
103
- });
104
- /**
105
- * React Navigation doesn't support dynamic getId function on the action. Because of this,
106
- * can you enter a state where the screen is pushed multiple times but the normal getStateForAction
107
- * doesn't remove the duplicates. We need to filter the state to only have singular screens.
108
- */
109
- return actionSingularOptions
110
- ? filterSingular(nextState, actionSingularOptions)
111
- : nextState;
62
+ if (!state.routeNames.includes(action.payload.name)) {
63
+ return null;
64
+ }
65
+ // START FORK
66
+ const getId = getIdFunction();
67
+ // const getId = options.routeGetIdList[action.payload.name];
68
+ // END FORK
69
+ const id = getId?.({ params: action.payload.params });
70
+ let route;
71
+ if (id !== undefined) {
72
+ route = state.routes.findLast((route) => route.name === action.payload.name && id === getId?.({ params: route.params }));
73
+ }
74
+ else if (action.type === 'NAVIGATE') {
75
+ const currentRoute = state.routes[state.index];
76
+ // If the route matches the current one, then navigate to it
77
+ if (action.payload.name === currentRoute.name) {
78
+ route = currentRoute;
79
+ }
80
+ else if (action.payload.pop) {
81
+ route = state.routes.findLast((route) => route.name === action.payload.name);
82
+ }
83
+ }
84
+ if (!route) {
85
+ route = state.preloadedRoutes.find((route) => route.name === action.payload.name && id === getId?.({ params: route.params }));
86
+ }
87
+ let params;
88
+ if (action.type === 'NAVIGATE' && action.payload.merge && route) {
89
+ params =
90
+ action.payload.params !== undefined ||
91
+ routeParamList[action.payload.name] !== undefined
92
+ ? {
93
+ ...routeParamList[action.payload.name],
94
+ ...route.params,
95
+ ...action.payload.params,
96
+ }
97
+ : route.params;
98
+ }
99
+ else {
100
+ params =
101
+ routeParamList[action.payload.name] !== undefined
102
+ ? {
103
+ ...routeParamList[action.payload.name],
104
+ ...action.payload.params,
105
+ }
106
+ : action.payload.params;
107
+ }
108
+ let routes;
109
+ if (route) {
110
+ if (action.type === 'NAVIGATE' && action.payload.pop) {
111
+ routes = [];
112
+ // Get all routes until the matching one
113
+ for (const r of state.routes) {
114
+ if (r.key === route.key) {
115
+ routes.push({
116
+ ...route,
117
+ path: action.payload.path !== undefined ? action.payload.path : route.path,
118
+ params,
119
+ });
120
+ break;
121
+ }
122
+ routes.push(r);
123
+ }
124
+ }
125
+ else {
126
+ // START FORK
127
+ // If there is an id, then filter out the existing route with the same id.
128
+ // THIS ACTION IS DANGEROUS. This can cause React Native Screens to freeze
129
+ if (id !== undefined) {
130
+ routes = state.routes.filter((r) => r.key !== route.key);
131
+ }
132
+ else if (action.type === 'NAVIGATE' && state.routes.length > 0) {
133
+ // The navigation action should only replace the last route if it has the same name and path params.
134
+ const lastRoute = state.routes[state.routes.length - 1];
135
+ if ((0, useScreens_1.getSingularId)(lastRoute.name, { params: lastRoute.params }) ===
136
+ (0, useScreens_1.getSingularId)(route.name, { params })) {
137
+ routes = state.routes.slice(0, -1);
138
+ }
139
+ else {
140
+ routes = [...state.routes];
141
+ }
142
+ }
143
+ else {
144
+ routes = [...state.routes];
145
+ }
146
+ // If the routes length is the same as the state routes length, then we are navigating to a new route.
147
+ // Otherwise we are replacing an existing route.
148
+ const key = routes.length === state.routes.length
149
+ ? `${action.payload.name}-${(0, non_secure_1.nanoid)()}`
150
+ : route.key;
151
+ routes.push({
152
+ ...route,
153
+ key,
154
+ path: action.type === 'NAVIGATE' && action.payload.path !== undefined
155
+ ? action.payload.path
156
+ : route.path,
157
+ params,
158
+ });
159
+ // routes = state.routes.filter((r) => r.key !== route.key);
160
+ // routes.push({
161
+ // ...route,
162
+ // path:
163
+ // action.type === 'NAVIGATE' && action.payload.path !== undefined
164
+ // ? action.payload.path
165
+ // : route.path,
166
+ // params,
167
+ // });
168
+ // END FORK
169
+ }
170
+ }
171
+ else {
172
+ routes = [
173
+ ...state.routes,
174
+ {
175
+ key: `${action.payload.name}-${(0, non_secure_1.nanoid)()}`,
176
+ name: action.payload.name,
177
+ path: action.type === 'NAVIGATE' ? action.payload.path : undefined,
178
+ params,
179
+ },
180
+ ];
181
+ }
182
+ // START FORK
183
+ // return filterSingular(
184
+ const result = {
185
+ ...state,
186
+ index: routes.length - 1,
187
+ preloadedRoutes: state.preloadedRoutes.filter((route) => routes[routes.length - 1].key !== route.key),
188
+ routes,
189
+ };
190
+ if (actionSingularOptions) {
191
+ return filterSingular(result, getId);
192
+ }
193
+ return result;
194
+ // return {
195
+ // ...state,
196
+ // index: routes.length - 1,
197
+ // preloadedRoutes: state.preloadedRoutes.filter(
198
+ // (route) => routes[routes.length - 1].key !== route.key
199
+ // ),
200
+ // routes,
201
+ // };
202
+ // END FORK
112
203
  }
113
204
  default: {
114
205
  return original.getStateForAction(state, action, options);
@@ -131,8 +222,8 @@ function getActionSingularIdFn(actionGetId, name) {
131
222
  * If there is a dynamic singular on an action, then we need to filter the state to only have singular screens.
132
223
  * As multiples may have been added before we did the singular navigation.
133
224
  */
134
- function filterSingular(state, singular) {
135
- if (!state || !singular) {
225
+ function filterSingular(state, getId) {
226
+ if (!state) {
136
227
  return state;
137
228
  }
138
229
  if (!state.routes) {
@@ -141,11 +232,7 @@ function filterSingular(state, singular) {
141
232
  const currentIndex = state.index || state.routes.length - 1;
142
233
  const current = state.routes[currentIndex];
143
234
  const name = current.name;
144
- const getId = getActionSingularIdFn(singular, name);
145
- if (!getId) {
146
- return state;
147
- }
148
- const id = getId({ params: current.params });
235
+ const id = getId?.({ params: current.params });
149
236
  if (!id) {
150
237
  return state;
151
238
  }
@@ -157,7 +244,7 @@ function filterSingular(state, singular) {
157
244
  return true;
158
245
  }
159
246
  // Remove all other routes with the same name and id.
160
- return name !== route.name || id !== getId({ params: route.params });
247
+ return name !== route.name || id !== getId?.({ params: route.params });
161
248
  });
162
249
  return {
163
250
  ...state,
@@ -1 +1 @@
1
- {"version":3,"file":"StackClient.js","sourceRoot":"","sources":["../../src/layouts/StackClient.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;AACb,qDAWkC;AAClC,iEAIwC;AAGxC,2DAAwD;AACxD,8CAA+D;AAC/D,kDAA+C;AAI/C,MAAM,oBAAoB,GAAG,IAAA,yCAA0B,GAAE,CAAC,SAAS,CAAC;AAEpE,MAAM,OAAO,GAAG,IAAA,qCAAiB,EAK/B,oBAAoB,CAAC,CAAC;AAExB,SAAS,aAAa,CACpB,MAAwB;IAExB,OAAO,CACL,MAAM,CAAC,IAAI,KAAK,MAAM;QACtB,MAAM,CAAC,IAAI,KAAK,UAAU;QAC1B,MAAM,CAAC,IAAI,KAAK,KAAK;QACrB,MAAM,C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/E,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACtC,8CAA8C;QAC9C,IAAI,KAAK,KAAK,YAAY,EAAE,CAAC;YAC3B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,qDAAqD;QACrD,OAAO,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,EAAE,KAAK,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,KAAK;QACR,KAAK,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC;QACxB,MAAM;KACP,CAAC;AACJ,CAAC;AAED,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CACzB,CAAC,KAAqC,EAAE,EAAE;IACxC,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,eAAe,CAAC,CAAC,2BAAmB,CAAC,EAAG,CAAC;AACtE,CAAC,EACD;IACE,MAAM,EAAE,OAAO,CAAC,MAEP;IACT,SAAS,EAAT,qBAAS;CACV,CACF,CAAC;AAEF,kBAAe,KAAK,CAAC;AAEd,MAAM,WAAW,GAAyB,CAAC,OAAO,EAAE,EAAE;IAC3D,MAAM,MAAM,GAAG,IAAA,oBAAa,EAAC,OAAO,CAAC,CAAC;IACtC,OAAO;QACL,GAAG,MAAM;QACT,GAAG,IAAA,2BAAmB,EAAC,MAAM,CAAC;KAC/B,CAAC;AACJ,CAAC,CAAC;AANW,QAAA,WAAW,eAMtB","sourcesContent":["'use client';\nimport {\n CommonNavigationAction,\n NavigationAction,\n ParamListBase,\n PartialRoute,\n PartialState,\n Route,\n RouterConfigOptions,\n StackRouter as RNStackRouter,\n StackActionType,\n StackNavigationState,\n} from '@react-navigation/native';\nimport {\n NativeStackNavigationEventMap,\n NativeStackNavigationOptions,\n createNativeStackNavigator,\n} from '@react-navigation/native-stack';\nimport { ComponentProps } from 'react';\n\nimport { withLayoutContext } from './withLayoutContext';\nimport { SingularOptions, getSingularId } from '../useScreens';\nimport { Protected } from '../views/Protected';\n\ntype GetId = NonNullable<RouterConfigOptions['routeGetIdList'][string]>;\n\nconst NativeStackNavigator = createNativeStackNavigator().Navigator;\n\nconst RNStack = withLayoutContext<\n NativeStackNavigationOptions,\n typeof NativeStackNavigator,\n StackNavigationState<ParamListBase>,\n NativeStackNavigationEventMap\n>(NativeStackNavigator);\n\nfunction isStackAction(\n action: NavigationAction\n): action is StackActionType | Extract<CommonNavigationAction, { type: 'NAVIGATE' }> {\n return (\n action.type === 'PUSH' ||\n action.type === 'NAVIGATE' ||\n action.type === 'POP' ||\n action.type === 'POP_TO_TOP' ||\n action.type === 'REPLACE'\n );\n}\n\n/**\n * React Navigation matches a screen by its name or a 'getID' function that uniquely identifies a screen.\n * When a screen has been uniquely identified, the Stack can only have one instance of that screen.\n *\n * Expo Router allows for a screen to be matched by name and path params, a 'getID' function or a singular id.\n *\n * Instead of reimplementing the entire StackRouter, we can override the getStateForAction method to handle the singular screen logic.\n *\n */\nexport const stackRouterOverride: NonNullable<ComponentProps<typeof RNStack>['UNSTABLE_router']> = (\n original\n) => {\n return {\n getStateForAction: (state, action, options) => {\n if (action.target && action.target !== state.key) {\n return null;\n }\n\n if (!isStackAction(action)) {\n return original.getStateForAction(state, action, options);\n }\n\n // The dynamic getId added to an action, `router.push('screen', { singular: true })`\n const actionSingularOptions =\n action.payload && 'singular' in action.payload\n ? (action.payload.singular as SingularOptions)\n : undefined;\n\n // Handle if 'getID' or 'singular' is set.\n function getIdFunction(fn?: GetId): GetId | undefined {\n // Actions can be fired by the user, so we do need to validate their structure.\n if (\n !('payload' in action) ||\n !action.payload ||\n !('name' in action.payload) ||\n typeof action.payload.name !== 'string'\n ) {\n return;\n }\n\n const name = action.payload.name;\n\n return (\n // The dynamic singular added to an action, `router.push('screen', { singular: () => 'id' })`\n getActionSingularIdFn(actionSingularOptions, name) ||\n // The static getId added as a prop to `<Screen singular />` or `<Screen getId={} />`\n options.routeGetIdList[name] ||\n // The custom singular added by Expo Router to support its concept of `navigate`\n fn\n );\n }\n\n switch (action.type) {\n case 'PUSH': {\n /**\n * PUSH should always push\n *\n * If 'getID' or 'singular' is set and a match is found, instead of pushing a new screen,\n * the existing screen will be moved to the HEAD of the stack. If there are multiple matches, the rest will be removed.\n */\n const nextState = original.getStateForAction(state, action, {\n ...options,\n routeGetIdList: {\n ...options.routeGetIdList,\n [action.payload.name]: getIdFunction(),\n },\n });\n\n /**\n * React Navigation doesn't support dynamic getId function on the action. Because of this,\n * can you enter a state where the screen is pushed multiple times but the normal getStateForAction\n * doesn't remove the duplicates. We need to filter the state to only have singular screens.\n */\n return actionSingularOptions\n ? filterSingular(nextState, actionSingularOptions)\n : nextState;\n }\n case 'NAVIGATE': {\n /**\n * NAVIGATE should push unless the current name & route params of the current and target screen match.\n * Search params and hashes should be ignored.\n *\n * If the name, route params & search params match, no action is taken.\n * If both the name and route params match, the screen is replaced.\n * If the name / route params do not match, the screen is pushed.\n *\n * If 'getID' or 'singular' is set and a match is found, instead of pushing a new screen,\n * the existing screen will be moved to the HEAD of the stack. If there are multiple matches, the rest will be removed.\n */\n const nextState = original.getStateForAction(state, action, {\n ...options,\n routeGetIdList: {\n ...options.routeGetIdList,\n [action.payload.name]: getIdFunction((options) => {\n return getSingularId(action.payload.name, options);\n }),\n },\n });\n\n /**\n * React Navigation doesn't support dynamic getId function on the action. Because of this,\n * can you enter a state where the screen is pushed multiple times but the normal getStateForAction\n * doesn't remove the duplicates. We need to filter the state to only have singular screens.\n */\n return actionSingularOptions\n ? filterSingular(nextState, actionSingularOptions)\n : nextState;\n }\n default: {\n return original.getStateForAction(state, action, options);\n }\n }\n },\n };\n};\n\nfunction getActionSingularIdFn(\n actionGetId: SingularOptions | undefined,\n name: string\n): GetId | undefined {\n if (typeof actionGetId === 'function') {\n return (options) => actionGetId(name, options.params ?? {});\n } else if (actionGetId === true) {\n return (options) => getSingularId(name, options);\n }\n\n return undefined;\n}\n\n/**\n * If there is a dynamic singular on an action, then we need to filter the state to only have singular screens.\n * As multiples may have been added before we did the singular navigation.\n */\nfunction filterSingular<\n T extends\n | StackNavigationState<ParamListBase>\n | PartialState<StackNavigationState<ParamListBase>>\n | null,\n>(state: T, singular: SingularOptions): T {\n if (!state || !singular) {\n return state;\n }\n\n if (!state.routes) {\n return state;\n }\n\n const currentIndex = state.index || state.routes.length - 1;\n const current = state.routes[currentIndex];\n const name = current.name;\n\n const getId = getActionSingularIdFn(singular, name);\n\n if (!getId) {\n return state;\n }\n\n const id = getId({ params: current.params });\n\n if (!id) {\n return state;\n }\n\n // TypeScript needs a type assertion here for the filter to work.\n let routes = state.routes as PartialRoute<Route<string, object | undefined>>[];\n routes = routes.filter((route, index) => {\n // If the route is the current route, keep it.\n if (index === currentIndex) {\n return true;\n }\n\n // Remove all other routes with the same name and id.\n return name !== route.name || id !== getId({ params: route.params });\n });\n\n return {\n ...state,\n index: routes.length - 1,\n routes,\n };\n}\n\nconst Stack = Object.assign(\n (props: ComponentProps<typeof RNStack>) => {\n return <RNStack {...props} UNSTABLE_router={stackRouterOverride} />;\n },\n {\n Screen: RNStack.Screen as (\n props: ComponentProps<typeof RNStack.Screen> & { singular?: boolean }\n ) => null,\n Protected,\n }\n);\n\nexport default Stack;\n\nexport const StackRouter: typeof RNStackRouter = (options) => {\n const router = RNStackRouter(options);\n return {\n ...router,\n ...stackRouterOverride(router),\n };\n};\n"]}
1
+ {"version":3,"file":"StackClient.js","sourceRoot":"","sources":["../../src/layouts/StackClient.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;AACb,qDAWkC;AAClC,iEAIwC;AACxC,kDAA2C;AAG3C,2DAAwD;AACxD,8CAA+D;AAC/D,kDAA+C;AAI/C,MAAM,oBAAoB,GAAG,IAAA,yCAA0B,GAAE,CAAC,SAAS,CAAC;AAEpE,MAAM,OAAO,GAAG,IAAA,qCAAiB,EAK/B,oBAAoB,CAAC,CAAC;AAExB,SAA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GAAG,CAAC;QACxB,MAAM;KACP,CAAC;AACJ,CAAC;AAED,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CACzB,CAAC,KAAqC,EAAE,EAAE;IACxC,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,eAAe,CAAC,CAAC,2BAAmB,CAAC,EAAG,CAAC;AACtE,CAAC,EACD;IACE,MAAM,EAAE,OAAO,CAAC,MAEP;IACT,SAAS,EAAT,qBAAS;CACV,CACF,CAAC;AAEF,kBAAe,KAAK,CAAC;AAEd,MAAM,WAAW,GAAyB,CAAC,OAAO,EAAE,EAAE;IAC3D,MAAM,MAAM,GAAG,IAAA,oBAAa,EAAC,OAAO,CAAC,CAAC;IACtC,OAAO;QACL,GAAG,MAAM;QACT,GAAG,IAAA,2BAAmB,EAAC,MAAM,CAAC;KAC/B,CAAC;AACJ,CAAC,CAAC;AANW,QAAA,WAAW,eAMtB","sourcesContent":["'use client';\nimport {\n CommonNavigationAction,\n NavigationAction,\n ParamListBase,\n PartialRoute,\n PartialState,\n Route,\n RouterConfigOptions,\n StackRouter as RNStackRouter,\n StackActionType,\n StackNavigationState,\n} from '@react-navigation/native';\nimport {\n NativeStackNavigationEventMap,\n NativeStackNavigationOptions,\n createNativeStackNavigator,\n} from '@react-navigation/native-stack';\nimport { nanoid } from 'nanoid/non-secure';\nimport { ComponentProps } from 'react';\n\nimport { withLayoutContext } from './withLayoutContext';\nimport { SingularOptions, getSingularId } from '../useScreens';\nimport { Protected } from '../views/Protected';\n\ntype GetId = NonNullable<RouterConfigOptions['routeGetIdList'][string]>;\n\nconst NativeStackNavigator = createNativeStackNavigator().Navigator;\n\nconst RNStack = withLayoutContext<\n NativeStackNavigationOptions,\n typeof NativeStackNavigator,\n StackNavigationState<ParamListBase>,\n NativeStackNavigationEventMap\n>(NativeStackNavigator);\n\nfunction isStackAction(\n action: NavigationAction\n): action is StackActionType | Extract<CommonNavigationAction, { type: 'NAVIGATE' }> {\n return (\n action.type === 'PUSH' ||\n action.type === 'NAVIGATE' ||\n action.type === 'POP' ||\n action.type === 'POP_TO_TOP' ||\n action.type === 'REPLACE'\n );\n}\n\n/**\n * React Navigation matches a screen by its name or a 'getID' function that uniquely identifies a screen.\n * When a screen has been uniquely identified, the Stack can only have one instance of that screen.\n *\n * Expo Router allows for a screen to be matched by name and path params, a 'getID' function or a singular id.\n *\n * Instead of reimplementing the entire StackRouter, we can override the getStateForAction method to handle the singular screen logic.\n *\n */\nexport const stackRouterOverride: NonNullable<ComponentProps<typeof RNStack>['UNSTABLE_router']> = (\n original\n) => {\n return {\n getStateForAction: (state, action, options) => {\n if (action.target && action.target !== state.key) {\n return null;\n }\n\n if (!isStackAction(action)) {\n return original.getStateForAction(state, action, options);\n }\n\n // The dynamic getId added to an action, `router.push('screen', { singular: true })`\n const actionSingularOptions =\n action.payload && 'singular' in action.payload\n ? (action.payload.singular as SingularOptions)\n : undefined;\n\n // Handle if 'getID' or 'singular' is set.\n function getIdFunction(): GetId | undefined {\n // Actions can be fired by the user, so we do need to validate their structure.\n if (\n !('payload' in action) ||\n !action.payload ||\n !('name' in action.payload) ||\n typeof action.payload.name !== 'string'\n ) {\n return;\n }\n\n const actionName = action.payload.name;\n\n return (\n // The dynamic singular added to an action, `router.push('screen', { singular: () => 'id' })`\n getActionSingularIdFn(actionSingularOptions, actionName) ||\n // The static getId added as a prop to `<Screen singular />` or `<Screen getId={} />`\n options.routeGetIdList[actionName]\n );\n }\n\n const { routeParamList } = options;\n\n switch (action.type) {\n case 'PUSH':\n case 'NAVIGATE': {\n if (!state.routeNames.includes(action.payload.name)) {\n return null;\n }\n\n // START FORK\n const getId = getIdFunction();\n // const getId = options.routeGetIdList[action.payload.name];\n // END FORK\n const id = getId?.({ params: action.payload.params });\n\n let route: Route<string> | undefined;\n\n if (id !== undefined) {\n route = state.routes.findLast(\n (route) =>\n route.name === action.payload.name && id === getId?.({ params: route.params })\n );\n } else if (action.type === 'NAVIGATE') {\n const currentRoute = state.routes[state.index];\n\n // If the route matches the current one, then navigate to it\n if (action.payload.name === currentRoute.name) {\n route = currentRoute;\n } else if (action.payload.pop) {\n route = state.routes.findLast((route) => route.name === action.payload.name);\n }\n }\n\n if (!route) {\n route = state.preloadedRoutes.find(\n (route) =>\n route.name === action.payload.name && id === getId?.({ params: route.params })\n );\n }\n\n let params;\n\n if (action.type === 'NAVIGATE' && action.payload.merge && route) {\n params =\n action.payload.params !== undefined ||\n routeParamList[action.payload.name] !== undefined\n ? {\n ...routeParamList[action.payload.name],\n ...route.params,\n ...action.payload.params,\n }\n : route.params;\n } else {\n params =\n routeParamList[action.payload.name] !== undefined\n ? {\n ...routeParamList[action.payload.name],\n ...action.payload.params,\n }\n : action.payload.params;\n }\n\n let routes: Route<string>[];\n\n if (route) {\n if (action.type === 'NAVIGATE' && action.payload.pop) {\n routes = [];\n\n // Get all routes until the matching one\n for (const r of state.routes) {\n if (r.key === route.key) {\n routes.push({\n ...route,\n path: action.payload.path !== undefined ? action.payload.path : route.path,\n params,\n });\n break;\n }\n\n routes.push(r);\n }\n } else {\n // START FORK\n // If there is an id, then filter out the existing route with the same id.\n // THIS ACTION IS DANGEROUS. This can cause React Native Screens to freeze\n if (id !== undefined) {\n routes = state.routes.filter((r) => r.key !== route.key);\n } else if (action.type === 'NAVIGATE' && state.routes.length > 0) {\n // The navigation action should only replace the last route if it has the same name and path params.\n const lastRoute = state.routes[state.routes.length - 1];\n if (\n getSingularId(lastRoute.name, { params: lastRoute.params }) ===\n getSingularId(route.name, { params })\n ) {\n routes = state.routes.slice(0, -1);\n } else {\n routes = [...state.routes];\n }\n } else {\n routes = [...state.routes];\n }\n\n // If the routes length is the same as the state routes length, then we are navigating to a new route.\n // Otherwise we are replacing an existing route.\n const key =\n routes.length === state.routes.length\n ? `${action.payload.name}-${nanoid()}`\n : route.key;\n\n routes.push({\n ...route,\n key,\n path:\n action.type === 'NAVIGATE' && action.payload.path !== undefined\n ? action.payload.path\n : route.path,\n params,\n });\n\n // routes = state.routes.filter((r) => r.key !== route.key);\n // routes.push({\n // ...route,\n // path:\n // action.type === 'NAVIGATE' && action.payload.path !== undefined\n // ? action.payload.path\n // : route.path,\n // params,\n // });\n // END FORK\n }\n } else {\n routes = [\n ...state.routes,\n {\n key: `${action.payload.name}-${nanoid()}`,\n name: action.payload.name,\n path: action.type === 'NAVIGATE' ? action.payload.path : undefined,\n params,\n },\n ];\n }\n\n // START FORK\n // return filterSingular(\n const result = {\n ...state,\n index: routes.length - 1,\n preloadedRoutes: state.preloadedRoutes.filter(\n (route) => routes[routes.length - 1].key !== route.key\n ),\n routes,\n };\n\n if (actionSingularOptions) {\n return filterSingular(result, getId);\n }\n\n return result;\n // return {\n // ...state,\n // index: routes.length - 1,\n // preloadedRoutes: state.preloadedRoutes.filter(\n // (route) => routes[routes.length - 1].key !== route.key\n // ),\n // routes,\n // };\n // END FORK\n }\n default: {\n return original.getStateForAction(state, action, options);\n }\n }\n },\n };\n};\n\nfunction getActionSingularIdFn(\n actionGetId: SingularOptions | undefined,\n name: string\n): GetId | undefined {\n if (typeof actionGetId === 'function') {\n return (options) => actionGetId(name, options.params ?? {});\n } else if (actionGetId === true) {\n return (options) => getSingularId(name, options);\n }\n\n return undefined;\n}\n\n/**\n * If there is a dynamic singular on an action, then we need to filter the state to only have singular screens.\n * As multiples may have been added before we did the singular navigation.\n */\nfunction filterSingular<\n T extends\n | StackNavigationState<ParamListBase>\n | PartialState<StackNavigationState<ParamListBase>>\n | null,\n>(state: T, getId?: GetId): T {\n if (!state) {\n return state;\n }\n\n if (!state.routes) {\n return state;\n }\n\n const currentIndex = state.index || state.routes.length - 1;\n const current = state.routes[currentIndex];\n const name = current.name;\n\n const id = getId?.({ params: current.params });\n\n if (!id) {\n return state;\n }\n\n // TypeScript needs a type assertion here for the filter to work.\n let routes = state.routes as PartialRoute<Route<string, object | undefined>>[];\n routes = routes.filter((route, index) => {\n // If the route is the current route, keep it.\n if (index === currentIndex) {\n return true;\n }\n\n // Remove all other routes with the same name and id.\n return name !== route.name || id !== getId?.({ params: route.params });\n });\n\n return {\n ...state,\n index: routes.length - 1,\n routes,\n };\n}\n\nconst Stack = Object.assign(\n (props: ComponentProps<typeof RNStack>) => {\n return <RNStack {...props} UNSTABLE_router={stackRouterOverride} />;\n },\n {\n Screen: RNStack.Screen as (\n props: ComponentProps<typeof RNStack.Screen> & { singular?: boolean }\n ) => null,\n Protected,\n }\n);\n\nexport default Stack;\n\nexport const StackRouter: typeof RNStackRouter = (options) => {\n const router = RNStackRouter(options);\n return {\n ...router,\n ...stackRouterOverride(router),\n };\n};\n"]}
@@ -2,6 +2,7 @@ import { BottomTabNavigationEventMap, BottomTabNavigationOptions } from '@react-
2
2
  import { ParamListBase, TabNavigationState } from '@react-navigation/native';
3
3
  import React, { ComponentProps } from 'react';
4
4
  import { Href } from '../types';
5
+ import { Protected } from '../views/Protected';
5
6
  declare const BottomTabNavigator: React.ComponentType<Omit<import("@react-navigation/bottom-tabs").BottomTabNavigatorProps, "children" | "layout" | "initialRouteName" | "id" | "screenListeners" | "screenOptions" | "screenLayout" | "UNSTABLE_router"> & import("@react-navigation/native").DefaultRouterOptions<string> & {
6
7
  children: React.ReactNode;
7
8
  layout?: ((props: {
@@ -156,10 +157,11 @@ declare const ExpoTabs: React.ForwardRefExoticComponent<Omit<Omit<import("@react
156
157
  id?: undefined;
157
158
  }, "children">> & React.RefAttributes<unknown>> & {
158
159
  Screen: (props: import("..").ScreenProps<TabsProps, TabNavigationState<ParamListBase>, BottomTabNavigationEventMap>) => null;
159
- Protected: typeof import("../views/Protected").Protected;
160
+ Protected: typeof Protected;
160
161
  };
161
162
  declare const Tabs: ((props: ComponentProps<typeof ExpoTabs>) => React.JSX.Element) & {
162
163
  Screen: (props: import("..").ScreenProps<TabsProps, TabNavigationState<ParamListBase>, BottomTabNavigationEventMap>) => null;
164
+ Protected: React.FunctionComponent<import("../views/Protected").ProtectedProps>;
163
165
  };
164
166
  export default Tabs;
165
167
  //# sourceMappingURL=TabsClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TabsClient.d.ts","sourceRoot":"","sources":["../../src/layouts/TabsClient.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,2BAA2B,EAC3B,0BAA0B,EAE3B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,KAAK,EAAE,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAK9C,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAIhC,QAAA,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAuC,CAAC;AAEhE,MAAM,MAAM,kBAAkB,GAAG,OAAO,kBAAkB,CAAC;AAE3D,KAAK,SAAS,GAAG,0BAA0B,GAAG;IAAE,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;CAAE,CAAC;AAErE,QAAA,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0CZ,CAAC;AAEH,QAAA,MAAM,IAAI,WACA,cAAc,CAAC,OAAO,QAAQ,CAAC;;CAMxC,CAAC;AAEF,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"TabsClient.d.ts","sourceRoot":"","sources":["../../src/layouts/TabsClient.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,2BAA2B,EAC3B,0BAA0B,EAE3B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,KAAK,EAAE,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAK9C,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG/C,QAAA,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAuC,CAAC;AAEhE,MAAM,MAAM,kBAAkB,GAAG,OAAO,kBAAkB,CAAC;AAE3D,KAAK,SAAS,GAAG,0BAA0B,GAAG;IAAE,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;CAAE,CAAC;AAErE,QAAA,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0CZ,CAAC;AAEH,QAAA,MAAM,IAAI,WACA,cAAc,CAAC,OAAO,QAAQ,CAAC;;;CAOxC,CAAC;AAEF,eAAe,IAAI,CAAC"}
@@ -10,6 +10,7 @@ const react_native_1 = require("react-native");
10
10
  const withLayoutContext_1 = require("./withLayoutContext");
11
11
  const Link_1 = require("../link/Link");
12
12
  const TabRouter_1 = require("./TabRouter");
13
+ const Protected_1 = require("../views/Protected");
13
14
  // This is the only way to access the navigator.
14
15
  const BottomTabNavigator = (0, bottom_tabs_1.createBottomTabNavigator)().Navigator;
15
16
  const ExpoTabs = (0, withLayoutContext_1.withLayoutContext)(BottomTabNavigator, (screens) => {
@@ -45,6 +46,7 @@ const Tabs = Object.assign((props) => {
45
46
  return <ExpoTabs {...props} UNSTABLE_router={TabRouter_1.tabRouterOverride}/>;
46
47
  }, {
47
48
  Screen: ExpoTabs.Screen,
49
+ Protected: Protected_1.Protected,
48
50
  });
49
51
  exports.default = Tabs;
50
52
  //# sourceMappingURL=TabsClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TabsClient.js","sourceRoot":"","sources":["../../src/layouts/TabsClient.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;AAEb,+DAIuC;AAEvC,kDAA8C;AAC9C,+CAAmD;AAEnD,2DAAwD;AACxD,uCAAoC;AAEpC,2C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AAC,CAAC,CACjD,IAAI,CAAC,CAAC,IAAI,CAAC,CACX,OAAO,CAAC,CAAC,uBAAQ,CAAC,EAAE,KAAK,KAAK,CAAC,CAC/B,QAAQ,CAAC,CAAC,QAAQ,CAAC,EACnB,CACH,CAAC;oBACJ,CAAC;iBACF;aACF,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CACxB,CAAC,KAAsC,EAAE,EAAE;IACzC,OAAO,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,CAAC,eAAe,CAAC,CAAC,6BAAiB,CAAC,EAAG,CAAC;AACrE,CAAC,EACD;IACE,MAAM,EAAE,QAAQ,CAAC,MAAM;CACxB,CACF,CAAC;AAEF,kBAAe,IAAI,CAAC","sourcesContent":["'use client';\n\nimport {\n BottomTabNavigationEventMap,\n BottomTabNavigationOptions,\n createBottomTabNavigator,\n} from '@react-navigation/bottom-tabs';\nimport { ParamListBase, TabNavigationState } from '@react-navigation/native';\nimport React, { ComponentProps } from 'react';\nimport { Pressable, Platform } from 'react-native';\n\nimport { withLayoutContext } from './withLayoutContext';\nimport { Link } from '../link/Link';\nimport { Href } from '../types';\nimport { tabRouterOverride } from './TabRouter';\n\n// This is the only way to access the navigator.\nconst BottomTabNavigator = createBottomTabNavigator().Navigator;\n\nexport type BottomTabNavigator = typeof BottomTabNavigator;\n\ntype TabsProps = BottomTabNavigationOptions & { href?: Href | null };\n\nconst ExpoTabs = withLayoutContext<\n TabsProps,\n typeof BottomTabNavigator,\n TabNavigationState<ParamListBase>,\n BottomTabNavigationEventMap\n>(BottomTabNavigator, (screens) => {\n // Support the `href` shortcut prop.\n return screens.map((screen) => {\n if (typeof screen.options !== 'function' && screen.options?.href !== undefined) {\n const { href, ...options } = screen.options;\n if (options.tabBarButton) {\n throw new Error('Cannot use `href` and `tabBarButton` together.');\n }\n return {\n ...screen,\n options: {\n ...options,\n tabBarItemStyle: href == null ? { display: 'none' } : options.tabBarItemStyle,\n // @ts-expect-error: TODO(@kitten): This isn't properly typed\n tabBarButton: (props) => {\n if (href == null) {\n return null;\n }\n const children =\n Platform.OS === 'web' ? props.children : <Pressable>{props.children}</Pressable>;\n // TODO: React Navigation types these props as Animated.WithAnimatedValue<StyleProp<ViewStyle>>\n // While Link expects a TextStyle. We need to reconcile these types.\n return (\n <Link\n {...(props as any)}\n style={[{ display: 'flex' }, props.style as any]}\n href={href}\n asChild={Platform.OS !== 'web'}\n children={children}\n />\n );\n },\n },\n };\n }\n return screen;\n });\n});\n\nconst Tabs = Object.assign(\n (props: ComponentProps<typeof ExpoTabs>) => {\n return <ExpoTabs {...props} UNSTABLE_router={tabRouterOverride} />;\n },\n {\n Screen: ExpoTabs.Screen,\n }\n);\n\nexport default Tabs;\n"]}
1
+ {"version":3,"file":"TabsClient.js","sourceRoot":"","sources":["../../src/layouts/TabsClient.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;AAEb,+DAIuC;AAEvC,kDAA8C;AAC9C,+CAAmD;AAEnD,2DAAwD;AACxD,uCAAoC;AAEpC,2CAAgD;AAChD,kDAA+C;AAE/C,gDAAgD;AAChD,MAAM,kBAAkB,GAAG,IAAA,sCAAwB,GAAE,CAAC,SAAS,CAAC;AAMhE,MAAM,QAAQ,GAAG,IAAA,qCAAiB,EAKhC,kBAAkB,EAAE,CAAC,OAAO,EAAE,EAAE;IAChC,oCAAoC;IACpC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QAC5B,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,UAAU,IAAI,MAAM,CAAC,OAAO,EAAE,IAAI,KAAK,SAAS,EAAE,CAAC;YAC/E,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC;YAC5C,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;gBACzB,M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,CAAC,MAAM;IACvB,SAAS,EAAT,qBAAS;CACV,CACF,CAAC;AAEF,kBAAe,IAAI,CAAC","sourcesContent":["'use client';\n\nimport {\n BottomTabNavigationEventMap,\n BottomTabNavigationOptions,\n createBottomTabNavigator,\n} from '@react-navigation/bottom-tabs';\nimport { ParamListBase, TabNavigationState } from '@react-navigation/native';\nimport React, { ComponentProps } from 'react';\nimport { Pressable, Platform } from 'react-native';\n\nimport { withLayoutContext } from './withLayoutContext';\nimport { Link } from '../link/Link';\nimport { Href } from '../types';\nimport { tabRouterOverride } from './TabRouter';\nimport { Protected } from '../views/Protected';\n\n// This is the only way to access the navigator.\nconst BottomTabNavigator = createBottomTabNavigator().Navigator;\n\nexport type BottomTabNavigator = typeof BottomTabNavigator;\n\ntype TabsProps = BottomTabNavigationOptions & { href?: Href | null };\n\nconst ExpoTabs = withLayoutContext<\n TabsProps,\n typeof BottomTabNavigator,\n TabNavigationState<ParamListBase>,\n BottomTabNavigationEventMap\n>(BottomTabNavigator, (screens) => {\n // Support the `href` shortcut prop.\n return screens.map((screen) => {\n if (typeof screen.options !== 'function' && screen.options?.href !== undefined) {\n const { href, ...options } = screen.options;\n if (options.tabBarButton) {\n throw new Error('Cannot use `href` and `tabBarButton` together.');\n }\n return {\n ...screen,\n options: {\n ...options,\n tabBarItemStyle: href == null ? { display: 'none' } : options.tabBarItemStyle,\n // @ts-expect-error: TODO(@kitten): This isn't properly typed\n tabBarButton: (props) => {\n if (href == null) {\n return null;\n }\n const children =\n Platform.OS === 'web' ? props.children : <Pressable>{props.children}</Pressable>;\n // TODO: React Navigation types these props as Animated.WithAnimatedValue<StyleProp<ViewStyle>>\n // While Link expects a TextStyle. We need to reconcile these types.\n return (\n <Link\n {...(props as any)}\n style={[{ display: 'flex' }, props.style as any]}\n href={href}\n asChild={Platform.OS !== 'web'}\n children={children}\n />\n );\n },\n },\n };\n }\n return screen;\n });\n});\n\nconst Tabs = Object.assign(\n (props: ComponentProps<typeof ExpoTabs>) => {\n return <ExpoTabs {...props} UNSTABLE_router={tabRouterOverride} />;\n },\n {\n Screen: ExpoTabs.Screen,\n Protected,\n }\n);\n\nexport default Tabs;\n"]}
@@ -6,62 +6,7 @@ export interface LinkComponent {
6
6
  /** Helper method to resolve an Href object into a string. */
7
7
  resolveHref: (href: Href) => string;
8
8
  }
9
- export type RedirectProps = {
10
- /**
11
- * The path of the route to navigate to. It can either be:
12
- * - **string**: A full path like `/profile/settings` or a relative path like `../settings`.
13
- * - **object**: An object with a `pathname` and optional `params`. The `pathname` can be
14
- * a full path like `/profile/settings` or a relative path like `../settings`. The
15
- * params can be an object of key-value pairs.
16
- *
17
- * @example
18
- * ```tsx Dynamic
19
- * import { Redirect } from 'expo-router';
20
- *
21
- * export default function RedirectToAbout() {
22
- * return (
23
- * <Redirect href="/about">About</Link>
24
- * );
25
- *}
26
- * ```
27
- */
28
- href: Href;
29
- /**
30
- * Relative URL references are either relative to the directory or the document.
31
- * By default, relative paths are relative to the document.
32
- *
33
- * @see [Resolving relative references in Mozilla's documentation](https://developer.mozilla.org/en-US/docs/Web/API/URL_API/Resolving_relative_references).
34
- */
35
- relativeToDirectory?: boolean;
36
- /**
37
- * Replaces the initial screen with the current route.
38
- */
39
- withAnchor?: boolean;
40
- };
41
- /**
42
- * Redirects to the `href` as soon as the component is mounted.
43
- *
44
- * @example
45
- * ```tsx
46
- * import { View, Text } from 'react-native';
47
- * import { Redirect } from 'expo-router';
48
- *
49
- * export default function Page() {
50
- * const { user } = useAuth();
51
- *
52
- * if (!user) {
53
- * return <Redirect href="/login" />;
54
- * }
55
- *
56
- * return (
57
- * <View>
58
- * <Text>Welcome Back!</Text>
59
- * </View>
60
- * );
61
- * }
62
- * ```
63
- */
64
- export declare function Redirect({ href, relativeToDirectory, withAnchor }: RedirectProps): null;
9
+ export { Redirect, RedirectProps } from './Redirect';
65
10
  /**
66
11
  * Component that renders a link using [`href`](#href) to another route.
67
12
  * By default, it accepts children and wraps them in a `<Text>` component.
@@ -1 +1 @@
1
- {"version":3,"file":"Link.d.ts","sourceRoot":"","sources":["../../src/link/Link.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAiD,GAAG,EAAE,MAAM,OAAO,CAAC;AAM9F,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAqC,SAAS,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAI9F,MAAM,WAAW,aAAa;IAC5B,CAAC,KAAK,EAAE,iBAAiB,CAAC,SAAS,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC;IACnD,6DAA6D;IAC7D,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC;CACrC;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;;;;;;;;;;;;;;OAiBG;IACH,IAAI,EAAE,IAAI,CAAC;IAEX;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,UAAU,EAAE,EAAE,aAAa,QAUhF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,IAAI,EAA4C,aAAa,CAAC;AAqF3E,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC"}
1
+ {"version":3,"file":"Link.d.ts","sourceRoot":"","sources":["../../src/link/Link.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAiD,GAAG,EAAE,MAAM,OAAO,CAAC;AAK9F,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAqC,SAAS,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAI9F,MAAM,WAAW,aAAa;IAC5B,CAAC,KAAK,EAAE,iBAAiB,CAAC,SAAS,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC;IACnD,6DAA6D;IAC7D,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC;CACrC;AAED,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,IAAI,EAA4C,aAAa,CAAC;AAqF3E,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC"}
@@ -4,54 +4,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.Link = void 0;
8
- exports.Redirect = Redirect;
7
+ exports.Link = exports.Redirect = void 0;
9
8
  // Fork of @react-navigation/native Link.tsx with `href` and `replace` support added and
10
9
  // `to` / `action` support removed.
11
10
  const react_1 = require("react");
12
11
  const react_native_1 = require("react-native");
13
12
  const href_1 = require("./href");
14
13
  const useLinkToPathProps_1 = __importDefault(require("./useLinkToPathProps"));
15
- const hooks_1 = require("../hooks");
16
- const useFocusEffect_1 = require("../useFocusEffect");
17
14
  const useLinkHooks_1 = require("./useLinkHooks");
18
15
  const Prefetch_1 = require("../Prefetch");
19
16
  const Slot_1 = require("../ui/Slot");
20
- /**
21
- * Redirects to the `href` as soon as the component is mounted.
22
- *
23
- * @example
24
- * ```tsx
25
- * import { View, Text } from 'react-native';
26
- * import { Redirect } from 'expo-router';
27
- *
28
- * export default function Page() {
29
- * const { user } = useAuth();
30
- *
31
- * if (!user) {
32
- * return <Redirect href="/login" />;
33
- * }
34
- *
35
- * return (
36
- * <View>
37
- * <Text>Welcome Back!</Text>
38
- * </View>
39
- * );
40
- * }
41
- * ```
42
- */
43
- function Redirect({ href, relativeToDirectory, withAnchor }) {
44
- const router = (0, hooks_1.useRouter)();
45
- (0, useFocusEffect_1.useFocusEffect)(() => {
46
- try {
47
- router.replace(href, { relativeToDirectory, withAnchor });
48
- }
49
- catch (error) {
50
- console.error(error);
51
- }
52
- });
53
- return null;
54
- }
17
+ var Redirect_1 = require("./Redirect");
18
+ Object.defineProperty(exports, "Redirect", { enumerable: true, get: function () { return Redirect_1.Redirect; } });
55
19
  /**
56
20
  * Component that renders a link using [`href`](#href) to another route.
57
21
  * By default, it accepts children and wraps them in a `<Text>` component.
@@ -1 +1 @@
1
- {"version":3,"file":"Link.js","sourceRoot":"","sources":["../../src/link/Link.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;AA+Eb,4BAUC;AAxFD,wFAAwF;AACxF,mCAAmC;AACnC,iCAA8F;AAC9F,+CAAqE;AAErE,iCAAqC;AACrC,8EAAsD;AACtD,oCAAqC;AAErC,sDAAmD;AACnD,iDAA8F;AAC9F,0CAAuC;AACvC,qCAAkC;AA2ClC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,UAAU,EAAiB;IAC/E,MAAM,MAAM,GAAG,IAAA,iBAAS,GAAE,CAAC;IAC3B,IAAA,+BAAc,EAAC,GAAG,EAAE;QAClB,IAAI,CAAC;YACH,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,mBAAmB,EAAE,UAAU,EAAE,CAAC,CAAC;QAC5D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACU,QAAA,IAAI,GAAG,IAAA,kBAAU,EAAC,cAAc,CAA6B,CAAC;AAE3E,YAAI,CAAC,WAAW,GAAG,kBAAW,CAAC;AAE/B,SAAS,cAAc,CACrB,EACE,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,SAAS;AACT,yDAAyD;AAC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I,CAAC;IAExC,6HAA6H;IAC7H,MAAM,OAAO,GAAG,CACd,CAAC,SAAS,CACR,GAAG,CAAC,CAAC,GAAG,CAAC,CACT,IAAI,KAAK,CAAC,CACV,IAAI,SAAS,CAAC,CACd,IAAI,IAAI,CAAC,CACT,KAAK,CAAC,CAAC,KAAK,CAAC,CACb,IAAI,uBAAQ,CAAC,MAAM,CAAC;QAClB,GAAG,EAAE;YACH,OAAO,EAAE,OAAO;SACV;QACR,OAAO,EAAE,EAAE,OAAO,EAAE;KACrB,CAAC,CAAC,EACH,CACH,CAAC;IAEF,OAAO,QAAQ,CAAC,CAAC,CAAC,CAChB,EACE;MAAA,CAAC,mBAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EACrB;MAAA,CAAC,OAAO,CACV;IAAA,GAAG,CACJ,CAAC,CAAC,CAAC,CACF,OAAO,CACR,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n// Fork of @react-navigation/native Link.tsx with `href` and `replace` support added and\n// `to` / `action` support removed.\nimport { PropsWithChildren, forwardRef, useMemo, MouseEvent, ForwardedRef, JSX } from 'react';\nimport { Text, GestureResponderEvent, Platform } from 'react-native';\n\nimport { resolveHref } from './href';\nimport useLinkToPathProps from './useLinkToPathProps';\nimport { useRouter } from '../hooks';\nimport { Href } from '../types';\nimport { useFocusEffect } from '../useFocusEffect';\nimport { useInteropClassName, useHrefAttrs, LinkProps, WebAnchorProps } from './useLinkHooks';\nimport { Prefetch } from '../Prefetch';\nimport { Slot } from '../ui/Slot';\n\nexport interface LinkComponent {\n (props: PropsWithChildren<LinkProps>): JSX.Element;\n /** Helper method to resolve an Href object into a string. */\n resolveHref: (href: Href) => string;\n}\n\nexport type RedirectProps = {\n /**\n * The path of the route to navigate to. It can either be:\n * - **string**: A full path like `/profile/settings` or a relative path like `../settings`.\n * - **object**: An object with a `pathname` and optional `params`. The `pathname` can be\n * a full path like `/profile/settings` or a relative path like `../settings`. The\n * params can be an object of key-value pairs.\n *\n * @example\n * ```tsx Dynamic\n * import { Redirect } from 'expo-router';\n *\n * export default function RedirectToAbout() {\n * return (\n * <Redirect href=\"/about\">About</Link>\n * );\n *}\n * ```\n */\n href: Href;\n\n /**\n * Relative URL references are either relative to the directory or the document.\n * By default, relative paths are relative to the document.\n *\n * @see [Resolving relative references in Mozilla's documentation](https://developer.mozilla.org/en-US/docs/Web/API/URL_API/Resolving_relative_references).\n */\n relativeToDirectory?: boolean;\n\n /**\n * Replaces the initial screen with the current route.\n */\n withAnchor?: boolean;\n};\n\n/**\n * Redirects to the `href` as soon as the component is mounted.\n *\n * @example\n * ```tsx\n * import { View, Text } from 'react-native';\n * import { Redirect } from 'expo-router';\n *\n * export default function Page() {\n * const { user } = useAuth();\n *\n * if (!user) {\n * return <Redirect href=\"/login\" />;\n * }\n *\n * return (\n * <View>\n * <Text>Welcome Back!</Text>\n * </View>\n * );\n * }\n * ```\n */\nexport function Redirect({ href, relativeToDirectory, withAnchor }: RedirectProps) {\n const router = useRouter();\n useFocusEffect(() => {\n try {\n router.replace(href, { relativeToDirectory, withAnchor });\n } catch (error) {\n console.error(error);\n }\n });\n return null;\n}\n\n/**\n * Component that renders a link using [`href`](#href) to another route.\n * By default, it accepts children and wraps them in a `<Text>` component.\n *\n * Uses an anchor tag (`<a>`) on web and performs a client-side navigation to preserve\n * the state of the website and navigate faster. The web-only attributes such as `target`,\n * `rel`, and `download` are supported and passed to the anchor tag on web. See\n * [`WebAnchorProps`](#webanchorprops) for more details.\n *\n * > **Note**: Client-side navigation works with both single-page apps,\n * and [static-rendering](/router/reference/static-rendering/).\n *\n * @example\n * ```tsx\n * import { Link } from 'expo-router';\n * import { View } from 'react-native';\n *\n * export default function Route() {\n * return (\n * <View>\n * <Link href=\"/about\">About</Link>\n * </View>\n * );\n *}\n * ```\n */\nexport const Link = forwardRef(ExpoRouterLink) as unknown as LinkComponent;\n\nLink.resolveHref = resolveHref;\n\nfunction ExpoRouterLink(\n {\n href,\n replace,\n push,\n dismissTo,\n // TODO: This does not prevent default on the anchor tag.\n relativeToDirectory,\n asChild,\n rel,\n target,\n download,\n withAnchor,\n dangerouslySingular: singular,\n prefetch,\n ...rest\n }: LinkProps,\n ref: ForwardedRef<Text>\n) {\n // Mutate the style prop to add the className on web.\n const style = useInteropClassName(rest);\n\n // If not passing asChild, we need to forward the props to the anchor tag using React Native Web's `hrefAttrs`.\n const hrefAttrs = useHrefAttrs({ asChild, rel, target, download });\n\n const resolvedHref = useMemo(() => {\n if (href == null) {\n throw new Error('Link: href is required');\n }\n return resolveHref(href);\n }, [href]);\n\n let event;\n if (push) event = 'PUSH';\n if (replace) event = 'REPLACE';\n if (dismissTo) event = 'POP_TO';\n\n const props = useLinkToPathProps({\n href: resolvedHref,\n event,\n relativeToDirectory,\n withAnchor,\n dangerouslySingular: singular,\n });\n\n const onPress = (e: MouseEvent<HTMLAnchorElement> | GestureResponderEvent) => {\n if ('onPress' in rest) {\n rest.onPress?.(e);\n }\n props.onPress(e);\n };\n\n const Component = asChild ? Slot : Text;\n\n // Avoid using createElement directly, favoring JSX, to allow tools like NativeWind to perform custom JSX handling on native.\n const element = (\n <Component\n ref={ref}\n {...props}\n {...hrefAttrs}\n {...rest}\n style={style}\n {...Platform.select({\n web: {\n onClick: onPress,\n } as any,\n default: { onPress },\n })}\n />\n );\n\n return prefetch ? (\n <>\n <Prefetch href={href} />\n {element}\n </>\n ) : (\n element\n );\n}\n\nexport { LinkProps, WebAnchorProps };\n"]}
1
+ {"version":3,"file":"Link.js","sourceRoot":"","sources":["../../src/link/Link.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;AACb,wFAAwF;AACxF,mCAAmC;AACnC,iCAA8F;AAC9F,+CAAqE;AAErE,iCAAqC;AACrC,8EAAsD;AAEtD,iDAA8F;AAC9F,0CAAuC;AACvC,qCAAkC;AAQlC,uCAAqD;AAA5C,oGAAA,QAAQ,OAAA;AAEjB;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACU,QAAA,IAAI,GAA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CAAC,CAAC,CAAC;QACpB,CAAC;QACD,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC,CAAC;IAEF,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,WAAI,CAAC,CAAC,CAAC,mBAAI,CAAC;IAExC,6HAA6H;IAC7H,MAAM,OAAO,GAAG,CACd,CAAC,SAAS,CACR,GAAG,CAAC,CAAC,GAAG,CAAC,CACT,IAAI,KAAK,CAAC,CACV,IAAI,SAAS,CAAC,CACd,IAAI,IAAI,CAAC,CACT,KAAK,CAAC,CAAC,KAAK,CAAC,CACb,IAAI,uBAAQ,CAAC,MAAM,CAAC;QAClB,GAAG,EAAE;YACH,OAAO,EAAE,OAAO;SACV;QACR,OAAO,EAAE,EAAE,OAAO,EAAE;KACrB,CAAC,CAAC,EACH,CACH,CAAC;IAEF,OAAO,QAAQ,CAAC,CAAC,CAAC,CAChB,EACE;MAAA,CAAC,mBAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EACrB;MAAA,CAAC,OAAO,CACV;IAAA,GAAG,CACJ,CAAC,CAAC,CAAC,CACF,OAAO,CACR,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n// Fork of @react-navigation/native Link.tsx with `href` and `replace` support added and\n// `to` / `action` support removed.\nimport { PropsWithChildren, forwardRef, useMemo, MouseEvent, ForwardedRef, JSX } from 'react';\nimport { Text, GestureResponderEvent, Platform } from 'react-native';\n\nimport { resolveHref } from './href';\nimport useLinkToPathProps from './useLinkToPathProps';\nimport { Href } from '../types';\nimport { useInteropClassName, useHrefAttrs, LinkProps, WebAnchorProps } from './useLinkHooks';\nimport { Prefetch } from '../Prefetch';\nimport { Slot } from '../ui/Slot';\n\nexport interface LinkComponent {\n (props: PropsWithChildren<LinkProps>): JSX.Element;\n /** Helper method to resolve an Href object into a string. */\n resolveHref: (href: Href) => string;\n}\n\nexport { Redirect, RedirectProps } from './Redirect';\n\n/**\n * Component that renders a link using [`href`](#href) to another route.\n * By default, it accepts children and wraps them in a `<Text>` component.\n *\n * Uses an anchor tag (`<a>`) on web and performs a client-side navigation to preserve\n * the state of the website and navigate faster. The web-only attributes such as `target`,\n * `rel`, and `download` are supported and passed to the anchor tag on web. See\n * [`WebAnchorProps`](#webanchorprops) for more details.\n *\n * > **Note**: Client-side navigation works with both single-page apps,\n * and [static-rendering](/router/reference/static-rendering/).\n *\n * @example\n * ```tsx\n * import { Link } from 'expo-router';\n * import { View } from 'react-native';\n *\n * export default function Route() {\n * return (\n * <View>\n * <Link href=\"/about\">About</Link>\n * </View>\n * );\n *}\n * ```\n */\nexport const Link = forwardRef(ExpoRouterLink) as unknown as LinkComponent;\n\nLink.resolveHref = resolveHref;\n\nfunction ExpoRouterLink(\n {\n href,\n replace,\n push,\n dismissTo,\n // TODO: This does not prevent default on the anchor tag.\n relativeToDirectory,\n asChild,\n rel,\n target,\n download,\n withAnchor,\n dangerouslySingular: singular,\n prefetch,\n ...rest\n }: LinkProps,\n ref: ForwardedRef<Text>\n) {\n // Mutate the style prop to add the className on web.\n const style = useInteropClassName(rest);\n\n // If not passing asChild, we need to forward the props to the anchor tag using React Native Web's `hrefAttrs`.\n const hrefAttrs = useHrefAttrs({ asChild, rel, target, download });\n\n const resolvedHref = useMemo(() => {\n if (href == null) {\n throw new Error('Link: href is required');\n }\n return resolveHref(href);\n }, [href]);\n\n let event;\n if (push) event = 'PUSH';\n if (replace) event = 'REPLACE';\n if (dismissTo) event = 'POP_TO';\n\n const props = useLinkToPathProps({\n href: resolvedHref,\n event,\n relativeToDirectory,\n withAnchor,\n dangerouslySingular: singular,\n });\n\n const onPress = (e: MouseEvent<HTMLAnchorElement> | GestureResponderEvent) => {\n if ('onPress' in rest) {\n rest.onPress?.(e);\n }\n props.onPress(e);\n };\n\n const Component = asChild ? Slot : Text;\n\n // Avoid using createElement directly, favoring JSX, to allow tools like NativeWind to perform custom JSX handling on native.\n const element = (\n <Component\n ref={ref}\n {...props}\n {...hrefAttrs}\n {...rest}\n style={style}\n {...Platform.select({\n web: {\n onClick: onPress,\n } as any,\n default: { onPress },\n })}\n />\n );\n\n return prefetch ? (\n <>\n <Prefetch href={href} />\n {element}\n </>\n ) : (\n element\n );\n}\n\nexport { LinkProps, WebAnchorProps };\n"]}