@react-navigation/native 6.1.4 → 7.0.0-alpha.0
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/lib/commonjs/Link.js +16 -5
- package/lib/commonjs/Link.js.map +1 -1
- package/lib/commonjs/NavigationContainer.js +3 -14
- package/lib/commonjs/NavigationContainer.js.map +1 -1
- package/lib/commonjs/createStaticNavigation.js +39 -0
- package/lib/commonjs/createStaticNavigation.js.map +1 -0
- package/lib/commonjs/index.js +8 -8
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/useLinkProps.js +17 -15
- package/lib/commonjs/useLinkProps.js.map +1 -1
- package/lib/commonjs/{useLinkBuilder.js → useLinkTools.js} +23 -5
- package/lib/commonjs/useLinkTools.js.map +1 -0
- package/lib/commonjs/useLinking.js +2 -4
- package/lib/commonjs/useLinking.js.map +1 -1
- package/lib/commonjs/useLinking.native.js +3 -4
- package/lib/commonjs/useLinking.native.js.map +1 -1
- package/lib/module/Link.js +16 -5
- package/lib/module/Link.js.map +1 -1
- package/lib/module/NavigationContainer.js +3 -14
- package/lib/module/NavigationContainer.js.map +1 -1
- package/lib/module/createStaticNavigation.js +30 -0
- package/lib/module/createStaticNavigation.js.map +1 -0
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/useLinkProps.js +17 -15
- package/lib/module/useLinkProps.js.map +1 -1
- package/lib/module/{useLinkBuilder.js → useLinkTools.js} +23 -5
- package/lib/module/useLinkTools.js.map +1 -0
- package/lib/module/useLinking.js +3 -5
- package/lib/module/useLinking.js.map +1 -1
- package/lib/module/useLinking.native.js +4 -5
- package/lib/module/useLinking.native.js.map +1 -1
- package/lib/typescript/src/Link.d.ts +8 -9
- package/lib/typescript/src/Link.d.ts.map +1 -1
- package/lib/typescript/src/NavigationContainer.d.ts +1 -3
- package/lib/typescript/src/NavigationContainer.d.ts.map +1 -1
- package/lib/typescript/src/ServerContext.d.ts +1 -1
- package/lib/typescript/src/ServerContext.d.ts.map +1 -1
- package/lib/typescript/src/__mocks__/createStackNavigator.d.ts +57 -0
- package/lib/typescript/src/__mocks__/createStackNavigator.d.ts.map +1 -0
- package/lib/typescript/src/createMemoryHistory.d.ts +1 -1
- package/lib/typescript/src/createMemoryHistory.d.ts.map +1 -1
- package/lib/typescript/src/createStaticNavigation.d.ts +20 -0
- package/lib/typescript/src/createStaticNavigation.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/theming/ThemeProvider.d.ts +1 -1
- package/lib/typescript/src/theming/ThemeProvider.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +4 -4
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useLinkProps.d.ts +17 -7
- package/lib/typescript/src/useLinkProps.d.ts.map +1 -1
- package/lib/typescript/src/useLinkTools.d.ts +33 -0
- package/lib/typescript/src/useLinkTools.d.ts.map +1 -0
- package/lib/typescript/src/useLinking.d.ts +2 -4
- package/lib/typescript/src/useLinking.d.ts.map +1 -1
- package/lib/typescript/src/useLinking.native.d.ts +2 -4
- package/lib/typescript/src/useLinking.native.d.ts.map +1 -1
- package/lib/typescript/src/useScrollToTop.d.ts +3 -3
- package/lib/typescript/src/useScrollToTop.d.ts.map +1 -1
- package/package.json +11 -11
- package/src/Link.tsx +25 -15
- package/src/NavigationContainer.tsx +4 -17
- package/src/__mocks__/createStackNavigator.tsx +21 -0
- package/src/createStaticNavigation.tsx +49 -0
- package/src/index.tsx +2 -2
- package/src/useLinkProps.tsx +43 -30
- package/src/{useLinkBuilder.tsx → useLinkTools.tsx} +32 -3
- package/src/useLinking.native.tsx +6 -6
- package/src/useLinking.tsx +5 -6
- package/lib/commonjs/useLinkBuilder.js.map +0 -1
- package/lib/commonjs/useLinkTo.js +0 -45
- package/lib/commonjs/useLinkTo.js.map +0 -1
- package/lib/module/useLinkBuilder.js.map +0 -1
- package/lib/module/useLinkTo.js +0 -36
- package/lib/module/useLinkTo.js.map +0 -1
- package/lib/typescript/src/useLinkBuilder.d.ts +0 -6
- package/lib/typescript/src/useLinkBuilder.d.ts.map +0 -1
- package/lib/typescript/src/useLinkTo.d.ts +0 -9
- package/lib/typescript/src/useLinkTo.d.ts.map +0 -1
- package/src/useLinkTo.tsx +0 -71
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../../../../src/theming/ThemeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAGtC,
|
|
1
|
+
{"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../../../../src/theming/ThemeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAGtC,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,KAAK,eAI/D"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { getActionFromState as getActionFromStateDefault, getPathFromState as getPathFromStateDefault, getStateFromPath as getStateFromPathDefault, PathConfigMap, Route } from '@react-navigation/core';
|
|
2
|
-
export
|
|
2
|
+
export type Theme = {
|
|
3
3
|
dark: boolean;
|
|
4
4
|
colors: {
|
|
5
5
|
primary: string;
|
|
@@ -10,7 +10,7 @@ export declare type Theme = {
|
|
|
10
10
|
notification: string;
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
|
-
export
|
|
13
|
+
export type LinkingOptions<ParamList extends {}> = {
|
|
14
14
|
/**
|
|
15
15
|
* Whether deep link handling should be enabled.
|
|
16
16
|
* Defaults to true.
|
|
@@ -117,11 +117,11 @@ export declare type LinkingOptions<ParamList extends {}> = {
|
|
|
117
117
|
*/
|
|
118
118
|
getActionFromState?: typeof getActionFromStateDefault;
|
|
119
119
|
};
|
|
120
|
-
export
|
|
120
|
+
export type DocumentTitleOptions = {
|
|
121
121
|
enabled?: boolean;
|
|
122
122
|
formatter?: (options: Record<string, any> | undefined, route: Route<string> | undefined) => string;
|
|
123
123
|
};
|
|
124
|
-
export
|
|
124
|
+
export type ServerContainerRef = {
|
|
125
125
|
getCurrentOptions(): Record<string, any> | undefined;
|
|
126
126
|
};
|
|
127
127
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,IAAI,yBAAyB,EAC/C,gBAAgB,IAAI,uBAAuB,EAC3C,gBAAgB,IAAI,uBAAuB,EAC3C,aAAa,EACb,KAAK,EACN,MAAM,wBAAwB,CAAC;AAEhC,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,IAAI,yBAAyB,EAC/C,gBAAgB,IAAI,uBAAuB,EAC3C,gBAAgB,IAAI,uBAAuB,EAC3C,aAAa,EACb,KAAK,EACN,MAAM,wBAAwB,CAAC;AAEhC,MAAM,MAAM,KAAK,GAAG;IAClB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,cAAc,CAAC,SAAS,SAAS,EAAE,IAAI;IACjD;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IAClC;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,EAAE;QACP,gBAAgB,CAAC,EAAE,MAAM,SAAS,CAAC;QACnC,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;KACnC,CAAC;IACF;;;;;;;;;;;;OAYG;IACH,aAAa,CAAC,EAAE,MACZ,MAAM,GACN,IAAI,GACJ,SAAS,GACT,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IACvC;;;;;;;;;;;;;;;;;;OAkBG;IACH,SAAS,CAAC,EAAE,CACV,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,KAC5B,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;IACrC;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,uBAAuB,CAAC;IAClD;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,uBAAuB,CAAC;IAClD;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,yBAAyB,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,CACV,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,EACxC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,KAC7B,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,iBAAiB,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;CACtD,CAAC"}
|
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
import { NavigationAction } from '@react-navigation/core';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { GestureResponderEvent } from 'react-native';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export type Props<ParamList extends ReactNavigation.RootParamList, RouteName extends keyof ParamList = keyof ParamList> = ({
|
|
5
|
+
screen: Extract<RouteName, string>;
|
|
6
|
+
href?: string;
|
|
7
7
|
action?: NavigationAction;
|
|
8
|
+
} & (undefined extends ParamList[RouteName] ? {
|
|
9
|
+
params?: ParamList[RouteName];
|
|
10
|
+
} : {
|
|
11
|
+
params: ParamList[RouteName];
|
|
12
|
+
})) | {
|
|
13
|
+
href?: string;
|
|
14
|
+
action: NavigationAction;
|
|
15
|
+
screen?: undefined;
|
|
16
|
+
params?: undefined;
|
|
8
17
|
};
|
|
9
18
|
/**
|
|
10
19
|
* Hook to get props for an anchor tag so it can work with in page navigation.
|
|
11
20
|
*
|
|
12
|
-
* @param props.
|
|
21
|
+
* @param props.screen Name of the screen to navigate to (e.g. `'Feeds'`).
|
|
22
|
+
* @param props.params Params to pass to the screen to navigate to (e.g. `{ sort: 'hot' }`).
|
|
23
|
+
* @param props.href Optional absolute path to use for the href (e.g. `/feeds/hot`).
|
|
13
24
|
* @param props.action Optional action to use for in-page navigation. By default, the path is parsed to an action based on linking config.
|
|
14
25
|
*/
|
|
15
|
-
export default function useLinkProps<ParamList extends ReactNavigation.RootParamList>({
|
|
16
|
-
href: string;
|
|
26
|
+
export default function useLinkProps<ParamList extends ReactNavigation.RootParamList>({ screen, params, href, action }: Props<ParamList>): {
|
|
27
|
+
href: string | undefined;
|
|
17
28
|
accessibilityRole: "link";
|
|
18
29
|
onPress: (e?: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent) => void;
|
|
19
30
|
};
|
|
20
|
-
export {};
|
|
21
31
|
//# sourceMappingURL=useLinkProps.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLinkProps.d.ts","sourceRoot":"","sources":["../../../src/useLinkProps.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EAKjB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAY,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"useLinkProps.d.ts","sourceRoot":"","sources":["../../../src/useLinkProps.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EAKjB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAY,MAAM,cAAc,CAAC;AAI/D,MAAM,MAAM,KAAK,CACf,SAAS,SAAS,eAAe,CAAC,aAAa,EAC/C,SAAS,SAAS,MAAM,SAAS,GAAG,MAAM,SAAS,IAEjD,CAAC;IACC,MAAM,EAAE,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC3B,GAAG,CAAC,SAAS,SAAS,SAAS,CAAC,SAAS,CAAC,GACvC;IAAE,MAAM,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAA;CAAE,GACjC;IAAE,MAAM,EAAE,SAAS,CAAC,SAAS,CAAC,CAAA;CAAE,CAAC,CAAC,GACtC;IACE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,gBAAgB,CAAC;IACzB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,MAAM,CAAC,EAAE,SAAS,CAAC;CACpB,CAAC;AA+BN;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,SAAS,SAAS,eAAe,CAAC,aAAa,EAC/C,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC;;;kBAM5C,gBAAgB,CAAC,iBAAiB,EAAE,UAAU,CAAC,GAAG,qBAAqB;EA6D9E"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CommonActions } from '@react-navigation/core';
|
|
2
|
+
/**
|
|
3
|
+
* Build destination link for a navigate action.
|
|
4
|
+
* Useful for showing anchor tags on the web for buttons that perform navigation.
|
|
5
|
+
*/
|
|
6
|
+
export default function useLinkTools(): {
|
|
7
|
+
buildHref: (name: string, params?: object) => string | undefined;
|
|
8
|
+
buildAction: (href: string) => {
|
|
9
|
+
type: "NAVIGATE";
|
|
10
|
+
payload: {
|
|
11
|
+
name: string;
|
|
12
|
+
params?: import("@react-navigation/core").NavigatorScreenParams<Readonly<{
|
|
13
|
+
key: string;
|
|
14
|
+
index: number;
|
|
15
|
+
routeNames: string[];
|
|
16
|
+
history?: unknown[] | undefined;
|
|
17
|
+
routes: (Readonly<{
|
|
18
|
+
key: string;
|
|
19
|
+
name: string;
|
|
20
|
+
path?: string | undefined;
|
|
21
|
+
}> & Readonly<{
|
|
22
|
+
params?: Readonly<object | undefined>;
|
|
23
|
+
}> & {
|
|
24
|
+
state?: Readonly<any> | import("@react-navigation/core").PartialState<Readonly<any>> | undefined;
|
|
25
|
+
})[];
|
|
26
|
+
type: string;
|
|
27
|
+
stale: false;
|
|
28
|
+
}>>;
|
|
29
|
+
path?: string | undefined;
|
|
30
|
+
};
|
|
31
|
+
} | CommonActions.Action;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=useLinkTools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLinkTools.d.ts","sourceRoot":"","sources":["../../../src/useLinkTools.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAQd,MAAM,wBAAwB,CAAC;AAqChC;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY;sBAKzB,MAAM,WAAW,MAAM;wBA6BvB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;EA0BhB"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { NavigationContainerRef, ParamListBase } from '@react-navigation/core';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import type { LinkingOptions } from './types';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
export default function useLinking(ref: React.RefObject<NavigationContainerRef<ParamListBase>>, { independent, enabled, config, getStateFromPath, getPathFromState, getActionFromState, }: Options): {
|
|
4
|
+
type Options = LinkingOptions<ParamListBase>;
|
|
5
|
+
export default function useLinking(ref: React.RefObject<NavigationContainerRef<ParamListBase>>, { enabled, config, getStateFromPath, getPathFromState, getActionFromState, }: Options): {
|
|
8
6
|
getInitialState: () => PromiseLike<(Partial<Omit<Readonly<{
|
|
9
7
|
key: string;
|
|
10
8
|
index: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLinking.d.ts","sourceRoot":"","sources":["../../../src/useLinking.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,sBAAsB,EAEtB,aAAa,
|
|
1
|
+
{"version":3,"file":"useLinking.d.ts","sourceRoot":"","sources":["../../../src/useLinking.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,sBAAsB,EAEtB,aAAa,EAEd,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAiF9C,KAAK,OAAO,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;AAE7C,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAC,EAC3D,EACE,OAAc,EACd,MAAM,EACN,gBAA0C,EAC1C,gBAA0C,EAC1C,kBAA8C,GAC/C,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwTX"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { NavigationContainerRef, ParamListBase } from '@react-navigation/core';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import type { LinkingOptions } from './types';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
export default function useLinking(ref: React.RefObject<NavigationContainerRef<ParamListBase>>, { independent, enabled, prefixes, filter, config, getInitialURL, subscribe, getStateFromPath, getActionFromState, }: Options): {
|
|
4
|
+
type Options = LinkingOptions<ParamListBase>;
|
|
5
|
+
export default function useLinking(ref: React.RefObject<NavigationContainerRef<ParamListBase>>, { enabled, prefixes, filter, config, getInitialURL, subscribe, getStateFromPath, getActionFromState, }: Options): {
|
|
8
6
|
getInitialState: () => PromiseLike<(Partial<Omit<Readonly<{
|
|
9
7
|
key: string;
|
|
10
8
|
index: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLinking.native.d.ts","sourceRoot":"","sources":["../../../src/useLinking.native.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,sBAAsB,EACtB,aAAa,
|
|
1
|
+
{"version":3,"file":"useLinking.native.d.ts","sourceRoot":"","sources":["../../../src/useLinking.native.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,sBAAsB,EACtB,aAAa,EAEd,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAI9C,KAAK,OAAO,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;AAI7C,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAC,EAC3D,EACE,OAAc,EACd,QAAQ,EACR,MAAM,EACN,MAAM,EACN,aAQI,EACJ,SAmBC,EACD,gBAA0C,EAC1C,kBAA8C,GAC/C,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6JX"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import type { ScrollView } from 'react-native';
|
|
3
|
-
|
|
3
|
+
type ScrollOptions = {
|
|
4
4
|
x?: number;
|
|
5
5
|
y?: number;
|
|
6
6
|
animated?: boolean;
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
type ScrollableView = {
|
|
9
9
|
scrollToTop(): void;
|
|
10
10
|
} | {
|
|
11
11
|
scrollTo(options: ScrollOptions): void;
|
|
@@ -17,7 +17,7 @@ declare type ScrollableView = {
|
|
|
17
17
|
} | {
|
|
18
18
|
scrollResponderScrollTo(options: ScrollOptions): void;
|
|
19
19
|
};
|
|
20
|
-
|
|
20
|
+
type ScrollableWrapper = {
|
|
21
21
|
getScrollResponder(): React.ReactNode | ScrollView;
|
|
22
22
|
} | {
|
|
23
23
|
getNode(): ScrollableView;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useScrollToTop.d.ts","sourceRoot":"","sources":["../../../src/useScrollToTop.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,
|
|
1
|
+
{"version":3,"file":"useScrollToTop.d.ts","sourceRoot":"","sources":["../../../src/useScrollToTop.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,KAAK,aAAa,GAAG;IAAE,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEpE,KAAK,cAAc,GACf;IAAE,WAAW,IAAI,IAAI,CAAA;CAAE,GACvB;IAAE,QAAQ,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAAA;CAAE,GAC1C;IAAE,cAAc,CAAC,OAAO,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAA;CAAE,GAC1E;IAAE,uBAAuB,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAAA;CAAE,CAAC;AAE9D,KAAK,iBAAiB,GAClB;IAAE,kBAAkB,IAAI,KAAK,CAAC,SAAS,GAAG,UAAU,CAAA;CAAE,GACtD;IAAE,OAAO,IAAI,cAAc,CAAA;CAAE,GAC7B,cAAc,CAAC;AA8BnB,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,iBAAiB,CAAC,QAgExC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-navigation/native",
|
|
3
3
|
"description": "React Native integration for React Navigation",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "7.0.0-alpha.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
7
7
|
"react-navigation",
|
|
@@ -37,22 +37,22 @@
|
|
|
37
37
|
"clean": "del lib"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@react-navigation/core": "^
|
|
40
|
+
"@react-navigation/core": "^7.0.0-alpha.0",
|
|
41
41
|
"escape-string-regexp": "^4.0.0",
|
|
42
42
|
"fast-deep-equal": "^3.1.3",
|
|
43
43
|
"nanoid": "^3.1.23"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@testing-library/react-native": "^11.5.0",
|
|
47
|
-
"@types/react": "~18.0.
|
|
48
|
-
"@types/react-dom": "~18.0.
|
|
49
|
-
"@types/react-native": "~0.
|
|
50
|
-
"del-cli": "^
|
|
51
|
-
"react": "18.
|
|
52
|
-
"react-dom": "18.
|
|
53
|
-
"react-native": "0.
|
|
47
|
+
"@types/react": "~18.0.26",
|
|
48
|
+
"@types/react-dom": "~18.0.9",
|
|
49
|
+
"@types/react-native": "~0.70.8",
|
|
50
|
+
"del-cli": "^5.0.0",
|
|
51
|
+
"react": "18.1.0",
|
|
52
|
+
"react-dom": "18.2.0",
|
|
53
|
+
"react-native": "0.70.5",
|
|
54
54
|
"react-native-builder-bob": "^0.20.3",
|
|
55
|
-
"typescript": "^4.
|
|
55
|
+
"typescript": "^4.9.4"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"react": "*",
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
]
|
|
73
73
|
]
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "ad722b882e0c40b1d1bc025d70112ddb126f265e"
|
|
76
76
|
}
|
package/src/Link.tsx
CHANGED
|
@@ -1,33 +1,40 @@
|
|
|
1
|
-
import type { NavigationAction } from '@react-navigation/core';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { GestureResponderEvent, Platform, Text, TextProps } from 'react-native';
|
|
4
3
|
|
|
5
|
-
import useLinkProps from './useLinkProps';
|
|
6
|
-
import type { To } from './useLinkTo';
|
|
4
|
+
import useLinkProps, { Props as LinkProps } from './useLinkProps';
|
|
7
5
|
|
|
8
|
-
type Props<ParamList extends ReactNavigation.RootParamList> =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
type Props<ParamList extends ReactNavigation.RootParamList> =
|
|
7
|
+
LinkProps<ParamList> &
|
|
8
|
+
Omit<TextProps, 'disabled'> & {
|
|
9
|
+
target?: string;
|
|
10
|
+
onPress?: (
|
|
11
|
+
e:
|
|
12
|
+
| React.MouseEvent<HTMLAnchorElement, MouseEvent>
|
|
13
|
+
| GestureResponderEvent
|
|
14
|
+
) => void;
|
|
15
|
+
disabled?: boolean | null;
|
|
16
|
+
children: React.ReactNode;
|
|
17
|
+
};
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
20
|
* Component to render link to another screen using a path.
|
|
19
21
|
* Uses an anchor tag on the web.
|
|
20
22
|
*
|
|
21
|
-
* @param props.
|
|
23
|
+
* @param props.screen Name of the screen to navigate to (e.g. `'Feeds'`).
|
|
24
|
+
* @param props.params Params to pass to the screen to navigate to (e.g. `{ sort: 'hot' }`).
|
|
25
|
+
* @param props.href Optional absolute path to use for the href (e.g. `/feeds/hot`).
|
|
22
26
|
* @param props.action Optional action to use for in-page navigation. By default, the path is parsed to an action based on linking config.
|
|
23
27
|
* @param props.children Child elements to render the content.
|
|
24
28
|
*/
|
|
25
29
|
export default function Link<ParamList extends ReactNavigation.RootParamList>({
|
|
26
|
-
|
|
30
|
+
screen,
|
|
31
|
+
params,
|
|
27
32
|
action,
|
|
33
|
+
href,
|
|
28
34
|
...rest
|
|
29
35
|
}: Props<ParamList>) {
|
|
30
|
-
|
|
36
|
+
// @ts-expect-error: This is already type-checked by the prop types
|
|
37
|
+
const props = useLinkProps<ParamList>({ screen, params, action, href });
|
|
31
38
|
|
|
32
39
|
const onPress = (
|
|
33
40
|
e: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent
|
|
@@ -36,7 +43,10 @@ export default function Link<ParamList extends ReactNavigation.RootParamList>({
|
|
|
36
43
|
rest.onPress?.(e);
|
|
37
44
|
}
|
|
38
45
|
|
|
39
|
-
|
|
46
|
+
// Let user prevent default behavior
|
|
47
|
+
if (!e.defaultPrevented) {
|
|
48
|
+
props.onPress(e);
|
|
49
|
+
}
|
|
40
50
|
};
|
|
41
51
|
|
|
42
52
|
return React.createElement(Text, {
|
|
@@ -33,7 +33,6 @@ type Props<ParamList extends {}> = NavigationContainerProps & {
|
|
|
33
33
|
linking?: LinkingOptions<ParamList>;
|
|
34
34
|
fallback?: React.ReactNode;
|
|
35
35
|
documentTitle?: DocumentTitleOptions;
|
|
36
|
-
onReady?: () => void;
|
|
37
36
|
};
|
|
38
37
|
|
|
39
38
|
/**
|
|
@@ -43,6 +42,7 @@ type Props<ParamList extends {}> = NavigationContainerProps & {
|
|
|
43
42
|
* @param props.initialState Initial state object for the navigation tree. When deep link handling is enabled, this will override deep links when specified. Make sure that you don't specify an `initialState` when there's a deep link (`Linking.getInitialURL()`).
|
|
44
43
|
* @param props.onReady Callback which is called after the navigation tree mounts.
|
|
45
44
|
* @param props.onStateChange Callback which is called with the latest navigation state when it changes.
|
|
45
|
+
* @param props.onUnhandledAction Callback which is called when an action is not handled.
|
|
46
46
|
* @param props.theme Theme object for the navigators.
|
|
47
47
|
* @param props.linking Options for deep linking. Deep link handling is enabled when this prop is provided, unless `linking.enabled` is `false`.
|
|
48
48
|
* @param props.fallback Fallback component to render until we have finished getting initial state when linking is enabled. Defaults to `null`.
|
|
@@ -56,7 +56,6 @@ function NavigationContainerInner(
|
|
|
56
56
|
linking,
|
|
57
57
|
fallback = null,
|
|
58
58
|
documentTitle,
|
|
59
|
-
onReady,
|
|
60
59
|
...rest
|
|
61
60
|
}: Props<ParamListBase>,
|
|
62
61
|
ref?: React.Ref<NavigationContainerRef<ParamListBase> | null>
|
|
@@ -74,7 +73,6 @@ function NavigationContainerInner(
|
|
|
74
73
|
useDocumentTitle(refContainer, documentTitle);
|
|
75
74
|
|
|
76
75
|
const { getInitialState } = useLinking(refContainer, {
|
|
77
|
-
independent: rest.independent,
|
|
78
76
|
enabled: isLinkingEnabled,
|
|
79
77
|
prefixes: [],
|
|
80
78
|
...linking,
|
|
@@ -106,21 +104,10 @@ function NavigationContainerInner(
|
|
|
106
104
|
|
|
107
105
|
const linkingContext = React.useMemo(() => ({ options: linking }), [linking]);
|
|
108
106
|
|
|
109
|
-
const
|
|
107
|
+
const isLinkingReady =
|
|
108
|
+
rest.initialState != null || !isLinkingEnabled || isResolved;
|
|
110
109
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
React.useEffect(() => {
|
|
114
|
-
onReadyRef.current = onReady;
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
React.useEffect(() => {
|
|
118
|
-
if (isReady) {
|
|
119
|
-
onReadyRef.current?.();
|
|
120
|
-
}
|
|
121
|
-
}, [isReady]);
|
|
122
|
-
|
|
123
|
-
if (!isReady) {
|
|
110
|
+
if (!isLinkingReady) {
|
|
124
111
|
// This is temporary until we have Suspense for data-fetching
|
|
125
112
|
// Then the fallback will be handled by a parent `Suspense` component
|
|
126
113
|
return fallback as React.ReactElement;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createNavigatorFactory,
|
|
3
|
+
StackRouter,
|
|
4
|
+
useNavigationBuilder,
|
|
5
|
+
} from '@react-navigation/core';
|
|
6
|
+
import * as React from 'react';
|
|
7
|
+
|
|
8
|
+
const createStackNavigator = createNavigatorFactory((props) => {
|
|
9
|
+
const { state, descriptors, NavigationContent } = useNavigationBuilder(
|
|
10
|
+
StackRouter,
|
|
11
|
+
props
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<NavigationContent>
|
|
16
|
+
{descriptors[state.routes[state.index].key].render()}
|
|
17
|
+
</NavigationContent>
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export default createStackNavigator;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createComponentForStaticNavigation,
|
|
3
|
+
createPathConfigForStaticNavigation,
|
|
4
|
+
ParamListBase,
|
|
5
|
+
StaticNavigation,
|
|
6
|
+
} from '@react-navigation/core';
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
|
|
9
|
+
import NavigationContainer from './NavigationContainer';
|
|
10
|
+
import type { LinkingOptions } from './types';
|
|
11
|
+
|
|
12
|
+
type Props = Omit<
|
|
13
|
+
React.ComponentProps<typeof NavigationContainer>,
|
|
14
|
+
'linking' | 'children'
|
|
15
|
+
> & {
|
|
16
|
+
/**
|
|
17
|
+
* Options for deep linking.
|
|
18
|
+
*/
|
|
19
|
+
linking?: Omit<LinkingOptions<ParamListBase>, 'config'>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Create a navigation component from a static navigation config.
|
|
24
|
+
* The returned component is a wrapper around `NavigationContainer`.
|
|
25
|
+
*
|
|
26
|
+
* @param tree Static navigation config.
|
|
27
|
+
* @returns Navigation component to use in your app.
|
|
28
|
+
*/
|
|
29
|
+
export default function createStaticNavigation(
|
|
30
|
+
tree: StaticNavigation<any, any, any>
|
|
31
|
+
) {
|
|
32
|
+
const Component = createComponentForStaticNavigation(tree, 'RootNavigator');
|
|
33
|
+
const linkingConfig = {
|
|
34
|
+
screens: tree.config.screens
|
|
35
|
+
? createPathConfigForStaticNavigation(tree)
|
|
36
|
+
: {},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return function Navigation({ linking, ...rest }: Props) {
|
|
40
|
+
return (
|
|
41
|
+
<NavigationContainer
|
|
42
|
+
{...rest}
|
|
43
|
+
linking={linking ? { ...linking, config: linkingConfig } : undefined}
|
|
44
|
+
>
|
|
45
|
+
<Component />
|
|
46
|
+
</NavigationContainer>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { default as createStaticNavigation } from './createStaticNavigation';
|
|
1
2
|
export { default as Link } from './Link';
|
|
2
3
|
export { default as LinkingContext } from './LinkingContext';
|
|
3
4
|
export { default as NavigationContainer } from './NavigationContainer';
|
|
@@ -7,8 +8,7 @@ export { default as DefaultTheme } from './theming/DefaultTheme';
|
|
|
7
8
|
export { default as ThemeProvider } from './theming/ThemeProvider';
|
|
8
9
|
export { default as useTheme } from './theming/useTheme';
|
|
9
10
|
export * from './types';
|
|
10
|
-
export { default as useLinkBuilder } from './useLinkBuilder';
|
|
11
11
|
export { default as useLinkProps } from './useLinkProps';
|
|
12
|
-
export { default as
|
|
12
|
+
export { default as useLinkTools } from './useLinkTools';
|
|
13
13
|
export { default as useScrollToTop } from './useScrollToTop';
|
|
14
14
|
export * from '@react-navigation/core';
|
package/src/useLinkProps.tsx
CHANGED
|
@@ -11,15 +11,27 @@ import * as React from 'react';
|
|
|
11
11
|
import { GestureResponderEvent, Platform } from 'react-native';
|
|
12
12
|
|
|
13
13
|
import LinkingContext from './LinkingContext';
|
|
14
|
-
import useLinkTo, { To } from './useLinkTo';
|
|
15
14
|
|
|
16
|
-
type Props<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
export type Props<
|
|
16
|
+
ParamList extends ReactNavigation.RootParamList,
|
|
17
|
+
RouteName extends keyof ParamList = keyof ParamList
|
|
18
|
+
> =
|
|
19
|
+
| ({
|
|
20
|
+
screen: Extract<RouteName, string>;
|
|
21
|
+
href?: string;
|
|
22
|
+
action?: NavigationAction;
|
|
23
|
+
} & (undefined extends ParamList[RouteName]
|
|
24
|
+
? { params?: ParamList[RouteName] }
|
|
25
|
+
: { params: ParamList[RouteName] }))
|
|
26
|
+
| {
|
|
27
|
+
href?: string;
|
|
28
|
+
action: NavigationAction;
|
|
29
|
+
screen?: undefined;
|
|
30
|
+
params?: undefined;
|
|
31
|
+
};
|
|
20
32
|
|
|
21
33
|
const getStateFromParams = (
|
|
22
|
-
params: NavigatorScreenParams<ParamListBase
|
|
34
|
+
params: NavigatorScreenParams<ParamListBase> | undefined
|
|
23
35
|
): PartialState<NavigationState> | NavigationState | undefined => {
|
|
24
36
|
if (params?.state) {
|
|
25
37
|
return params.state;
|
|
@@ -35,7 +47,7 @@ const getStateFromParams = (
|
|
|
35
47
|
state: params.screen
|
|
36
48
|
? getStateFromParams(
|
|
37
49
|
params.params as
|
|
38
|
-
| NavigatorScreenParams<ParamListBase
|
|
50
|
+
| NavigatorScreenParams<ParamListBase>
|
|
39
51
|
| undefined
|
|
40
52
|
)
|
|
41
53
|
: undefined,
|
|
@@ -50,16 +62,17 @@ const getStateFromParams = (
|
|
|
50
62
|
/**
|
|
51
63
|
* Hook to get props for an anchor tag so it can work with in page navigation.
|
|
52
64
|
*
|
|
53
|
-
* @param props.
|
|
65
|
+
* @param props.screen Name of the screen to navigate to (e.g. `'Feeds'`).
|
|
66
|
+
* @param props.params Params to pass to the screen to navigate to (e.g. `{ sort: 'hot' }`).
|
|
67
|
+
* @param props.href Optional absolute path to use for the href (e.g. `/feeds/hot`).
|
|
54
68
|
* @param props.action Optional action to use for in-page navigation. By default, the path is parsed to an action based on linking config.
|
|
55
69
|
*/
|
|
56
70
|
export default function useLinkProps<
|
|
57
71
|
ParamList extends ReactNavigation.RootParamList
|
|
58
|
-
>({
|
|
72
|
+
>({ screen, params, href, action }: Props<ParamList>) {
|
|
59
73
|
const root = React.useContext(NavigationContainerRefContext);
|
|
60
74
|
const navigation = React.useContext(NavigationHelpersContext);
|
|
61
75
|
const { options } = React.useContext(LinkingContext);
|
|
62
|
-
const linkTo = useLinkTo<ParamList>();
|
|
63
76
|
|
|
64
77
|
const onPress = (
|
|
65
78
|
e?: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent
|
|
@@ -93,33 +106,33 @@ export default function useLinkProps<
|
|
|
93
106
|
);
|
|
94
107
|
}
|
|
95
108
|
} else {
|
|
96
|
-
|
|
109
|
+
// @ts-expect-error: This is already type-checked by the prop types
|
|
110
|
+
navigation?.navigate(screen, params);
|
|
97
111
|
}
|
|
98
112
|
}
|
|
99
113
|
};
|
|
100
114
|
|
|
101
115
|
const getPathFromStateHelper = options?.getPathFromState ?? getPathFromState;
|
|
102
116
|
|
|
103
|
-
const href =
|
|
104
|
-
typeof to === 'string'
|
|
105
|
-
? to
|
|
106
|
-
: getPathFromStateHelper(
|
|
107
|
-
{
|
|
108
|
-
routes: [
|
|
109
|
-
{
|
|
110
|
-
name: to.screen,
|
|
111
|
-
// @ts-expect-error
|
|
112
|
-
params: to.params,
|
|
113
|
-
// @ts-expect-error
|
|
114
|
-
state: getStateFromParams(to.params),
|
|
115
|
-
},
|
|
116
|
-
],
|
|
117
|
-
},
|
|
118
|
-
options?.config
|
|
119
|
-
);
|
|
120
|
-
|
|
121
117
|
return {
|
|
122
|
-
href
|
|
118
|
+
href:
|
|
119
|
+
href ??
|
|
120
|
+
(Platform.OS === 'web' && screen != null
|
|
121
|
+
? getPathFromStateHelper(
|
|
122
|
+
{
|
|
123
|
+
routes: [
|
|
124
|
+
{
|
|
125
|
+
name: screen,
|
|
126
|
+
// @ts-expect-error
|
|
127
|
+
params: params,
|
|
128
|
+
// @ts-expect-error
|
|
129
|
+
state: getStateFromParams(params),
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
options?.config
|
|
134
|
+
)
|
|
135
|
+
: undefined),
|
|
123
136
|
accessibilityRole: 'link' as const,
|
|
124
137
|
onPress,
|
|
125
138
|
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
+
CommonActions,
|
|
3
|
+
getActionFromState,
|
|
2
4
|
getPathFromState,
|
|
5
|
+
getStateFromPath,
|
|
3
6
|
NavigationHelpers,
|
|
4
7
|
NavigationHelpersContext,
|
|
5
8
|
NavigationProp,
|
|
@@ -45,11 +48,11 @@ const getRootStateForNavigate = (
|
|
|
45
48
|
* Build destination link for a navigate action.
|
|
46
49
|
* Useful for showing anchor tags on the web for buttons that perform navigation.
|
|
47
50
|
*/
|
|
48
|
-
export default function
|
|
51
|
+
export default function useLinkTools() {
|
|
49
52
|
const navigation = React.useContext(NavigationHelpersContext);
|
|
50
53
|
const linking = React.useContext(LinkingContext);
|
|
51
54
|
|
|
52
|
-
const
|
|
55
|
+
const buildHref = React.useCallback(
|
|
53
56
|
(name: string, params?: object) => {
|
|
54
57
|
const { options } = linking;
|
|
55
58
|
|
|
@@ -78,5 +81,31 @@ export default function useLinkBuilder() {
|
|
|
78
81
|
[linking, navigation]
|
|
79
82
|
);
|
|
80
83
|
|
|
81
|
-
|
|
84
|
+
const buildAction = React.useCallback(
|
|
85
|
+
(href: string) => {
|
|
86
|
+
if (!href.startsWith('/')) {
|
|
87
|
+
throw new Error(`The path must start with '/' (${href}).`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const { options } = linking;
|
|
91
|
+
|
|
92
|
+
const state = options?.getStateFromPath
|
|
93
|
+
? options.getStateFromPath(href, options.config)
|
|
94
|
+
: getStateFromPath(href, options?.config);
|
|
95
|
+
|
|
96
|
+
if (state) {
|
|
97
|
+
const action = getActionFromState(state, options?.config);
|
|
98
|
+
|
|
99
|
+
return action ?? CommonActions.reset(state);
|
|
100
|
+
} else {
|
|
101
|
+
throw new Error('Failed to parse the path to a navigation state.');
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
[linking]
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
buildHref,
|
|
109
|
+
buildAction,
|
|
110
|
+
};
|
|
82
111
|
}
|