@react-navigation/routers 8.0.0-alpha.10 → 8.0.0-alpha.12
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/module/CommonActions.js +9 -21
- package/lib/module/CommonActions.js.map +1 -1
- package/lib/module/StackRouter.js +91 -23
- package/lib/module/StackRouter.js.map +1 -1
- package/lib/module/TabRouter.js +52 -11
- package/lib/module/TabRouter.js.map +1 -1
- package/lib/typescript/src/BaseRouter.d.ts +1 -1
- package/lib/typescript/src/BaseRouter.d.ts.map +1 -1
- package/lib/typescript/src/CommonActions.d.ts +1 -8
- package/lib/typescript/src/CommonActions.d.ts.map +1 -1
- package/lib/typescript/src/DrawerRouter.d.ts +2 -2
- package/lib/typescript/src/DrawerRouter.d.ts.map +1 -1
- package/lib/typescript/src/StackRouter.d.ts +2 -2
- package/lib/typescript/src/StackRouter.d.ts.map +1 -1
- package/lib/typescript/src/TabRouter.d.ts +2 -2
- package/lib/typescript/src/TabRouter.d.ts.map +1 -1
- package/lib/typescript/src/createParamsFromAction.d.ts +1 -1
- package/lib/typescript/src/createParamsFromAction.d.ts.map +1 -1
- package/lib/typescript/src/createRouteFromAction.d.ts +1 -1
- package/lib/typescript/src/createRouteFromAction.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +9 -9
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +3 -3
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/CommonActions.tsx +10 -34
- package/src/StackRouter.tsx +129 -17
- package/src/TabRouter.tsx +75 -14
- package/src/types.tsx +13 -15
package/src/TabRouter.tsx
CHANGED
|
@@ -91,10 +91,16 @@ const getRouteHistory = (
|
|
|
91
91
|
backBehavior: BackBehavior,
|
|
92
92
|
initialRouteName: string | undefined
|
|
93
93
|
) => {
|
|
94
|
+
const route = routes[index];
|
|
95
|
+
|
|
96
|
+
if (route == null) {
|
|
97
|
+
throw new Error(`Couldn't find a route at index ${index}.`);
|
|
98
|
+
}
|
|
99
|
+
|
|
94
100
|
const history = [
|
|
95
101
|
{
|
|
96
102
|
type: TYPE_ROUTE,
|
|
97
|
-
key:
|
|
103
|
+
key: route.key,
|
|
98
104
|
},
|
|
99
105
|
];
|
|
100
106
|
|
|
@@ -103,17 +109,29 @@ const getRouteHistory = (
|
|
|
103
109
|
switch (backBehavior) {
|
|
104
110
|
case 'order':
|
|
105
111
|
for (let i = index; i > 0; i--) {
|
|
112
|
+
const route = routes[i - 1];
|
|
113
|
+
|
|
114
|
+
if (route == null) {
|
|
115
|
+
throw new Error(`Couldn't find a route at index ${i - 1}.`);
|
|
116
|
+
}
|
|
117
|
+
|
|
106
118
|
history.unshift({
|
|
107
119
|
type: TYPE_ROUTE,
|
|
108
|
-
key:
|
|
120
|
+
key: route.key,
|
|
109
121
|
});
|
|
110
122
|
}
|
|
111
123
|
break;
|
|
112
124
|
case 'firstRoute':
|
|
113
125
|
if (index !== 0) {
|
|
126
|
+
const route = routes[0];
|
|
127
|
+
|
|
128
|
+
if (route == null) {
|
|
129
|
+
throw new Error("Couldn't find a route at index 0.");
|
|
130
|
+
}
|
|
131
|
+
|
|
114
132
|
history.unshift({
|
|
115
133
|
type: TYPE_ROUTE,
|
|
116
|
-
key:
|
|
134
|
+
key: route.key,
|
|
117
135
|
});
|
|
118
136
|
}
|
|
119
137
|
break;
|
|
@@ -124,9 +142,17 @@ const getRouteHistory = (
|
|
|
124
142
|
initialRouteIndex = initialRouteIndex === -1 ? 0 : initialRouteIndex;
|
|
125
143
|
|
|
126
144
|
if (index !== initialRouteIndex) {
|
|
145
|
+
const route = routes[initialRouteIndex];
|
|
146
|
+
|
|
147
|
+
if (route == null) {
|
|
148
|
+
throw new Error(
|
|
149
|
+
`Couldn't find a route at index ${initialRouteIndex}.`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
127
153
|
history.unshift({
|
|
128
154
|
type: TYPE_ROUTE,
|
|
129
|
-
key:
|
|
155
|
+
key: route.key,
|
|
130
156
|
});
|
|
131
157
|
}
|
|
132
158
|
break;
|
|
@@ -150,6 +176,10 @@ const changeIndex = (
|
|
|
150
176
|
if (backBehavior === 'history' || backBehavior === 'fullHistory') {
|
|
151
177
|
const currentRoute = state.routes[index];
|
|
152
178
|
|
|
179
|
+
if (currentRoute == null) {
|
|
180
|
+
throw new Error(`Couldn't find a route at index ${index}.`);
|
|
181
|
+
}
|
|
182
|
+
|
|
153
183
|
if (backBehavior === 'history') {
|
|
154
184
|
// Remove the existing key from the history to de-duplicate it
|
|
155
185
|
history = history.filter((it) =>
|
|
@@ -266,8 +296,9 @@ export function TabRouter({
|
|
|
266
296
|
} as Route<string>;
|
|
267
297
|
});
|
|
268
298
|
|
|
299
|
+
const currentRoute = state.routes[state.index ?? 0];
|
|
269
300
|
const index = Math.min(
|
|
270
|
-
Math.max(routeNames.indexOf(
|
|
301
|
+
Math.max(currentRoute ? routeNames.indexOf(currentRoute.name) : 0, 0),
|
|
271
302
|
routes.length - 1
|
|
272
303
|
);
|
|
273
304
|
|
|
@@ -311,10 +342,13 @@ export function TabRouter({
|
|
|
311
342
|
}
|
|
312
343
|
);
|
|
313
344
|
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
345
|
+
const currentRoute = state.routes[state.index];
|
|
346
|
+
|
|
347
|
+
if (currentRoute == null) {
|
|
348
|
+
throw new Error(`Couldn't find a route at index ${state.index}.`);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const index = Math.max(0, routeNames.indexOf(currentRoute.name));
|
|
318
352
|
|
|
319
353
|
let history = state.history.filter(
|
|
320
354
|
// Type will always be 'route' for tabs, but could be different in a router extending this (e.g. drawer)
|
|
@@ -414,10 +448,18 @@ export function TabRouter({
|
|
|
414
448
|
initialRouteName
|
|
415
449
|
);
|
|
416
450
|
|
|
451
|
+
const updatedRoute = updatedState.routes[updatedState.index];
|
|
452
|
+
|
|
453
|
+
if (updatedRoute == null) {
|
|
454
|
+
throw new Error(
|
|
455
|
+
`Couldn't find a route at index ${updatedState.index}.`
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
|
|
417
459
|
return {
|
|
418
460
|
...updatedState,
|
|
419
461
|
preloadedRouteKeys: updatedState.preloadedRouteKeys.filter(
|
|
420
|
-
(key) => key !==
|
|
462
|
+
(key) => key !== updatedRoute.key
|
|
421
463
|
),
|
|
422
464
|
};
|
|
423
465
|
}
|
|
@@ -425,6 +467,10 @@ export function TabRouter({
|
|
|
425
467
|
case 'GO_BACK': {
|
|
426
468
|
const focusedRoute = state.routes[state.index];
|
|
427
469
|
|
|
470
|
+
if (focusedRoute == null) {
|
|
471
|
+
throw new Error(`Couldn't find a route at index ${state.index}.`);
|
|
472
|
+
}
|
|
473
|
+
|
|
428
474
|
if (state.history.length === 1 && !focusedRoute.history?.length) {
|
|
429
475
|
return null;
|
|
430
476
|
}
|
|
@@ -453,7 +499,12 @@ export function TabRouter({
|
|
|
453
499
|
}
|
|
454
500
|
|
|
455
501
|
const previousHistoryItem = state.history[state.history.length - 2];
|
|
456
|
-
|
|
502
|
+
|
|
503
|
+
if (previousHistoryItem == null) {
|
|
504
|
+
return null;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
const previousKey = previousHistoryItem.key;
|
|
457
508
|
const index = state.routes.findLastIndex(
|
|
458
509
|
(route) => route.key === previousKey
|
|
459
510
|
);
|
|
@@ -464,13 +515,19 @@ export function TabRouter({
|
|
|
464
515
|
|
|
465
516
|
let routes = state.routes;
|
|
466
517
|
|
|
518
|
+
const previousRoute = routes[index];
|
|
519
|
+
|
|
520
|
+
if (previousRoute == null) {
|
|
521
|
+
throw new Error(`Couldn't find a route at index ${index}.`);
|
|
522
|
+
}
|
|
523
|
+
|
|
467
524
|
if (
|
|
468
525
|
backBehavior === 'fullHistory' &&
|
|
469
|
-
|
|
526
|
+
previousRoute.params !== previousHistoryItem.params
|
|
470
527
|
) {
|
|
471
528
|
routes = [...state.routes];
|
|
472
529
|
routes[index] = {
|
|
473
|
-
...
|
|
530
|
+
...previousRoute,
|
|
474
531
|
params: previousHistoryItem.params,
|
|
475
532
|
};
|
|
476
533
|
}
|
|
@@ -479,7 +536,7 @@ export function TabRouter({
|
|
|
479
536
|
...state,
|
|
480
537
|
routes,
|
|
481
538
|
preloadedRouteKeys: state.preloadedRouteKeys.filter(
|
|
482
|
-
(key) => key !==
|
|
539
|
+
(key) => key !== previousRoute.key
|
|
483
540
|
),
|
|
484
541
|
history: state.history.slice(0, -1),
|
|
485
542
|
index,
|
|
@@ -497,6 +554,10 @@ export function TabRouter({
|
|
|
497
554
|
|
|
498
555
|
const route = state.routes[routeIndex];
|
|
499
556
|
|
|
557
|
+
if (route == null) {
|
|
558
|
+
throw new Error(`Couldn't find a route at index ${routeIndex}.`);
|
|
559
|
+
}
|
|
560
|
+
|
|
500
561
|
const getId = routeGetIdList[route.name];
|
|
501
562
|
|
|
502
563
|
const currentId = getId?.({ params: route.params });
|
package/src/types.tsx
CHANGED
|
@@ -86,21 +86,19 @@ export type Route<
|
|
|
86
86
|
* History of param changes for this route.
|
|
87
87
|
*/
|
|
88
88
|
history?: { type: 'params'; params: object }[] | undefined;
|
|
89
|
-
} &
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
>
|
|
89
|
+
} & (undefined extends Params
|
|
90
|
+
? {
|
|
91
|
+
/**
|
|
92
|
+
* Params for this route
|
|
93
|
+
*/
|
|
94
|
+
params?: Readonly<Params> | undefined;
|
|
95
|
+
}
|
|
96
|
+
: {
|
|
97
|
+
/**
|
|
98
|
+
* Params for this route
|
|
99
|
+
*/
|
|
100
|
+
params: Readonly<Params>;
|
|
101
|
+
})
|
|
104
102
|
>;
|
|
105
103
|
|
|
106
104
|
export type ParamListBase = Record<string, object | undefined>;
|