@react-navigation/native 6.0.3 → 6.0.7
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 +6 -5
- package/lib/commonjs/Link.js.map +1 -1
- package/lib/commonjs/NavigationContainer.js +9 -8
- package/lib/commonjs/NavigationContainer.js.map +1 -1
- package/lib/commonjs/ServerContainer.js +5 -4
- package/lib/commonjs/ServerContainer.js.map +1 -1
- package/lib/commonjs/ServerContext.js.map +1 -1
- package/lib/commonjs/index.js +16 -16
- package/lib/commonjs/theming/ThemeProvider.js +5 -4
- package/lib/commonjs/theming/ThemeProvider.js.map +1 -1
- package/lib/commonjs/useDocumentTitle.js +9 -8
- package/lib/commonjs/useDocumentTitle.js.map +1 -1
- package/lib/commonjs/useLinkProps.js +32 -8
- package/lib/commonjs/useLinkProps.js.map +1 -1
- package/lib/commonjs/useLinking.js +60 -40
- package/lib/commonjs/useLinking.js.map +1 -1
- package/lib/commonjs/useLinking.native.js +34 -29
- package/lib/commonjs/useLinking.native.js.map +1 -1
- package/lib/module/Link.js +6 -5
- package/lib/module/Link.js.map +1 -1
- package/lib/module/NavigationContainer.js +9 -8
- package/lib/module/NavigationContainer.js.map +1 -1
- package/lib/module/ServerContainer.js +5 -4
- package/lib/module/ServerContainer.js.map +1 -1
- package/lib/module/ServerContext.js.map +1 -1
- package/lib/module/theming/ThemeProvider.js +5 -4
- package/lib/module/theming/ThemeProvider.js.map +1 -1
- package/lib/module/useDocumentTitle.js +8 -7
- package/lib/module/useDocumentTitle.js.map +1 -1
- package/lib/module/useLinkProps.js +32 -8
- package/lib/module/useLinkProps.js.map +1 -1
- package/lib/module/useLinking.js +57 -38
- package/lib/module/useLinking.js.map +1 -1
- package/lib/module/useLinking.native.js +33 -28
- package/lib/module/useLinking.native.js.map +1 -1
- package/package.json +7 -6
- package/src/ServerContext.tsx +3 -2
- package/src/useLinkProps.tsx +39 -1
- package/src/useLinking.native.tsx +6 -1
- package/src/useLinking.tsx +46 -15
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": "6.0.
|
|
4
|
+
"version": "6.0.7",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
7
7
|
"react-navigation",
|
|
@@ -37,8 +37,9 @@
|
|
|
37
37
|
"clean": "del lib"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@react-navigation/core": "^6.
|
|
40
|
+
"@react-navigation/core": "^6.1.1",
|
|
41
41
|
"escape-string-regexp": "^4.0.0",
|
|
42
|
+
"fast-deep-equal": "^3.1.3",
|
|
42
43
|
"nanoid": "^3.1.23"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
@@ -47,9 +48,9 @@
|
|
|
47
48
|
"@types/react-dom": "^17.0.6",
|
|
48
49
|
"@types/react-native": "~0.64.9",
|
|
49
50
|
"del-cli": "^3.0.1",
|
|
50
|
-
"react": "
|
|
51
|
-
"react-dom": "
|
|
52
|
-
"react-native": "~0.
|
|
51
|
+
"react": "17.0.1",
|
|
52
|
+
"react-dom": "17.0.1",
|
|
53
|
+
"react-native": "~0.64.3",
|
|
53
54
|
"react-native-builder-bob": "^0.18.1",
|
|
54
55
|
"typescript": "^4.3.2"
|
|
55
56
|
},
|
|
@@ -71,5 +72,5 @@
|
|
|
71
72
|
]
|
|
72
73
|
]
|
|
73
74
|
},
|
|
74
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "4c5805867ce946d99ba17f71b4d6086bb8751262"
|
|
75
76
|
}
|
package/src/ServerContext.tsx
CHANGED
|
@@ -7,7 +7,8 @@ export type ServerContextType = {
|
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
const ServerContext =
|
|
11
|
-
|
|
10
|
+
const ServerContext = React.createContext<ServerContextType | undefined>(
|
|
11
|
+
undefined
|
|
12
|
+
);
|
|
12
13
|
|
|
13
14
|
export default ServerContext;
|
package/src/useLinkProps.tsx
CHANGED
|
@@ -3,7 +3,10 @@ import {
|
|
|
3
3
|
NavigationAction,
|
|
4
4
|
NavigationContainerRefContext,
|
|
5
5
|
NavigationHelpersContext,
|
|
6
|
+
NavigatorScreenParams,
|
|
7
|
+
ParamListBase,
|
|
6
8
|
} from '@react-navigation/core';
|
|
9
|
+
import type { NavigationState, PartialState } from '@react-navigation/routers';
|
|
7
10
|
import * as React from 'react';
|
|
8
11
|
import { GestureResponderEvent, Platform } from 'react-native';
|
|
9
12
|
|
|
@@ -15,6 +18,35 @@ type Props<ParamList extends ReactNavigation.RootParamList> = {
|
|
|
15
18
|
action?: NavigationAction;
|
|
16
19
|
};
|
|
17
20
|
|
|
21
|
+
const getStateFromParams = (
|
|
22
|
+
params: NavigatorScreenParams<ParamListBase, NavigationState> | undefined
|
|
23
|
+
): PartialState<NavigationState> | NavigationState | undefined => {
|
|
24
|
+
if (params?.state) {
|
|
25
|
+
return params.state;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (params?.screen) {
|
|
29
|
+
return {
|
|
30
|
+
routes: [
|
|
31
|
+
{
|
|
32
|
+
name: params.screen,
|
|
33
|
+
params: params.params,
|
|
34
|
+
// @ts-expect-error
|
|
35
|
+
state: params.screen
|
|
36
|
+
? getStateFromParams(
|
|
37
|
+
params.params as
|
|
38
|
+
| NavigatorScreenParams<ParamListBase, NavigationState>
|
|
39
|
+
| undefined
|
|
40
|
+
)
|
|
41
|
+
: undefined,
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return undefined;
|
|
48
|
+
};
|
|
49
|
+
|
|
18
50
|
/**
|
|
19
51
|
* Hook to get props for an anchor tag so it can work with in page navigation.
|
|
20
52
|
*
|
|
@@ -74,7 +106,13 @@ export default function useLinkProps<
|
|
|
74
106
|
: getPathFromStateHelper(
|
|
75
107
|
{
|
|
76
108
|
routes: [
|
|
77
|
-
{
|
|
109
|
+
{
|
|
110
|
+
name: to.screen,
|
|
111
|
+
// @ts-expect-error
|
|
112
|
+
params: to.params,
|
|
113
|
+
// @ts-expect-error
|
|
114
|
+
state: getStateFromParams(to.params),
|
|
115
|
+
},
|
|
78
116
|
],
|
|
79
117
|
},
|
|
80
118
|
options?.config
|
|
@@ -189,7 +189,12 @@ export default function useLinking(
|
|
|
189
189
|
// Ignore any errors from deep linking.
|
|
190
190
|
// This could happen in case of malformed links, navigation object not being initialized etc.
|
|
191
191
|
console.warn(
|
|
192
|
-
`An error occurred when trying to handle the link '${url}': ${
|
|
192
|
+
`An error occurred when trying to handle the link '${url}': ${
|
|
193
|
+
typeof e === 'object' && e != null && 'message' in e
|
|
194
|
+
? // @ts-expect-error: we're already checking for this
|
|
195
|
+
e.message
|
|
196
|
+
: e
|
|
197
|
+
}`
|
|
193
198
|
);
|
|
194
199
|
}
|
|
195
200
|
} else {
|
package/src/useLinking.tsx
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
NavigationState,
|
|
8
8
|
ParamListBase,
|
|
9
9
|
} from '@react-navigation/core';
|
|
10
|
+
import isEqual from 'fast-deep-equal';
|
|
10
11
|
import { nanoid } from 'nanoid/non-secure';
|
|
11
12
|
import * as React from 'react';
|
|
12
13
|
|
|
@@ -121,20 +122,14 @@ const createMemoryHistory = () => {
|
|
|
121
122
|
go(n: number) {
|
|
122
123
|
interrupt();
|
|
123
124
|
|
|
124
|
-
if (n > 0) {
|
|
125
|
-
// We shouldn't go forward more than available index
|
|
126
|
-
n = Math.min(n, items.length - 1);
|
|
127
|
-
} else if (n < 0) {
|
|
128
|
-
// We shouldn't go back more than the 0 index
|
|
129
|
-
// Otherwise we'll exit the page
|
|
130
|
-
n = index + n < 0 ? -index : n;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
125
|
if (n === 0) {
|
|
134
126
|
return;
|
|
135
127
|
}
|
|
136
128
|
|
|
137
|
-
index
|
|
129
|
+
// We shouldn't go back more than the 0 index (otherwise we'll exit the page)
|
|
130
|
+
// Or forward more than the available index (or the app will crash)
|
|
131
|
+
index =
|
|
132
|
+
n < 0 ? Math.max(index - n, 0) : Math.min(index + n, items.length - 1);
|
|
138
133
|
|
|
139
134
|
// When we call `history.go`, `popstate` will fire when there's history to go back to
|
|
140
135
|
// So we need to somehow handle following cases:
|
|
@@ -461,7 +456,12 @@ export default function useLinking(
|
|
|
461
456
|
// Ignore any errors from deep linking.
|
|
462
457
|
// This could happen in case of malformed links, navigation object not being initialized etc.
|
|
463
458
|
console.warn(
|
|
464
|
-
`An error occurred when trying to handle the link '${path}': ${
|
|
459
|
+
`An error occurred when trying to handle the link '${path}': ${
|
|
460
|
+
typeof e === 'object' && e != null && 'message' in e
|
|
461
|
+
? // @ts-expect-error: we're already checking for this
|
|
462
|
+
e.message
|
|
463
|
+
: e
|
|
464
|
+
}`
|
|
465
465
|
);
|
|
466
466
|
}
|
|
467
467
|
} else {
|
|
@@ -482,6 +482,34 @@ export default function useLinking(
|
|
|
482
482
|
return;
|
|
483
483
|
}
|
|
484
484
|
|
|
485
|
+
const getPathForRoute = (
|
|
486
|
+
route: ReturnType<typeof findFocusedRoute>,
|
|
487
|
+
state: NavigationState
|
|
488
|
+
): string => {
|
|
489
|
+
// If the `route` object contains a `path`, use that path as long as `route.name` and `params` still match
|
|
490
|
+
// This makes sure that we preserve the original URL for wildcard routes
|
|
491
|
+
if (route?.path) {
|
|
492
|
+
const stateForPath = getStateFromPathRef.current(
|
|
493
|
+
route.path,
|
|
494
|
+
configRef.current
|
|
495
|
+
);
|
|
496
|
+
|
|
497
|
+
if (stateForPath) {
|
|
498
|
+
const focusedRoute = findFocusedRoute(stateForPath);
|
|
499
|
+
|
|
500
|
+
if (
|
|
501
|
+
focusedRoute &&
|
|
502
|
+
focusedRoute.name === route.name &&
|
|
503
|
+
isEqual(focusedRoute.params, route.params)
|
|
504
|
+
) {
|
|
505
|
+
return route.path;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
return getPathFromStateRef.current(state, configRef.current);
|
|
511
|
+
};
|
|
512
|
+
|
|
485
513
|
if (ref.current) {
|
|
486
514
|
// We need to record the current metadata on the first render if they aren't set
|
|
487
515
|
// This will allow the initial state to be in the history entry
|
|
@@ -489,8 +517,7 @@ export default function useLinking(
|
|
|
489
517
|
|
|
490
518
|
if (state) {
|
|
491
519
|
const route = findFocusedRoute(state);
|
|
492
|
-
const path =
|
|
493
|
-
route?.path ?? getPathFromStateRef.current(state, configRef.current);
|
|
520
|
+
const path = getPathForRoute(route, state);
|
|
494
521
|
|
|
495
522
|
if (previousStateRef.current === undefined) {
|
|
496
523
|
previousStateRef.current = state;
|
|
@@ -510,10 +537,14 @@ export default function useLinking(
|
|
|
510
537
|
const previousState = previousStateRef.current;
|
|
511
538
|
const state = navigation.getRootState();
|
|
512
539
|
|
|
540
|
+
// root state may not available, for example when root navigators switch inside the container
|
|
541
|
+
if (!state) {
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
|
|
513
545
|
const pendingPath = pendingPopStatePathRef.current;
|
|
514
546
|
const route = findFocusedRoute(state);
|
|
515
|
-
const path =
|
|
516
|
-
route?.path ?? getPathFromStateRef.current(state, configRef.current);
|
|
547
|
+
const path = getPathForRoute(route, state);
|
|
517
548
|
|
|
518
549
|
previousStateRef.current = state;
|
|
519
550
|
pendingPopStatePathRef.current = undefined;
|