react-router-native 6.3.0 → 6.4.0-pre.3

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.
@@ -0,0 +1,36 @@
1
+ import * as TestRenderer from "react-test-renderer";
2
+
3
+ export class MockEvent {
4
+ type: string;
5
+ defaultPrevented: boolean;
6
+ [k: string]: any;
7
+
8
+ constructor(type: string, extraProps?: any) {
9
+ this.type = type;
10
+ this.defaultPrevented = false;
11
+ Object.assign(this, extraProps);
12
+ }
13
+ preventDefault() {
14
+ this.defaultPrevented = true;
15
+ }
16
+ }
17
+
18
+ export function press(
19
+ element: React.ReactElement | TestRenderer.ReactTestInstance,
20
+ extraProps?: any
21
+ ) {
22
+ if (!element.props.onPress) {
23
+ throw new Error(`Missing onPress prop for element in press(element)`);
24
+ }
25
+ let event = new MockEvent("press", extraProps);
26
+ element.props.onPress(event);
27
+ return event;
28
+ }
29
+
30
+ export function mockPromiseThatResolvesImmediatelyWith<T = void>(value?: T) {
31
+ return {
32
+ then(callback: (val?: T | undefined) => any) {
33
+ callback(value);
34
+ },
35
+ } as Promise<T>;
36
+ }
package/index.tsx ADDED
@@ -0,0 +1,348 @@
1
+ import * as React from "react";
2
+ import {
3
+ BackHandler,
4
+ GestureResponderEvent,
5
+ Linking,
6
+ TouchableHighlight,
7
+ TouchableHighlightProps,
8
+ } from "react-native";
9
+ import {
10
+ MemoryRouter,
11
+ MemoryRouterProps,
12
+ NavigateOptions,
13
+ useLocation,
14
+ useNavigate,
15
+ } from "react-router";
16
+ import type { To } from "react-router";
17
+
18
+ import URLSearchParams from "@ungap/url-search-params";
19
+
20
+ ////////////////////////////////////////////////////////////////////////////////
21
+ // RE-EXPORTS
22
+ ////////////////////////////////////////////////////////////////////////////////
23
+
24
+ // Note: Keep in sync with react-router exports!
25
+ export type {
26
+ ActionFunction,
27
+ DataMemoryRouterProps,
28
+ DataRouteMatch,
29
+ Fetcher,
30
+ Hash,
31
+ IndexRouteProps,
32
+ JsonFunction,
33
+ LayoutRouteProps,
34
+ LoaderFunction,
35
+ Location,
36
+ MemoryRouterProps,
37
+ NavigateFunction,
38
+ NavigateOptions,
39
+ NavigateProps,
40
+ Navigation,
41
+ Navigator,
42
+ OutletProps,
43
+ Params,
44
+ Path,
45
+ PathMatch,
46
+ Pathname,
47
+ PathPattern,
48
+ PathRouteProps,
49
+ RedirectFunction,
50
+ RouteMatch,
51
+ RouteObject,
52
+ RouteProps,
53
+ RouterProps,
54
+ RoutesProps,
55
+ Search,
56
+ ShouldRevalidateFunction,
57
+ To,
58
+ } from "react-router";
59
+ export {
60
+ DataMemoryRouter,
61
+ MemoryRouter,
62
+ Navigate,
63
+ NavigationType,
64
+ Outlet,
65
+ Route,
66
+ Router,
67
+ Routes,
68
+ createPath,
69
+ createRoutesFromChildren,
70
+ isRouteErrorResponse,
71
+ generatePath,
72
+ json,
73
+ matchPath,
74
+ matchRoutes,
75
+ parsePath,
76
+ redirect,
77
+ renderMatches,
78
+ resolvePath,
79
+ useActionData,
80
+ useHref,
81
+ useInRouterContext,
82
+ useLoaderData,
83
+ useLocation,
84
+ useMatch,
85
+ useMatches,
86
+ useNavigate,
87
+ useNavigation,
88
+ useNavigationType,
89
+ useOutlet,
90
+ useOutletContext,
91
+ useParams,
92
+ useResolvedPath,
93
+ useRevalidator,
94
+ useRouteError,
95
+ useRouteLoaderData,
96
+ useRoutes,
97
+ } from "react-router";
98
+
99
+ ///////////////////////////////////////////////////////////////////////////////
100
+ // DANGER! PLEASE READ ME!
101
+ // We provide these exports as an escape hatch in the event that you need any
102
+ // routing data that we don't provide an explicit API for. With that said, we
103
+ // want to cover your use case if we can, so if you feel the need to use these
104
+ // we want to hear from you. Let us know what you're building and we'll do our
105
+ // best to make sure we can support you!
106
+ //
107
+ // We consider these exports an implementation detail and do not guarantee
108
+ // against any breaking changes, regardless of the semver release. Use with
109
+ // extreme caution and only if you understand the consequences. Godspeed.
110
+ ///////////////////////////////////////////////////////////////////////////////
111
+
112
+ /** @internal */
113
+ export {
114
+ UNSAFE_NavigationContext,
115
+ UNSAFE_LocationContext,
116
+ UNSAFE_RouteContext,
117
+ UNSAFE_DataRouterContext,
118
+ UNSAFE_DataRouterStateContext,
119
+ useRenderDataRouter,
120
+ } from "react-router";
121
+
122
+ ////////////////////////////////////////////////////////////////////////////////
123
+ // COMPONENTS
124
+ ////////////////////////////////////////////////////////////////////////////////
125
+
126
+ export interface NativeRouterProps extends MemoryRouterProps {}
127
+
128
+ /**
129
+ * A <Router> that runs on React Native.
130
+ */
131
+ export function NativeRouter(props: NativeRouterProps) {
132
+ return <MemoryRouter {...props} />;
133
+ }
134
+
135
+ export interface LinkProps extends TouchableHighlightProps {
136
+ children?: React.ReactNode;
137
+ onPress?: (event: GestureResponderEvent) => void;
138
+ replace?: boolean;
139
+ state?: any;
140
+ to: To;
141
+ }
142
+
143
+ /**
144
+ * A <TouchableHighlight> that navigates to a different URL when touched.
145
+ */
146
+ export function Link({
147
+ onPress,
148
+ replace = false,
149
+ state,
150
+ to,
151
+ ...rest
152
+ }: LinkProps) {
153
+ let internalOnPress = useLinkPressHandler(to, { replace, state });
154
+ function handlePress(event: GestureResponderEvent) {
155
+ if (onPress) onPress(event);
156
+ if (!event.defaultPrevented) {
157
+ internalOnPress(event);
158
+ }
159
+ }
160
+
161
+ return <TouchableHighlight {...rest} onPress={handlePress} />;
162
+ }
163
+
164
+ ////////////////////////////////////////////////////////////////////////////////
165
+ // HOOKS
166
+ ////////////////////////////////////////////////////////////////////////////////
167
+
168
+ const HardwareBackPressEventType = "hardwareBackPress";
169
+ const URLEventType = "url";
170
+
171
+ /**
172
+ * Handles the press behavior for router `<Link>` components. This is useful if
173
+ * you need to create custom `<Link>` components with the same press behavior we
174
+ * use in our exported `<Link>`.
175
+ */
176
+ export function useLinkPressHandler(
177
+ to: To,
178
+ {
179
+ replace,
180
+ state,
181
+ }: {
182
+ replace?: boolean;
183
+ state?: any;
184
+ } = {}
185
+ ): (event: GestureResponderEvent) => void {
186
+ let navigate = useNavigate();
187
+ return function handlePress() {
188
+ navigate(to, { replace, state });
189
+ };
190
+ }
191
+
192
+ /**
193
+ * Enables support for the hardware back button on Android.
194
+ */
195
+ export function useHardwareBackButton() {
196
+ React.useEffect(() => {
197
+ function handleHardwardBackPress() {
198
+ return undefined;
199
+ // TODO: The implementation will be something like this
200
+ // if (history.index === 0) {
201
+ // return false; // home screen
202
+ // } else {
203
+ // history.back();
204
+ // return true;
205
+ // }
206
+ }
207
+
208
+ BackHandler.addEventListener(
209
+ HardwareBackPressEventType,
210
+ handleHardwardBackPress
211
+ );
212
+
213
+ return () => {
214
+ BackHandler.removeEventListener(
215
+ HardwareBackPressEventType,
216
+ handleHardwardBackPress
217
+ );
218
+ };
219
+ }, []);
220
+ }
221
+
222
+ export { useHardwareBackButton as useAndroidBackButton };
223
+
224
+ /**
225
+ * Enables deep linking, both on the initial app launch and for
226
+ * subsequent incoming links.
227
+ */
228
+ export function useDeepLinking() {
229
+ let navigate = useNavigate();
230
+
231
+ // Get the initial URL
232
+ React.useEffect(() => {
233
+ let current = true;
234
+
235
+ Linking.getInitialURL().then((url) => {
236
+ if (current) {
237
+ if (url) navigate(trimScheme(url));
238
+ }
239
+ });
240
+
241
+ return () => {
242
+ current = false;
243
+ };
244
+ }, [navigate]);
245
+
246
+ // Listen for URL changes
247
+ React.useEffect(() => {
248
+ function handleURLChange(event: { url: string }) {
249
+ navigate(trimScheme(event.url));
250
+ }
251
+
252
+ Linking.addEventListener(URLEventType, handleURLChange);
253
+
254
+ return () => {
255
+ Linking.removeEventListener(URLEventType, handleURLChange);
256
+ };
257
+ }, [navigate]);
258
+ }
259
+
260
+ function trimScheme(url: string) {
261
+ return url.replace(/^.*?:\/\//, "");
262
+ }
263
+
264
+ /**
265
+ * A convenient wrapper for accessing individual query parameters via the
266
+ * URLSearchParams interface.
267
+ */
268
+ export function useSearchParams(
269
+ defaultInit?: URLSearchParamsInit
270
+ ): [URLSearchParams, SetURLSearchParams] {
271
+ let defaultSearchParamsRef = React.useRef(createSearchParams(defaultInit));
272
+
273
+ let location = useLocation();
274
+ let searchParams = React.useMemo(() => {
275
+ let searchParams = createSearchParams(location.search);
276
+
277
+ for (let key of defaultSearchParamsRef.current.keys()) {
278
+ if (!searchParams.has(key)) {
279
+ defaultSearchParamsRef.current.getAll(key).forEach((value) => {
280
+ searchParams.append(key, value);
281
+ });
282
+ }
283
+ }
284
+
285
+ return searchParams;
286
+ }, [location.search]);
287
+
288
+ let navigate = useNavigate();
289
+ let setSearchParams: SetURLSearchParams = React.useCallback(
290
+ (nextInit, navigateOpts) => {
291
+ navigate("?" + createSearchParams(nextInit), navigateOpts);
292
+ },
293
+ [navigate]
294
+ );
295
+
296
+ return [searchParams, setSearchParams];
297
+ }
298
+
299
+ type SetURLSearchParams = (
300
+ nextInit?: URLSearchParamsInit | undefined,
301
+ navigateOpts?: NavigateOptions | undefined
302
+ ) => void;
303
+
304
+ export type ParamKeyValuePair = [string, string];
305
+
306
+ export type URLSearchParamsInit =
307
+ | string
308
+ | ParamKeyValuePair[]
309
+ | Record<string, string | string[]>
310
+ | URLSearchParams;
311
+
312
+ /**
313
+ * Creates a URLSearchParams object using the given initializer.
314
+ *
315
+ * This is identical to `new URLSearchParams(init)` except it also
316
+ * supports arrays as values in the object form of the initializer
317
+ * instead of just strings. This is convenient when you need multiple
318
+ * values for a given key, but don't want to use an array initializer.
319
+ *
320
+ * For example, instead of:
321
+ *
322
+ * let searchParams = new URLSearchParams([
323
+ * ['sort', 'name'],
324
+ * ['sort', 'price']
325
+ * ]);
326
+ *
327
+ * you can do:
328
+ *
329
+ * let searchParams = createSearchParams({
330
+ * sort: ['name', 'price']
331
+ * });
332
+ */
333
+ export function createSearchParams(
334
+ init: URLSearchParamsInit = ""
335
+ ): URLSearchParams {
336
+ return new URLSearchParams(
337
+ typeof init === "string" ||
338
+ Array.isArray(init) ||
339
+ init instanceof URLSearchParams
340
+ ? init
341
+ : Object.keys(init).reduce((memo, key) => {
342
+ let value = init[key];
343
+ return memo.concat(
344
+ Array.isArray(value) ? value.map((v) => [key, v]) : [[key, value]]
345
+ );
346
+ }, [] as ParamKeyValuePair[])
347
+ );
348
+ }
package/jest.config.js ADDED
@@ -0,0 +1,14 @@
1
+ module.exports = {
2
+ preset: "react-native",
3
+ testMatch: ["**/__tests__/*-test.[jt]s?(x)"],
4
+ transform: {
5
+ "\\.[jt]sx?$": "<rootDir>/node_modules/react-native/jest/preprocessor.js",
6
+ },
7
+ globals: {
8
+ __DEV__: true,
9
+ },
10
+ modulePaths: [
11
+ "<rootDir>/node_modules", // for react-native
12
+ ],
13
+ setupFiles: ["<rootDir>/__tests__/setup.ts"],
14
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-router-native",
3
- "version": "6.3.0",
3
+ "version": "6.4.0-pre.3",
4
4
  "author": "Remix Software <hello@remix.run>",
5
5
  "description": "Declarative routing for React Native applications",
6
6
  "repository": {
@@ -13,16 +13,16 @@
13
13
  "types": "./index.d.ts",
14
14
  "dependencies": {
15
15
  "@ungap/url-search-params": "^0.1.4",
16
- "react-router": "6.3.0",
17
- "history": "^5.2.0"
16
+ "react-router": "6.4.0-pre.3"
17
+ },
18
+ "devDependencies": {
19
+ "react": "^17.0.2",
20
+ "react-native": "^0.61.4"
18
21
  },
19
22
  "peerDependencies": {
20
23
  "react": ">=16.8",
21
24
  "react-native": ">=0.44"
22
25
  },
23
- "devDependencies": {
24
- "react-native": "^0.61.4"
25
- },
26
26
  "sideEffects": false,
27
27
  "keywords": [
28
28
  "react",
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "files": ["index.tsx"],
3
+ "compilerOptions": {
4
+ "lib": ["ES2020", "DOM.Iterable"],
5
+ "target": "ES2020",
6
+ "module": "ES2020",
7
+ "moduleResolution": "node",
8
+
9
+ "allowSyntheticDefaultImports": true,
10
+ "strict": true,
11
+ "jsx": "react",
12
+
13
+ "declaration": true,
14
+ "emitDeclarationOnly": true,
15
+
16
+ "skipLibCheck": true,
17
+
18
+ "outDir": "../../build/node_modules/react-router-native",
19
+ "rootDir": "."
20
+ }
21
+ }
package/LICENSE.md DELETED
@@ -1,22 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) React Training 2015-2019
4
- Copyright (c) Remix Software 2020-2021
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in all
14
- copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- SOFTWARE.
package/index.d.ts DELETED
@@ -1,76 +0,0 @@
1
- import * as React from "react";
2
- import { GestureResponderEvent, TouchableHighlightProps } from "react-native";
3
- import { MemoryRouter, MemoryRouterProps, Navigate, NavigateOptions, Outlet, Route, Router, Routes, createRoutesFromChildren, generatePath, matchRoutes, matchPath, createPath, parsePath, resolvePath, renderMatches, useHref, useInRouterContext, useLocation, useMatch, useNavigate, useNavigationType, useOutlet, useParams, useResolvedPath, useRoutes, useOutletContext } from "react-router";
4
- import type { To } from "react-router";
5
- import URLSearchParams from "@ungap/url-search-params";
6
- export { MemoryRouter, Navigate, Outlet, Route, Router, Routes, createRoutesFromChildren, generatePath, matchRoutes, matchPath, createPath, parsePath, resolvePath, renderMatches, useHref, useInRouterContext, useLocation, useMatch, useNavigate, useNavigationType, useOutlet, useParams, useResolvedPath, useRoutes, useOutletContext, };
7
- export { NavigationType } from "react-router";
8
- export type { Hash, IndexRouteProps, LayoutRouteProps, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigator, OutletProps, Params, Path, PathMatch, PathRouteProps, RouteMatch, RouteObject, RouteProps, RouterProps, RoutesProps, Pathname, Search, To, } from "react-router";
9
- /** @internal */
10
- export { UNSAFE_NavigationContext, UNSAFE_LocationContext, UNSAFE_RouteContext, } from "react-router";
11
- export interface NativeRouterProps extends MemoryRouterProps {
12
- }
13
- /**
14
- * A <Router> that runs on React Native.
15
- */
16
- export declare function NativeRouter(props: NativeRouterProps): JSX.Element;
17
- export interface LinkProps extends TouchableHighlightProps {
18
- children?: React.ReactNode;
19
- onPress?: (event: GestureResponderEvent) => void;
20
- replace?: boolean;
21
- state?: any;
22
- to: To;
23
- }
24
- /**
25
- * A <TouchableHighlight> that navigates to a different URL when touched.
26
- */
27
- export declare function Link({ onPress, replace, state, to, ...rest }: LinkProps): JSX.Element;
28
- /**
29
- * Handles the press behavior for router `<Link>` components. This is useful if
30
- * you need to create custom `<Link>` components with the same press behavior we
31
- * use in our exported `<Link>`.
32
- */
33
- export declare function useLinkPressHandler(to: To, { replace, state, }?: {
34
- replace?: boolean;
35
- state?: any;
36
- }): (event: GestureResponderEvent) => void;
37
- /**
38
- * Enables support for the hardware back button on Android.
39
- */
40
- export declare function useHardwareBackButton(): void;
41
- export { useHardwareBackButton as useAndroidBackButton };
42
- /**
43
- * Enables deep linking, both on the initial app launch and for
44
- * subsequent incoming links.
45
- */
46
- export declare function useDeepLinking(): void;
47
- /**
48
- * A convenient wrapper for accessing individual query parameters via the
49
- * URLSearchParams interface.
50
- */
51
- export declare function useSearchParams(defaultInit?: URLSearchParamsInit): [URLSearchParams, SetURLSearchParams];
52
- declare type SetURLSearchParams = (nextInit?: URLSearchParamsInit | undefined, navigateOpts?: NavigateOptions | undefined) => void;
53
- export declare type ParamKeyValuePair = [string, string];
54
- export declare type URLSearchParamsInit = string | ParamKeyValuePair[] | Record<string, string | string[]> | URLSearchParams;
55
- /**
56
- * Creates a URLSearchParams object using the given initializer.
57
- *
58
- * This is identical to `new URLSearchParams(init)` except it also
59
- * supports arrays as values in the object form of the initializer
60
- * instead of just strings. This is convenient when you need multiple
61
- * values for a given key, but don't want to use an array initializer.
62
- *
63
- * For example, instead of:
64
- *
65
- * let searchParams = new URLSearchParams([
66
- * ['sort', 'name'],
67
- * ['sort', 'price']
68
- * ]);
69
- *
70
- * you can do:
71
- *
72
- * let searchParams = createSearchParams({
73
- * sort: ['name', 'price']
74
- * });
75
- */
76
- export declare function createSearchParams(init?: URLSearchParamsInit): URLSearchParams;
package/index.js DELETED
@@ -1,112 +0,0 @@
1
- /**
2
- * React Router Native v6.3.0
3
- *
4
- * Copyright (c) Remix Software Inc.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- import { createElement, useEffect, useRef, useMemo, useCallback } from 'react';
12
- import { TouchableHighlight, BackHandler, Linking } from 'react-native';
13
- import { MemoryRouter, useNavigate, useLocation } from 'react-router';
14
- export { MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, Routes, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, createPath, createRoutesFromChildren, generatePath, matchPath, matchRoutes, parsePath, renderMatches, resolvePath, useHref, useInRouterContext, useLocation, useMatch, useNavigate, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes } from 'react-router';
15
- import URLSearchParams from '@ungap/url-search-params';
16
-
17
- function _extends() {
18
- _extends = Object.assign || function (target) {
19
- for (var i = 1; i < arguments.length; i++) {
20
- var source = arguments[i];
21
-
22
- for (var key in source) {
23
- if (Object.prototype.hasOwnProperty.call(source, key)) {
24
- target[key] = source[key];
25
- }
26
- }
27
- }
28
-
29
- return target;
30
- };
31
-
32
- return _extends.apply(this, arguments);
33
- }
34
-
35
- function _objectWithoutPropertiesLoose(source, excluded) {
36
- if (source == null) return {};
37
- var target = {};
38
- var sourceKeys = Object.keys(source);
39
- var key, i;
40
-
41
- for (i = 0; i < sourceKeys.length; i++) {
42
- key = sourceKeys[i];
43
- if (excluded.indexOf(key) >= 0) continue;
44
- target[key] = source[key];
45
- }
46
-
47
- return target;
48
- }
49
-
50
- function _objectWithoutProperties(source, excluded) {
51
- if (source == null) return {};
52
-
53
- var target = _objectWithoutPropertiesLoose(source, excluded);
54
-
55
- var key, i;
56
-
57
- if (Object.getOwnPropertySymbols) {
58
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
59
-
60
- for (i = 0; i < sourceSymbolKeys.length; i++) {
61
- key = sourceSymbolKeys[i];
62
- if (excluded.indexOf(key) >= 0) continue;
63
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
64
- target[key] = source[key];
65
- }
66
- }
67
-
68
- return target;
69
- }
70
-
71
- function _unsupportedIterableToArray(o, minLen) {
72
- if (!o) return;
73
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
74
- var n = Object.prototype.toString.call(o).slice(8, -1);
75
- if (n === "Object" && o.constructor) n = o.constructor.name;
76
- if (n === "Map" || n === "Set") return Array.from(o);
77
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
78
- }
79
-
80
- function _arrayLikeToArray(arr, len) {
81
- if (len == null || len > arr.length) len = arr.length;
82
-
83
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
84
-
85
- return arr2;
86
- }
87
-
88
- function _createForOfIteratorHelperLoose(o, allowArrayLike) {
89
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
90
- if (it) return (it = it.call(o)).next.bind(it);
91
-
92
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
93
- if (it) o = it;
94
- var i = 0;
95
- return function () {
96
- if (i >= o.length) return {
97
- done: true
98
- };
99
- return {
100
- done: false,
101
- value: o[i++]
102
- };
103
- };
104
- }
105
-
106
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
107
- }
108
-
109
- var _excluded=["onPress","replace","state","to"];var _jsxFileName="/home/runner/work/react-router/react-router/packages/react-router-native/index.tsx";function NativeRouter(props){return createElement(MemoryRouter,_extends({},props,{__source:{fileName:_jsxFileName,lineNumber:131,columnNumber:10}}));}function Link(_ref){var onPress=_ref.onPress,_ref$replace=_ref.replace,replace=_ref$replace===void 0?false:_ref$replace,state=_ref.state,to=_ref.to,rest=_objectWithoutProperties(_ref,_excluded);var internalOnPress=useLinkPressHandler(to,{replace:replace,state:state});function handlePress(event){if(onPress)onPress(event);if(!event.defaultPrevented){internalOnPress(event);}}return createElement(TouchableHighlight,_extends({},rest,{onPress:handlePress,__source:{fileName:_jsxFileName,lineNumber:160,columnNumber:10}}));}var HardwareBackPressEventType="hardwareBackPress";var URLEventType="url";function useLinkPressHandler(to){var _ref2=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},replace=_ref2.replace,state=_ref2.state;var navigate=useNavigate();return function handlePress(){navigate(to,{replace:replace,state:state});};}function useHardwareBackButton(){useEffect(function(){function handleHardwardBackPress(){return undefined;}BackHandler.addEventListener(HardwareBackPressEventType,handleHardwardBackPress);return function(){BackHandler.removeEventListener(HardwareBackPressEventType,handleHardwardBackPress);};},[]);}function useDeepLinking(){var navigate=useNavigate();useEffect(function(){var current=true;Linking.getInitialURL().then(function(url){if(current){if(url)navigate(trimScheme(url));}});return function(){current=false;};},[navigate]);useEffect(function(){function handleURLChange(event){navigate(trimScheme(event.url));}Linking.addEventListener(URLEventType,handleURLChange);return function(){Linking.removeEventListener(URLEventType,handleURLChange);};},[navigate]);}function trimScheme(url){return url.replace(/^.*?:\/\//,"");}function useSearchParams(defaultInit){var defaultSearchParamsRef=useRef(createSearchParams(defaultInit));var location=useLocation();var searchParams=useMemo(function(){var searchParams=createSearchParams(location.search);var _loop=function _loop(key){if(!searchParams.has(key)){defaultSearchParamsRef.current.getAll(key).forEach(function(value){searchParams.append(key,value);});}};for(var _iterator=_createForOfIteratorHelperLoose(defaultSearchParamsRef.current.keys()),_step;!(_step=_iterator()).done;){var key=_step.value;_loop(key);}return searchParams;},[location.search]);var navigate=useNavigate();var setSearchParams=useCallback(function(nextInit,navigateOpts){navigate("?"+createSearchParams(nextInit),navigateOpts);},[navigate]);return [searchParams,setSearchParams];}function createSearchParams(){var init=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"";return new URLSearchParams(typeof init==="string"||Array.isArray(init)||init instanceof URLSearchParams?init:Object.keys(init).reduce(function(memo,key){var value=init[key];return memo.concat(Array.isArray(value)?value.map(function(v){return [key,v];}):[[key,value]]);},[]));}
110
-
111
- export { Link, NativeRouter, createSearchParams, useHardwareBackButton as useAndroidBackButton, useDeepLinking, useHardwareBackButton, useLinkPressHandler, useSearchParams };
112
- //# sourceMappingURL=index.js.map