@amazon-devices/react-navigation__routers 7.0.9000000000 → 8.0.9000000000-rn-83
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/SystemBundles/b6cc62e27d70be8722b0e7aef9fd04a870d49127e6c724fe934d1f8ca4ff8177.bundle +1298 -0
- package/SystemBundles/b6cc62e27d70be8722b0e7aef9fd04a870d49127e6c724fe934d1f8ca4ff8177.map +373 -0
- package/SystemModules/amzn__react-navigation__routers-8.modules.txt +9 -0
- package/SystemModules/amzn__react-navigation__routers-8.private.modules.txt +1 -0
- package/SystemModules/keplerscript-system-bundle-config.json +4 -4
- package/kepler-compatibility.json +2 -2
- package/lib/module/BaseRouter.js +6 -4
- package/lib/module/BaseRouter.js.map +1 -1
- package/lib/module/CommonActions.js +48 -7
- package/lib/module/CommonActions.js.map +1 -1
- package/lib/module/DrawerRouter.js +6 -6
- package/lib/module/DrawerRouter.js.map +1 -1
- package/lib/module/StackRouter.js +261 -80
- package/lib/module/StackRouter.js.map +1 -1
- package/lib/module/TabRouter.js +117 -34
- package/lib/module/TabRouter.js.map +1 -1
- package/lib/module/createParamsFromAction.js +16 -0
- package/lib/module/createParamsFromAction.js.map +1 -0
- package/lib/module/createRouteFromAction.js +21 -0
- package/lib/module/createRouteFromAction.js.map +1 -0
- package/lib/module/index.js +8 -6
- package/lib/module/index.js.map +1 -1
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/BaseRouter.d.ts +23 -20
- package/lib/typescript/src/BaseRouter.d.ts.map +1 -1
- package/lib/typescript/src/CommonActions.d.ts +66 -18
- package/lib/typescript/src/CommonActions.d.ts.map +1 -1
- package/lib/typescript/src/DrawerRouter.d.ts +18 -6
- package/lib/typescript/src/DrawerRouter.d.ts.map +1 -1
- package/lib/typescript/src/StackRouter.d.ts +73 -11
- package/lib/typescript/src/StackRouter.d.ts.map +1 -1
- package/lib/typescript/src/TabRouter.d.ts +24 -4
- package/lib/typescript/src/TabRouter.d.ts.map +1 -1
- package/lib/typescript/src/createParamsFromAction.d.ts +13 -0
- package/lib/typescript/src/createParamsFromAction.d.ts.map +1 -0
- package/lib/typescript/src/createRouteFromAction.d.ts +17 -0
- package/lib/typescript/src/createRouteFromAction.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -4
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +1 -2
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/oss-attribution/attribution.txt +0 -0
- package/oss-attribution/licenseInfos.json +1 -0
- package/package.json +80 -1
- package/src/BaseRouter.tsx +11 -6
- package/src/CommonActions.tsx +147 -56
- package/src/DrawerRouter.tsx +15 -13
- package/src/StackRouter.tsx +437 -199
- package/src/TabRouter.tsx +192 -53
- package/src/createParamsFromAction.tsx +22 -0
- package/src/createRouteFromAction.tsx +24 -0
- package/src/index.tsx +4 -4
- package/src/types.tsx +5 -5
- package/SystemBundles/b274ab157641de9520fe27a8e8049450e176a8ce2fedd3283fcb46c038bc6247.bundle +0 -3497
- package/SystemBundles/b274ab157641de9520fe27a8e8049450e176a8ce2fedd3283fcb46c038bc6247.map +0 -987
- package/SystemModules/amzn__react-navigation__routers-7.modules.txt +0 -21
- package/SystemModules/amzn__react-navigation__routers-7.private.modules.txt +0 -12
- package/THIRD_PARTY_NOTICES.txt +0 -24
- package/lib/commonjs/BaseRouter.js +0 -61
- package/lib/commonjs/BaseRouter.js.map +0 -1
- package/lib/commonjs/CommonActions.js +0 -53
- package/lib/commonjs/CommonActions.js.map +0 -1
- package/lib/commonjs/DrawerRouter.js +0 -154
- package/lib/commonjs/DrawerRouter.js.map +0 -1
- package/lib/commonjs/StackRouter.js +0 -310
- package/lib/commonjs/StackRouter.js.map +0 -1
- package/lib/commonjs/TabRouter.js +0 -253
- package/lib/commonjs/TabRouter.js.map +0 -1
- package/lib/commonjs/index.js +0 -80
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/types.js +0 -6
- package/lib/commonjs/types.js.map +0 -1
|
@@ -1,16 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
1
3
|
export function goBack() {
|
|
2
4
|
return {
|
|
3
5
|
type: 'GO_BACK'
|
|
4
6
|
};
|
|
5
7
|
}
|
|
6
|
-
|
|
7
|
-
// eslint-disable-next-line no-redeclare
|
|
8
|
-
|
|
9
|
-
// eslint-disable-next-line no-redeclare
|
|
10
8
|
export function navigate(...args) {
|
|
11
9
|
if (typeof args[0] === 'string') {
|
|
10
|
+
const [name, params, options] = args;
|
|
11
|
+
if (typeof options === 'boolean') {
|
|
12
|
+
console.warn(`Passing a boolean as the third argument to 'navigate' is deprecated. Pass '{ merge: true }' instead.`);
|
|
13
|
+
}
|
|
12
14
|
return {
|
|
13
15
|
type: 'NAVIGATE',
|
|
16
|
+
payload: {
|
|
17
|
+
name,
|
|
18
|
+
params,
|
|
19
|
+
merge: typeof options === 'boolean' ? options : options?.merge,
|
|
20
|
+
pop: options?.pop
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
} else {
|
|
24
|
+
const payload = args[0] || {};
|
|
25
|
+
if (!('name' in payload)) {
|
|
26
|
+
throw new Error('You need to specify a name when calling navigate with an object as the argument. See https://reactnavigation.org/docs/navigation-actions#navigate for usage.');
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
type: 'NAVIGATE',
|
|
30
|
+
payload
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function navigateDeprecated(...args) {
|
|
35
|
+
if (typeof args[0] === 'string') {
|
|
36
|
+
return {
|
|
37
|
+
type: 'NAVIGATE_DEPRECATED',
|
|
14
38
|
payload: {
|
|
15
39
|
name: args[0],
|
|
16
40
|
params: args[1]
|
|
@@ -18,11 +42,11 @@ export function navigate(...args) {
|
|
|
18
42
|
};
|
|
19
43
|
} else {
|
|
20
44
|
const payload = args[0] || {};
|
|
21
|
-
if (!
|
|
22
|
-
throw new Error('You need to specify name
|
|
45
|
+
if (!('name' in payload)) {
|
|
46
|
+
throw new Error('You need to specify a name when calling navigateDeprecated with an object as the argument. See https://reactnavigation.org/docs/navigation-actions#navigatelegacy for usage.');
|
|
23
47
|
}
|
|
24
48
|
return {
|
|
25
|
-
type: '
|
|
49
|
+
type: 'NAVIGATE_DEPRECATED',
|
|
26
50
|
payload
|
|
27
51
|
};
|
|
28
52
|
}
|
|
@@ -41,4 +65,21 @@ export function setParams(params) {
|
|
|
41
65
|
}
|
|
42
66
|
};
|
|
43
67
|
}
|
|
68
|
+
export function replaceParams(params) {
|
|
69
|
+
return {
|
|
70
|
+
type: 'REPLACE_PARAMS',
|
|
71
|
+
payload: {
|
|
72
|
+
params
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export function preload(name, params) {
|
|
77
|
+
return {
|
|
78
|
+
type: 'PRELOAD',
|
|
79
|
+
payload: {
|
|
80
|
+
name,
|
|
81
|
+
params
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
44
85
|
//# sourceMappingURL=CommonActions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["goBack","type","navigate","args","
|
|
1
|
+
{"version":3,"names":["goBack","type","navigate","args","name","params","options","console","warn","payload","merge","pop","Error","navigateDeprecated","reset","state","setParams","replaceParams","preload"],"sourceRoot":"../../src","sources":["CommonActions.tsx"],"mappings":";;AA+EA,OAAO,SAASA,MAAMA,CAAA,EAAW;EAC/B,OAAO;IAAEC,IAAI,EAAE;EAAU,CAAC;AAC5B;AAmBA,OAAO,SAASC,QAAQA,CAAC,GAAGC,IAAS,EAAU;EAC7C,IAAI,OAAOA,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;IAC/B,MAAM,CAACC,IAAI,EAAEC,MAAM,EAAEC,OAAO,CAAC,GAAGH,IAAI;IAEpC,IAAI,O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Ac,EAAE;EACxC,OAAO;IACLJ,IAAI,EAAE,YAAY;IAClBQ,OAAO,EAAE;MAAEJ;IAAO;EACpB,CAAC;AACH;AAEA,OAAO,SAASY,aAAaA,CAACZ,MAAc,EAAE;EAC5C,OAAO;IACLJ,IAAI,EAAE,gBAAgB;IACtBQ,OAAO,EAAE;MAAEJ;IAAO;EACpB,CAAC;AACH;AAEA,OAAO,SAASa,OAAOA,CAACd,IAAY,EAAEC,MAAe,EAAE;EACrD,OAAO;IACLJ,IAAI,EAAE,SAAS;IACfQ,OAAO,EAAE;MAAEL,IAAI;MAAEC;IAAO;EAC1B,CAAC;AACH","ignoreList":[]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
1
3
|
import { nanoid } from 'nanoid/non-secure';
|
|
2
|
-
import
|
|
4
|
+
import { TabActions, TabRouter } from "./TabRouter.js";
|
|
3
5
|
export const DrawerActions = {
|
|
4
6
|
...TabActions,
|
|
5
7
|
openDrawer() {
|
|
@@ -18,15 +20,12 @@ export const DrawerActions = {
|
|
|
18
20
|
};
|
|
19
21
|
}
|
|
20
22
|
};
|
|
21
|
-
export
|
|
23
|
+
export function DrawerRouter({
|
|
22
24
|
defaultStatus = 'closed',
|
|
23
25
|
...rest
|
|
24
26
|
}) {
|
|
25
27
|
const router = TabRouter(rest);
|
|
26
|
-
const isDrawerInHistory = state =>
|
|
27
|
-
var _state$history;
|
|
28
|
-
return Boolean((_state$history = state.history) === null || _state$history === void 0 ? void 0 : _state$history.some(it => it.type === 'drawer'));
|
|
29
|
-
};
|
|
28
|
+
const isDrawerInHistory = state => Boolean(state.history?.some(it => it.type === 'drawer'));
|
|
30
29
|
const addDrawerToHistory = state => {
|
|
31
30
|
if (isDrawerInHistory(state)) {
|
|
32
31
|
return state;
|
|
@@ -123,6 +122,7 @@ export default function DrawerRouter({
|
|
|
123
122
|
return addDrawerToHistory(state);
|
|
124
123
|
case 'JUMP_TO':
|
|
125
124
|
case 'NAVIGATE':
|
|
125
|
+
case 'NAVIGATE_DEPRECATED':
|
|
126
126
|
{
|
|
127
127
|
const result = router.getStateForAction(state, action, options);
|
|
128
128
|
if (result != null && result.index !== state.index) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["nanoid","
|
|
1
|
+
{"version":3,"names":["nanoid","TabActions","TabRouter","DrawerActions","openDrawer","type","closeDrawer","toggleDrawer","DrawerRouter","defaultStatus","rest","router","isDrawerInHistory","state","Boolean","history","some","it","addDrawerToHistory","status","removeDrawerFromHistory","filter","getInitialState","routeNames","routeParamList","routeGetIdList","default","stale","key","getRehydratedState","partialState","getStateForRouteFocus","result","getStateForAction","action","options","index","actionCreators"],"sourceRoot":"../../src","sources":["DrawerRouter.tsx"],"mappings":";;AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAE1C,SAEEC,UAAU,EAGVC,SAAS,QAEJ,gBAAa;AA4DpB,OAAO,MAAMC,aAAa,GAAG;EAC3B,GAAGF,UAAU;EACbG,UAAUA,CAAA,EAAG;IACX,OAAO;MAAEC,IAAI,EAAE;IAAc,CAAC;EAChC,CAAC;EACDC,WAAWA,CAAA,EAAG;IACZ,OAAO;MAAED,IAAI,EAAE;IAAe,CAAC;EACjC,CAAC;EACDE,YAAYA,CAAA,EAAG;IACb,OAAO;MAAEF,IAAI,EAAE;IAAgB,CAAC;EAClC;AACF,CAAC;AAED,OAAO,SAASG,YAAYA,CAAC;EAC3BC,aAAa,GAAG,QAAQ;EACxB,GAAGC;AACgB,CAAC,EAGpB;EACA,MAAMC,MAAM,GAAGT,SAAS,CAACQ,IAAI,CAG5B;EAED,MAAME,iBAAiB,GACrBC,KAEsD,IACnDC,OAAO,CAACD,KAAK,CAACE,OAAO,EAAEC,IAAI,CAAEC,EAAE,IAAKA,EAAE,CAACZ,IAAI,KAAK,QAAQ,CAAC,CAAC;EAE/D,MAAMa,kBAAkB,GACtBL,KAA2C,IACF;IACzC,IAAID,iBAAiB,CAACC,KAAK,CAAC,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MAAM,GAAGrB,MAAM,CAACsB,iBAAiB,CAACpB,KAAK,EAAEqB,MAAM,EAAEC,OAAO,CAAC;YAE/D,IAAIH,MAAM,IAAI,IAAI,IAAIA,MAAM,CAACI,KAAK,KAAKvB,KAAK,CAACuB,KAAK,EAAE;cAClD,OAAO9B,WAAW,CAAC0B,MAA8C,CAAC;YACpE;YAEA,OAAOA,MAAM;UACf;QAEA,KAAK,SAAS;UACZ,IAAIpB,iBAAiB,CAACC,KAAK,CAAC,EAAE;YAC5B,OAAOO,uBAAuB,CAACP,KAAK,CAAC;UACvC;UAEA,OAAOF,MAAM,CAACsB,iBAAiB,CAACpB,KAAK,EAAEqB,MAAM,EAAEC,OAAO,CAAC;QAEzD;UACE,OAAOxB,MAAM,CAACsB,iBAAiB,CAACpB,KAAK,EAAEqB,MAAM,EAAEC,OAAO,CAAC;MAC3D;IACF,CAAC;IAEDE,cAAc,EAAElC;EAClB,CAAC;AACH","ignoreList":[]}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
1
3
|
import { nanoid } from 'nanoid/non-secure';
|
|
2
|
-
import BaseRouter from
|
|
4
|
+
import { BaseRouter } from "./BaseRouter.js";
|
|
5
|
+
import { createParamsFromAction } from "./createParamsFromAction.js";
|
|
6
|
+
import { createRouteFromAction } from "./createRouteFromAction.js";
|
|
3
7
|
export const StackActions = {
|
|
4
8
|
replace(name, params) {
|
|
5
9
|
return {
|
|
@@ -31,9 +35,22 @@ export const StackActions = {
|
|
|
31
35
|
return {
|
|
32
36
|
type: 'POP_TO_TOP'
|
|
33
37
|
};
|
|
38
|
+
},
|
|
39
|
+
popTo(name, params, options) {
|
|
40
|
+
if (typeof options === 'boolean') {
|
|
41
|
+
console.warn(`Passing a boolean as the third argument to 'popTo' is deprecated. Pass '{ merge: true }' instead.`);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
type: 'POP_TO',
|
|
45
|
+
payload: {
|
|
46
|
+
name,
|
|
47
|
+
params,
|
|
48
|
+
merge: typeof options === 'boolean' ? options : options?.merge
|
|
49
|
+
}
|
|
50
|
+
};
|
|
34
51
|
}
|
|
35
52
|
};
|
|
36
|
-
export
|
|
53
|
+
export function StackRouter(options) {
|
|
37
54
|
const router = {
|
|
38
55
|
...BaseRouter,
|
|
39
56
|
type: 'stack',
|
|
@@ -48,6 +65,7 @@ export default function StackRouter(options) {
|
|
|
48
65
|
key: `stack-${nanoid()}`,
|
|
49
66
|
index: 0,
|
|
50
67
|
routeNames,
|
|
68
|
+
preloadedRoutes: [],
|
|
51
69
|
routes: [{
|
|
52
70
|
key: `${initialRouteName}-${nanoid()}`,
|
|
53
71
|
name: initialRouteName,
|
|
@@ -59,7 +77,7 @@ export default function StackRouter(options) {
|
|
|
59
77
|
routeNames,
|
|
60
78
|
routeParamList
|
|
61
79
|
}) {
|
|
62
|
-
|
|
80
|
+
const state = partialState;
|
|
63
81
|
if (state.stale === false) {
|
|
64
82
|
return state;
|
|
65
83
|
}
|
|
@@ -71,6 +89,14 @@ export default function StackRouter(options) {
|
|
|
71
89
|
...route.params
|
|
72
90
|
} : route.params
|
|
73
91
|
}));
|
|
92
|
+
const preloadedRoutes = state.preloadedRoutes?.filter(route => routeNames.includes(route.name)).map(route => ({
|
|
93
|
+
...route,
|
|
94
|
+
key: route.key || `${route.name}-${nanoid()}`,
|
|
95
|
+
params: routeParamList[route.name] !== undefined ? {
|
|
96
|
+
...routeParamList[route.name],
|
|
97
|
+
...route.params
|
|
98
|
+
} : route.params
|
|
99
|
+
})) ?? [];
|
|
74
100
|
if (routes.length === 0) {
|
|
75
101
|
const initialRouteName = options.initialRouteName !== undefined ? options.initialRouteName : routeNames[0];
|
|
76
102
|
routes.push({
|
|
@@ -85,7 +111,8 @@ export default function StackRouter(options) {
|
|
|
85
111
|
key: `stack-${nanoid()}`,
|
|
86
112
|
index: routes.length - 1,
|
|
87
113
|
routeNames,
|
|
88
|
-
routes
|
|
114
|
+
routes,
|
|
115
|
+
preloadedRoutes
|
|
89
116
|
};
|
|
90
117
|
},
|
|
91
118
|
getStateForRouteNamesChange(state, {
|
|
@@ -127,72 +154,183 @@ export default function StackRouter(options) {
|
|
|
127
154
|
switch (action.type) {
|
|
128
155
|
case 'REPLACE':
|
|
129
156
|
{
|
|
130
|
-
const
|
|
131
|
-
if (
|
|
157
|
+
const currentIndex = action.target === state.key && action.source ? state.routes.findIndex(r => r.key === action.source) : state.index;
|
|
158
|
+
if (currentIndex === -1) {
|
|
132
159
|
return null;
|
|
133
160
|
}
|
|
134
|
-
|
|
135
|
-
name,
|
|
136
|
-
key,
|
|
137
|
-
params
|
|
138
|
-
} = action.payload;
|
|
139
|
-
if (!state.routeNames.includes(name)) {
|
|
161
|
+
if (!state.routeNames.includes(action.payload.name)) {
|
|
140
162
|
return null;
|
|
141
163
|
}
|
|
164
|
+
const getId = options.routeGetIdList[action.payload.name];
|
|
165
|
+
const id = getId?.({
|
|
166
|
+
params: action.payload.params
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Re-use preloaded route if available
|
|
170
|
+
let route = state.preloadedRoutes.find(route => route.name === action.payload.name && id === getId?.({
|
|
171
|
+
params: route.params
|
|
172
|
+
}));
|
|
173
|
+
if (!route) {
|
|
174
|
+
route = createRouteFromAction({
|
|
175
|
+
action,
|
|
176
|
+
routeParamList
|
|
177
|
+
});
|
|
178
|
+
}
|
|
142
179
|
return {
|
|
143
180
|
...state,
|
|
144
|
-
routes: state.routes.map((
|
|
145
|
-
|
|
146
|
-
name,
|
|
147
|
-
params: routeParamList[name] !== undefined ? {
|
|
148
|
-
...routeParamList[name],
|
|
149
|
-
...params
|
|
150
|
-
} : params
|
|
151
|
-
} : route)
|
|
181
|
+
routes: state.routes.map((r, i) => i === currentIndex ? route : r),
|
|
182
|
+
preloadedRoutes: state.preloadedRoutes.filter(r => r.key !== route.key)
|
|
152
183
|
};
|
|
153
184
|
}
|
|
154
185
|
case 'PUSH':
|
|
155
|
-
|
|
186
|
+
case 'NAVIGATE':
|
|
187
|
+
{
|
|
188
|
+
if (!state.routeNames.includes(action.payload.name)) {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
156
191
|
const getId = options.routeGetIdList[action.payload.name];
|
|
157
|
-
const id = getId
|
|
192
|
+
const id = getId?.({
|
|
158
193
|
params: action.payload.params
|
|
159
194
|
});
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
195
|
+
let route;
|
|
196
|
+
if (id !== undefined) {
|
|
197
|
+
route = state.routes.findLast(route => route.name === action.payload.name && id === getId?.({
|
|
198
|
+
params: route.params
|
|
199
|
+
}));
|
|
200
|
+
} else if (action.type === 'NAVIGATE') {
|
|
201
|
+
const currentRoute = state.routes[state.index];
|
|
202
|
+
|
|
203
|
+
// If the route matches the current one, then navigate to it
|
|
204
|
+
if (action.payload.name === currentRoute.name) {
|
|
205
|
+
route = currentRoute;
|
|
206
|
+
} else if (action.payload.pop) {
|
|
207
|
+
route = state.routes.findLast(route => route.name === action.payload.name);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (!route) {
|
|
211
|
+
route = state.preloadedRoutes.find(route => route.name === action.payload.name && id === getId?.({
|
|
212
|
+
params: route.params
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
let params;
|
|
216
|
+
if (action.type === 'NAVIGATE' && action.payload.merge && route) {
|
|
217
|
+
params = action.payload.params !== undefined || routeParamList[action.payload.name] !== undefined ? {
|
|
218
|
+
...routeParamList[action.payload.name],
|
|
219
|
+
...route.params,
|
|
220
|
+
...action.payload.params
|
|
221
|
+
} : route.params;
|
|
222
|
+
} else {
|
|
223
|
+
params = createParamsFromAction({
|
|
224
|
+
action,
|
|
225
|
+
routeParamList
|
|
226
|
+
});
|
|
227
|
+
}
|
|
163
228
|
let routes;
|
|
164
229
|
if (route) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
230
|
+
if (action.type === 'NAVIGATE' && action.payload.pop) {
|
|
231
|
+
routes = [];
|
|
232
|
+
|
|
233
|
+
// Get all routes until the matching one
|
|
234
|
+
for (const r of state.routes) {
|
|
235
|
+
if (r.key === route.key) {
|
|
236
|
+
routes.push({
|
|
237
|
+
...route,
|
|
238
|
+
path: action.payload.path !== undefined ? action.payload.path : route.path,
|
|
239
|
+
params
|
|
240
|
+
});
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
routes.push(r);
|
|
244
|
+
}
|
|
245
|
+
} else {
|
|
246
|
+
routes = state.routes.filter(r => r.key !== route.key);
|
|
247
|
+
routes.push({
|
|
248
|
+
...route,
|
|
249
|
+
path: action.type === 'NAVIGATE' && action.payload.path !== undefined ? action.payload.path : route.path,
|
|
250
|
+
params
|
|
251
|
+
});
|
|
252
|
+
}
|
|
173
253
|
} else {
|
|
174
254
|
routes = [...state.routes, {
|
|
175
255
|
key: `${action.payload.name}-${nanoid()}`,
|
|
176
256
|
name: action.payload.name,
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
...action.payload.params
|
|
180
|
-
} : action.payload.params
|
|
257
|
+
path: action.type === 'NAVIGATE' ? action.payload.path : undefined,
|
|
258
|
+
params
|
|
181
259
|
}];
|
|
182
260
|
}
|
|
183
261
|
return {
|
|
184
262
|
...state,
|
|
185
263
|
index: routes.length - 1,
|
|
264
|
+
preloadedRoutes: state.preloadedRoutes.filter(route => routes[routes.length - 1].key !== route.key),
|
|
186
265
|
routes
|
|
187
266
|
};
|
|
188
267
|
}
|
|
189
|
-
|
|
268
|
+
case 'NAVIGATE_DEPRECATED':
|
|
269
|
+
{
|
|
270
|
+
if (!state.routeNames.includes(action.payload.name)) {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
if (state.preloadedRoutes.find(route => route.name === action.payload.name && id === getId?.({
|
|
274
|
+
params: route.params
|
|
275
|
+
}))) {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// If the route already exists, navigate to that
|
|
280
|
+
let index = -1;
|
|
281
|
+
const getId = options.routeGetIdList[action.payload.name];
|
|
282
|
+
const id = getId?.({
|
|
283
|
+
params: action.payload.params
|
|
284
|
+
});
|
|
285
|
+
if (id !== undefined) {
|
|
286
|
+
index = state.routes.findIndex(route => route.name === action.payload.name && id === getId?.({
|
|
287
|
+
params: route.params
|
|
288
|
+
}));
|
|
289
|
+
} else if (state.routes[state.index].name === action.payload.name) {
|
|
290
|
+
index = state.index;
|
|
291
|
+
} else {
|
|
292
|
+
index = state.routes.findLastIndex(route => route.name === action.payload.name);
|
|
293
|
+
}
|
|
294
|
+
if (index === -1) {
|
|
295
|
+
const routes = [...state.routes, createRouteFromAction({
|
|
296
|
+
action,
|
|
297
|
+
routeParamList
|
|
298
|
+
})];
|
|
299
|
+
return {
|
|
300
|
+
...state,
|
|
301
|
+
routes,
|
|
302
|
+
index: routes.length - 1
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
const route = state.routes[index];
|
|
306
|
+
let params;
|
|
307
|
+
if (action.payload.merge) {
|
|
308
|
+
params = action.payload.params !== undefined || routeParamList[route.name] !== undefined ? {
|
|
309
|
+
...routeParamList[route.name],
|
|
310
|
+
...route.params,
|
|
311
|
+
...action.payload.params
|
|
312
|
+
} : route.params;
|
|
313
|
+
} else {
|
|
314
|
+
params = createParamsFromAction({
|
|
315
|
+
action,
|
|
316
|
+
routeParamList
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
return {
|
|
320
|
+
...state,
|
|
321
|
+
index,
|
|
322
|
+
routes: [...state.routes.slice(0, index), params !== route.params ? {
|
|
323
|
+
...route,
|
|
324
|
+
params
|
|
325
|
+
} : state.routes[index]]
|
|
326
|
+
};
|
|
327
|
+
}
|
|
190
328
|
case 'POP':
|
|
191
329
|
{
|
|
192
|
-
const
|
|
193
|
-
if (
|
|
194
|
-
const count = Math.max(
|
|
195
|
-
const routes = state.routes.slice(0, count).concat(state.routes.slice(
|
|
330
|
+
const currentIndex = action.target === state.key && action.source ? state.routes.findIndex(r => r.key === action.source) : state.index;
|
|
331
|
+
if (currentIndex > 0) {
|
|
332
|
+
const count = Math.max(currentIndex - action.payload.count + 1, 1);
|
|
333
|
+
const routes = state.routes.slice(0, count).concat(state.routes.slice(currentIndex + 1));
|
|
196
334
|
return {
|
|
197
335
|
...state,
|
|
198
336
|
index: routes.length - 1,
|
|
@@ -208,50 +346,55 @@ export default function StackRouter(options) {
|
|
|
208
346
|
count: state.routes.length - 1
|
|
209
347
|
}
|
|
210
348
|
}, options);
|
|
211
|
-
case '
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
349
|
+
case 'POP_TO':
|
|
350
|
+
{
|
|
351
|
+
const currentIndex = action.target === state.key && action.source ? state.routes.findLastIndex(r => r.key === action.source) : state.index;
|
|
352
|
+
if (currentIndex === -1) {
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
if (!state.routeNames.includes(action.payload.name)) {
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// If the route already exists, navigate to it
|
|
217
360
|
let index = -1;
|
|
218
|
-
const getId =
|
|
219
|
-
|
|
220
|
-
action.payload.key === undefined && action.payload.name !== undefined ? options.routeGetIdList[action.payload.name] : undefined;
|
|
221
|
-
const id = getId === null || getId === void 0 ? void 0 : getId({
|
|
361
|
+
const getId = options.routeGetIdList[action.payload.name];
|
|
362
|
+
const id = getId?.({
|
|
222
363
|
params: action.payload.params
|
|
223
364
|
});
|
|
224
|
-
if (id) {
|
|
225
|
-
index = state.routes.findIndex(route => route.name === action.payload.name && id ===
|
|
365
|
+
if (id !== undefined) {
|
|
366
|
+
index = state.routes.findIndex(route => route.name === action.payload.name && id === getId?.({
|
|
226
367
|
params: route.params
|
|
227
|
-
}))
|
|
228
|
-
} else if (state.routes[
|
|
229
|
-
index =
|
|
368
|
+
}));
|
|
369
|
+
} else if (state.routes[currentIndex].name === action.payload.name) {
|
|
370
|
+
index = currentIndex;
|
|
230
371
|
} else {
|
|
231
|
-
for (let i =
|
|
232
|
-
if (state.routes[i].name === action.payload.name
|
|
372
|
+
for (let i = currentIndex; i >= 0; i--) {
|
|
373
|
+
if (state.routes[i].name === action.payload.name) {
|
|
233
374
|
index = i;
|
|
234
375
|
break;
|
|
235
376
|
}
|
|
236
377
|
}
|
|
237
378
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
}
|
|
379
|
+
|
|
380
|
+
// If the route doesn't exist, remove the current route and add the new one
|
|
381
|
+
if (index === -1) {
|
|
382
|
+
// Re-use preloaded route if available
|
|
383
|
+
let route = state.preloadedRoutes.find(route => route.name === action.payload.name && id === getId?.({
|
|
384
|
+
params: route.params
|
|
385
|
+
}));
|
|
386
|
+
if (!route) {
|
|
387
|
+
route = createRouteFromAction({
|
|
388
|
+
action,
|
|
389
|
+
routeParamList
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
const routes = state.routes.slice(0, currentIndex).concat(route);
|
|
251
393
|
return {
|
|
252
394
|
...state,
|
|
395
|
+
index: routes.length - 1,
|
|
253
396
|
routes,
|
|
254
|
-
|
|
397
|
+
preloadedRoutes: state.preloadedRoutes.filter(r => r.key !== route.key)
|
|
255
398
|
};
|
|
256
399
|
}
|
|
257
400
|
const route = state.routes[index];
|
|
@@ -263,22 +406,20 @@ export default function StackRouter(options) {
|
|
|
263
406
|
...action.payload.params
|
|
264
407
|
} : route.params;
|
|
265
408
|
} else {
|
|
266
|
-
params =
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
409
|
+
params = createParamsFromAction({
|
|
410
|
+
action,
|
|
411
|
+
routeParamList
|
|
412
|
+
});
|
|
270
413
|
}
|
|
271
414
|
return {
|
|
272
415
|
...state,
|
|
273
416
|
index,
|
|
274
|
-
routes: [...state.routes.slice(0, index), params !== route.params
|
|
417
|
+
routes: [...state.routes.slice(0, index), params !== route.params ? {
|
|
275
418
|
...route,
|
|
276
|
-
path: action.payload.path ?? route.path,
|
|
277
419
|
params
|
|
278
420
|
} : state.routes[index]]
|
|
279
421
|
};
|
|
280
422
|
}
|
|
281
|
-
return null;
|
|
282
423
|
case 'GO_BACK':
|
|
283
424
|
if (state.index > 0) {
|
|
284
425
|
return router.getStateForAction(state, {
|
|
@@ -291,6 +432,46 @@ export default function StackRouter(options) {
|
|
|
291
432
|
}, options);
|
|
292
433
|
}
|
|
293
434
|
return null;
|
|
435
|
+
case 'PRELOAD':
|
|
436
|
+
{
|
|
437
|
+
const getId = options.routeGetIdList[action.payload.name];
|
|
438
|
+
const id = getId?.({
|
|
439
|
+
params: action.payload.params
|
|
440
|
+
});
|
|
441
|
+
let route;
|
|
442
|
+
if (id !== undefined) {
|
|
443
|
+
route = state.routes.find(route => route.name === action.payload.name && id === getId?.({
|
|
444
|
+
params: route.params
|
|
445
|
+
}));
|
|
446
|
+
}
|
|
447
|
+
if (route) {
|
|
448
|
+
return {
|
|
449
|
+
...state,
|
|
450
|
+
routes: state.routes.map(r => {
|
|
451
|
+
if (r.key !== route?.key) {
|
|
452
|
+
return r;
|
|
453
|
+
}
|
|
454
|
+
return {
|
|
455
|
+
...r,
|
|
456
|
+
params: createParamsFromAction({
|
|
457
|
+
action,
|
|
458
|
+
routeParamList
|
|
459
|
+
})
|
|
460
|
+
};
|
|
461
|
+
})
|
|
462
|
+
};
|
|
463
|
+
} else {
|
|
464
|
+
return {
|
|
465
|
+
...state,
|
|
466
|
+
preloadedRoutes: state.preloadedRoutes.filter(r => r.name !== action.payload.name || id !== getId?.({
|
|
467
|
+
params: r.params
|
|
468
|
+
})).concat(createRouteFromAction({
|
|
469
|
+
action,
|
|
470
|
+
routeParamList
|
|
471
|
+
}))
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
}
|
|
294
475
|
default:
|
|
295
476
|
return BaseRouter.getStateForAction(state, action);
|
|
296
477
|
}
|