@react-navigation/routers 8.0.0-alpha.16 → 8.0.0-alpha.18
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/BaseRouter.js +2 -2
- package/lib/module/BaseRouter.js.map +1 -1
- package/lib/module/CommonActions.js.map +1 -1
- package/lib/module/StackRouter.js +87 -74
- package/lib/module/StackRouter.js.map +1 -1
- package/lib/module/SwitchRouter.js +22 -1
- package/lib/module/SwitchRouter.js.map +1 -1
- package/lib/typescript/src/BaseRouter.d.ts.map +1 -1
- package/lib/typescript/src/CommonActions.d.ts +12 -2
- package/lib/typescript/src/CommonActions.d.ts.map +1 -1
- package/lib/typescript/src/StackRouter.d.ts +29 -2
- package/lib/typescript/src/StackRouter.d.ts.map +1 -1
- package/lib/typescript/src/SwitchRouter.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +2 -2
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/BaseRouter.tsx +8 -6
- package/src/CommonActions.tsx +4 -4
- package/src/StackRouter.tsx +153 -117
- package/src/SwitchRouter.tsx +36 -0
- package/src/types.tsx +2 -2
|
@@ -42,6 +42,14 @@ export type StackActionType = {
|
|
|
42
42
|
};
|
|
43
43
|
source?: string | undefined;
|
|
44
44
|
target?: string | undefined;
|
|
45
|
+
} | {
|
|
46
|
+
type: 'REMOVE';
|
|
47
|
+
payload: {
|
|
48
|
+
name: string;
|
|
49
|
+
count: number;
|
|
50
|
+
};
|
|
51
|
+
source?: string | undefined;
|
|
52
|
+
target?: string | undefined;
|
|
45
53
|
};
|
|
46
54
|
export type StackRouterOptions = DefaultRouterOptions;
|
|
47
55
|
export type StackNavigationState<ParamList extends ParamListBase> = NavigationState<ParamList> & {
|
|
@@ -72,7 +80,9 @@ export type StackActionHelpers<ParamList extends ParamListBase> = {
|
|
|
72
80
|
*/
|
|
73
81
|
push<RouteName extends keyof ParamList>(...args: RouteName extends unknown ? undefined extends ParamList[RouteName] ? [screen: RouteName, params?: ParamList[RouteName]] : [screen: RouteName, params: ParamList[RouteName]] : never): void;
|
|
74
82
|
/**
|
|
75
|
-
* Pop a
|
|
83
|
+
* Pop a history entry from the stack.
|
|
84
|
+
*
|
|
85
|
+
* @param [count=1] Number of history entries to pop. Defaults to 1.
|
|
76
86
|
*/
|
|
77
87
|
pop(count?: number): void;
|
|
78
88
|
/**
|
|
@@ -101,13 +111,23 @@ export type StackActionHelpers<ParamList extends ParamListBase> = {
|
|
|
101
111
|
}
|
|
102
112
|
] : never): void;
|
|
103
113
|
/**
|
|
104
|
-
* Enable or disable retaining the current
|
|
114
|
+
* Enable or disable retaining the current screen in the stack.
|
|
115
|
+
*
|
|
105
116
|
* When a retained route gets removed from the stack,
|
|
106
117
|
* it'll be kept in routes and can be navigated to again.
|
|
107
118
|
*
|
|
108
119
|
* @param enable Whether to retain the current route in the stack or not.
|
|
109
120
|
*/
|
|
110
121
|
retain(enable: boolean): void;
|
|
122
|
+
/**
|
|
123
|
+
* Remove the specified screen from the stack.
|
|
124
|
+
*
|
|
125
|
+
* The `count` parameter has no effect when removing preloaded or retained screens.
|
|
126
|
+
*
|
|
127
|
+
* @param screen Name of the route to remove.
|
|
128
|
+
* @param [count=1] Number of screens to remove. Defaults to 1.
|
|
129
|
+
*/
|
|
130
|
+
remove(screen: keyof ParamList, count?: number): void;
|
|
111
131
|
};
|
|
112
132
|
export declare const StackActions: {
|
|
113
133
|
replace(name: string, params?: object): {
|
|
@@ -149,6 +169,13 @@ export declare const StackActions: {
|
|
|
149
169
|
readonly enable: boolean;
|
|
150
170
|
};
|
|
151
171
|
};
|
|
172
|
+
remove(name: string, count?: number): {
|
|
173
|
+
readonly type: "REMOVE";
|
|
174
|
+
readonly payload: {
|
|
175
|
+
readonly name: string;
|
|
176
|
+
readonly count: number;
|
|
177
|
+
};
|
|
178
|
+
};
|
|
152
179
|
};
|
|
153
180
|
export declare function StackRouter(options: StackRouterOptions): Router<StackNavigationState<ParamListBase>, import("./CommonActions.js").Action | StackActionType>;
|
|
154
181
|
//# sourceMappingURL=StackRouter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StackRouter.d.ts","sourceRoot":"","sources":["../../../src/StackRouter.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEV,oBAAoB,EACpB,eAAe,EACf,aAAa,EAEb,MAAM,EACP,MAAM,YAAS,CAAC;AAEjB,MAAM,MAAM,eAAe,GACvB;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IACvD,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IACvD,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,GACD;IACE,IAAI,EAAE,KAAK,CAAC;IACZ,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,GACD;IACE,IAAI,EAAE,YAAY,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,GACD;IACE,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,MA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KzC,wBAAgB,YAAY,CAAC,IAAI,SAAS,gBAAgB,EAAE,EAC1D,gBAAgB,EAChB,YAA2B,GAC5B,EAAE,mBAAmB;qDASf,mBAAmB,GAAG,iBAAiB,CAAC,YAAY,CAAC;8BAwB/C,YAAY,4BAAO,kCACM,mBAAmB,GAClD,iBAAiB,CAAC,YAAY,CAAC;qHA8D7B,mBAAmB,GAAG;QAAE,eAAe,EAAE,MAAM,EAAE,CAAA;KAAE;kEAwDf,MAAM;iEAerC,gBAAgB,GAAG,sBAAsB,sCACb,mBAAmB,GACtD,6BAAQ,YAAY,4BAAO,GAAG,IAAI;;;;;kBA1Y5B,CAAC;gBACD,CAAC;iBAGJ,CAAC;eAA8B,CAAC;;;;;EAwpBzC"}
|
|
@@ -42,11 +42,11 @@ export type InitialState = Readonly<Partial<Omit<NavigationState, 'stale' | 'rou
|
|
|
42
42
|
}>;
|
|
43
43
|
export type PartialRoute<R extends Route<string>> = Omit<R, 'key'> & {
|
|
44
44
|
key?: string | undefined;
|
|
45
|
-
state?: PartialState<NavigationState> | undefined;
|
|
45
|
+
state?: NavigationState | PartialState<NavigationState> | undefined;
|
|
46
46
|
};
|
|
47
47
|
export type PartialState<State extends NavigationState> = Partial<Omit<State, 'stale' | 'routes'>> & Readonly<{
|
|
48
48
|
stale?: true | undefined;
|
|
49
|
-
routes: PartialRoute<
|
|
49
|
+
routes: PartialRoute<State['routes'][number]>[];
|
|
50
50
|
}>;
|
|
51
51
|
export type Route<RouteName extends string, Params extends unknown | object | undefined = object | undefined> = Readonly<{
|
|
52
52
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,aAAa,MAAM,oBAAiB,CAAC;AAEtD,MAAM,MAAM,sBAAsB,GAAG,aAAa,CAAC,MAAM,CAAC;AAE1D,MAAM,MAAM,eAAe,CACzB,SAAS,SAAS,aAAa,EAC/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AM,CAChB,KAAK,SAAS,eAAe,EAC7B,MAAM,SAAS,gBAAgB,IAC7B;IACF;;;OAGG;IACH,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAEpB;;;;;OAKG;IACH,eAAe,CAAC,OAAO,EAAE,mBAAmB,GAAG,KAAK,CAAC;IAErD;;;;;;OAMG;IACH,kBAAkB,CAChB,YAAY,EAAE,YAAY,CAAC,KAAK,CAAC,GAAG,KAAK,EACzC,OAAO,EAAE,mBAAmB,GAC3B,KAAK,CAAC;IAET;;;;;;OAMG;IACH,2BAA2B,CACzB,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,mBAAmB,GAAG;QAC7B;;;WAGG;QACH,eAAe,EAAE,MAAM,EAAE,CAAC;KAC3B,GACA,KAAK,CAAC;IAET;;;;;OAKG;IACH,qBAAqB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC;IAExD;;;;;;;;OAQG;IACH,iBAAiB,CACf,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,mBAAmB,GAC3B,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IAEtC;;;;OAIG;IACH,uBAAuB,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC;IAE3D;;OAEG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;CACzC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-navigation/routers",
|
|
3
3
|
"description": "Routers to help build custom navigators",
|
|
4
|
-
"version": "8.0.0-alpha.
|
|
4
|
+
"version": "8.0.0-alpha.18",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
7
7
|
"react-native",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"nanoid": "^5.1.11"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@jest/globals": "^
|
|
47
|
+
"@jest/globals": "^30.4.1",
|
|
48
48
|
"del-cli": "^7.0.0",
|
|
49
49
|
"react-native-builder-bob": "^0.43.0",
|
|
50
50
|
"typescript": "^6.0.3"
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
]
|
|
68
68
|
]
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "904ba65a2938924d87658b7009a95698f93c7731"
|
|
71
71
|
}
|
package/src/BaseRouter.tsx
CHANGED
|
@@ -17,9 +17,10 @@ function getStateForAction(
|
|
|
17
17
|
switch (action.type) {
|
|
18
18
|
case 'SET_PARAMS':
|
|
19
19
|
case 'REPLACE_PARAMS': {
|
|
20
|
-
const index =
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const index =
|
|
21
|
+
action.source !== undefined
|
|
22
|
+
? state.routes.findIndex((r) => r.key === action.source)
|
|
23
|
+
: state.index;
|
|
23
24
|
|
|
24
25
|
if (index === -1) {
|
|
25
26
|
return null;
|
|
@@ -42,9 +43,10 @@ function getStateForAction(
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
case 'PUSH_PARAMS': {
|
|
45
|
-
const index =
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const index =
|
|
47
|
+
action.source !== undefined
|
|
48
|
+
? state.routes.findIndex((r) => r.key === action.source)
|
|
49
|
+
: state.index;
|
|
48
50
|
|
|
49
51
|
if (index === -1) {
|
|
50
52
|
return null;
|
package/src/CommonActions.tsx
CHANGED
|
@@ -73,8 +73,8 @@ export type Action =
|
|
|
73
73
|
| PushParamsAction
|
|
74
74
|
| PreloadAction;
|
|
75
75
|
|
|
76
|
-
export function goBack()
|
|
77
|
-
return { type: 'GO_BACK' };
|
|
76
|
+
export function goBack() {
|
|
77
|
+
return { type: 'GO_BACK' } as const satisfies GoBackAction;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
export function navigate(
|
|
@@ -86,7 +86,7 @@ export function navigate(
|
|
|
86
86
|
pop?: boolean | undefined;
|
|
87
87
|
}
|
|
88
88
|
| undefined
|
|
89
|
-
)
|
|
89
|
+
) {
|
|
90
90
|
return {
|
|
91
91
|
type: 'NAVIGATE',
|
|
92
92
|
payload: {
|
|
@@ -95,7 +95,7 @@ export function navigate(
|
|
|
95
95
|
merge: options?.merge,
|
|
96
96
|
pop: options?.pop,
|
|
97
97
|
},
|
|
98
|
-
};
|
|
98
|
+
} as const satisfies NavigateAction;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
export function reset(state: ResetState) {
|
package/src/StackRouter.tsx
CHANGED
|
@@ -51,6 +51,12 @@ export type StackActionType =
|
|
|
51
51
|
payload: { enable: boolean };
|
|
52
52
|
source?: string | undefined;
|
|
53
53
|
target?: string | undefined;
|
|
54
|
+
}
|
|
55
|
+
| {
|
|
56
|
+
type: 'REMOVE';
|
|
57
|
+
payload: { name: string; count: number };
|
|
58
|
+
source?: string | undefined;
|
|
59
|
+
target?: string | undefined;
|
|
54
60
|
};
|
|
55
61
|
|
|
56
62
|
export type StackRouterOptions = DefaultRouterOptions;
|
|
@@ -99,7 +105,9 @@ export type StackActionHelpers<ParamList extends ParamListBase> = {
|
|
|
99
105
|
): void;
|
|
100
106
|
|
|
101
107
|
/**
|
|
102
|
-
* Pop a
|
|
108
|
+
* Pop a history entry from the stack.
|
|
109
|
+
*
|
|
110
|
+
* @param [count=1] Number of history entries to pop. Defaults to 1.
|
|
103
111
|
*/
|
|
104
112
|
pop(count?: number): void;
|
|
105
113
|
|
|
@@ -133,13 +141,24 @@ export type StackActionHelpers<ParamList extends ParamListBase> = {
|
|
|
133
141
|
): void;
|
|
134
142
|
|
|
135
143
|
/**
|
|
136
|
-
* Enable or disable retaining the current
|
|
144
|
+
* Enable or disable retaining the current screen in the stack.
|
|
145
|
+
*
|
|
137
146
|
* When a retained route gets removed from the stack,
|
|
138
147
|
* it'll be kept in routes and can be navigated to again.
|
|
139
148
|
*
|
|
140
149
|
* @param enable Whether to retain the current route in the stack or not.
|
|
141
150
|
*/
|
|
142
151
|
retain(enable: boolean): void;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Remove the specified screen from the stack.
|
|
155
|
+
*
|
|
156
|
+
* The `count` parameter has no effect when removing preloaded or retained screens.
|
|
157
|
+
*
|
|
158
|
+
* @param screen Name of the route to remove.
|
|
159
|
+
* @param [count=1] Number of screens to remove. Defaults to 1.
|
|
160
|
+
*/
|
|
161
|
+
remove(screen: keyof ParamList, count?: number): void;
|
|
143
162
|
};
|
|
144
163
|
|
|
145
164
|
export const StackActions = {
|
|
@@ -180,6 +199,12 @@ export const StackActions = {
|
|
|
180
199
|
payload: { enable },
|
|
181
200
|
} as const satisfies StackActionType;
|
|
182
201
|
},
|
|
202
|
+
remove(name: string, count: number = 1) {
|
|
203
|
+
return {
|
|
204
|
+
type: 'REMOVE',
|
|
205
|
+
payload: { name, count },
|
|
206
|
+
} as const satisfies StackActionType;
|
|
207
|
+
},
|
|
183
208
|
};
|
|
184
209
|
|
|
185
210
|
function retainRoutes<ParamList extends ParamListBase>(
|
|
@@ -464,8 +489,12 @@ export function StackRouter(options: StackRouterOptions) {
|
|
|
464
489
|
|
|
465
490
|
switch (action.type) {
|
|
466
491
|
case 'REPLACE': {
|
|
492
|
+
if (!state.routeNames.includes(action.payload.name)) {
|
|
493
|
+
return null;
|
|
494
|
+
}
|
|
495
|
+
|
|
467
496
|
const currentIndex =
|
|
468
|
-
action.
|
|
497
|
+
action.source !== undefined
|
|
469
498
|
? routes.findIndex((r) => r.key === action.source)
|
|
470
499
|
: state.index;
|
|
471
500
|
|
|
@@ -473,10 +502,6 @@ export function StackRouter(options: StackRouterOptions) {
|
|
|
473
502
|
return null;
|
|
474
503
|
}
|
|
475
504
|
|
|
476
|
-
if (!state.routeNames.includes(action.payload.name)) {
|
|
477
|
-
return null;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
505
|
const getId = options.routeGetIdList[action.payload.name];
|
|
481
506
|
const id = getId?.({ params: action.payload.params });
|
|
482
507
|
|
|
@@ -516,24 +541,37 @@ export function StackRouter(options: StackRouterOptions) {
|
|
|
516
541
|
const getId = options.routeGetIdList[action.payload.name];
|
|
517
542
|
const id = getId?.({ params: action.payload.params });
|
|
518
543
|
|
|
544
|
+
let remainingRoutes = routes;
|
|
519
545
|
let route: Route<string> | undefined;
|
|
520
546
|
|
|
521
547
|
if (action.type === 'NAVIGATE') {
|
|
522
|
-
const
|
|
548
|
+
const currentIndex =
|
|
549
|
+
action.source !== undefined
|
|
550
|
+
? routes.findIndex((r) => r.key === action.source)
|
|
551
|
+
: state.index;
|
|
523
552
|
|
|
524
|
-
if (
|
|
525
|
-
|
|
553
|
+
if (currentIndex === -1) {
|
|
554
|
+
return null;
|
|
526
555
|
}
|
|
527
556
|
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
557
|
+
/**
|
|
558
|
+
* When navigating,
|
|
559
|
+
* - If the current route matches the destination, reuse it.
|
|
560
|
+
* - Or, if a route matching the destination exists after the current, reuse it.
|
|
561
|
+
* - Remove all non-matching routes after the current.
|
|
562
|
+
*/
|
|
563
|
+
remainingRoutes = routes.slice(0, currentIndex + 1);
|
|
564
|
+
route = routes.find(
|
|
565
|
+
(route, i) =>
|
|
566
|
+
i >= currentIndex &&
|
|
567
|
+
route.name === action.payload.name &&
|
|
568
|
+
(id === undefined || id === getId?.({ params: route.params }))
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
if (!route && action.payload.pop) {
|
|
572
|
+
if (id !== undefined) {
|
|
573
|
+
for (let i = remainingRoutes.length - 1; i >= 0; i--) {
|
|
574
|
+
const r = remainingRoutes[i];
|
|
537
575
|
|
|
538
576
|
if (r == null) {
|
|
539
577
|
throw new Error(`Couldn't find a route at index ${i}.`);
|
|
@@ -576,13 +614,8 @@ export function StackRouter(options: StackRouterOptions) {
|
|
|
576
614
|
}
|
|
577
615
|
}
|
|
578
616
|
}
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
// If the route matches the current one, then navigate to it
|
|
582
|
-
if (action.payload.name === currentRoute.name) {
|
|
583
|
-
route = currentRoute;
|
|
584
|
-
} else if (action.payload.pop) {
|
|
585
|
-
route = routes.findLast(
|
|
617
|
+
} else {
|
|
618
|
+
route = remainingRoutes.findLast(
|
|
586
619
|
(route) => route.name === action.payload.name
|
|
587
620
|
);
|
|
588
621
|
}
|
|
@@ -619,48 +652,29 @@ export function StackRouter(options: StackRouterOptions) {
|
|
|
619
652
|
if (action.type === 'NAVIGATE' && action.payload.pop) {
|
|
620
653
|
nextRoutes = [];
|
|
621
654
|
|
|
622
|
-
// Get all routes
|
|
623
|
-
for (const r of
|
|
655
|
+
// Get all routes before the matching one
|
|
656
|
+
for (const r of remainingRoutes) {
|
|
624
657
|
if (r.key === route.key) {
|
|
625
|
-
nextRoutes.push({
|
|
626
|
-
...route,
|
|
627
|
-
path:
|
|
628
|
-
action.payload.path !== undefined
|
|
629
|
-
? action.payload.path
|
|
630
|
-
: route.path,
|
|
631
|
-
params,
|
|
632
|
-
});
|
|
633
658
|
break;
|
|
634
659
|
}
|
|
635
660
|
|
|
636
661
|
nextRoutes.push(r);
|
|
637
662
|
}
|
|
638
|
-
|
|
639
|
-
if (!nextRoutes.some((r) => r.key === route.key)) {
|
|
640
|
-
nextRoutes.push({
|
|
641
|
-
...route,
|
|
642
|
-
path:
|
|
643
|
-
action.payload.path !== undefined
|
|
644
|
-
? action.payload.path
|
|
645
|
-
: route.path,
|
|
646
|
-
params,
|
|
647
|
-
});
|
|
648
|
-
}
|
|
649
663
|
} else {
|
|
650
|
-
nextRoutes =
|
|
651
|
-
nextRoutes.push({
|
|
652
|
-
...route,
|
|
653
|
-
path:
|
|
654
|
-
action.type === 'NAVIGATE' &&
|
|
655
|
-
action.payload.path !== undefined
|
|
656
|
-
? action.payload.path
|
|
657
|
-
: route.path,
|
|
658
|
-
params,
|
|
659
|
-
});
|
|
664
|
+
nextRoutes = remainingRoutes.filter((r) => r.key !== route.key);
|
|
660
665
|
}
|
|
666
|
+
|
|
667
|
+
nextRoutes.push({
|
|
668
|
+
...route,
|
|
669
|
+
path:
|
|
670
|
+
action.type === 'NAVIGATE' && action.payload.path !== undefined
|
|
671
|
+
? action.payload.path
|
|
672
|
+
: route.path,
|
|
673
|
+
params,
|
|
674
|
+
});
|
|
661
675
|
} else {
|
|
662
676
|
nextRoutes = [
|
|
663
|
-
...
|
|
677
|
+
...remainingRoutes,
|
|
664
678
|
{
|
|
665
679
|
key: `${action.payload.name}-${nanoid()}`,
|
|
666
680
|
name: action.payload.name,
|
|
@@ -671,27 +685,12 @@ export function StackRouter(options: StackRouterOptions) {
|
|
|
671
685
|
];
|
|
672
686
|
}
|
|
673
687
|
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
if (lastRoute == null) {
|
|
677
|
-
throw new Error(
|
|
678
|
-
`Couldn't find a route at index ${nextRoutes.length - 1}.`
|
|
679
|
-
);
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
return retainRoutes(
|
|
683
|
-
state,
|
|
684
|
-
getStateWithRoutes(
|
|
685
|
-
state,
|
|
686
|
-
nextRoutes,
|
|
687
|
-
preloadedRoutes.filter((route) => lastRoute.key !== route.key)
|
|
688
|
-
)
|
|
689
|
-
);
|
|
688
|
+
return retainRoutes(state, getStateWithRoutes(state, nextRoutes));
|
|
690
689
|
}
|
|
691
690
|
|
|
692
691
|
case 'POP': {
|
|
693
692
|
let currentIndex =
|
|
694
|
-
action.
|
|
693
|
+
action.source !== undefined
|
|
695
694
|
? routes.findIndex((r) => r.key === action.source)
|
|
696
695
|
: state.index;
|
|
697
696
|
|
|
@@ -714,15 +713,11 @@ export function StackRouter(options: StackRouterOptions) {
|
|
|
714
713
|
* - We have popped the amount of items in count
|
|
715
714
|
* - There are no more items to pop
|
|
716
715
|
*
|
|
717
|
-
* Routes above the current route
|
|
716
|
+
* Routes above the current route are removed.
|
|
718
717
|
*/
|
|
719
718
|
if (route.history?.length || currentIndex > 0) {
|
|
720
719
|
let count = action.payload.count;
|
|
721
720
|
|
|
722
|
-
let removedFromIndex: number | undefined;
|
|
723
|
-
|
|
724
|
-
const sourceIndex = currentIndex;
|
|
725
|
-
|
|
726
721
|
while (count > 0 && (route.history?.length || currentIndex > 0)) {
|
|
727
722
|
if (route.history?.length) {
|
|
728
723
|
const end = Math.min(count, route.history.length);
|
|
@@ -741,7 +736,6 @@ export function StackRouter(options: StackRouterOptions) {
|
|
|
741
736
|
|
|
742
737
|
if (currentIndex > 0 && count > 0) {
|
|
743
738
|
count = count - 1;
|
|
744
|
-
removedFromIndex = currentIndex;
|
|
745
739
|
currentIndex = currentIndex - 1;
|
|
746
740
|
|
|
747
741
|
const currentRoute = routes[currentIndex];
|
|
@@ -756,18 +750,9 @@ export function StackRouter(options: StackRouterOptions) {
|
|
|
756
750
|
}
|
|
757
751
|
}
|
|
758
752
|
|
|
759
|
-
|
|
760
|
-
removedFromIndex === undefined
|
|
761
|
-
? routes
|
|
762
|
-
: routes
|
|
763
|
-
.slice(0, removedFromIndex)
|
|
764
|
-
.concat(routes.slice(sourceIndex + 1));
|
|
753
|
+
const nextRoutes = routes.slice(0, currentIndex + 1);
|
|
765
754
|
|
|
766
755
|
if (route !== routes[currentIndex]) {
|
|
767
|
-
if (nextRoutes === routes) {
|
|
768
|
-
nextRoutes = [...routes];
|
|
769
|
-
}
|
|
770
|
-
|
|
771
756
|
nextRoutes[currentIndex] = route;
|
|
772
757
|
}
|
|
773
758
|
|
|
@@ -777,6 +762,67 @@ export function StackRouter(options: StackRouterOptions) {
|
|
|
777
762
|
return null;
|
|
778
763
|
}
|
|
779
764
|
|
|
765
|
+
case 'REMOVE': {
|
|
766
|
+
if (!state.routeNames.includes(action.payload.name)) {
|
|
767
|
+
return null;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
let currentIndex =
|
|
771
|
+
action.source !== undefined
|
|
772
|
+
? state.routes.findIndex((r) => r.key === action.source)
|
|
773
|
+
: state.index;
|
|
774
|
+
|
|
775
|
+
if (currentIndex === -1) {
|
|
776
|
+
return null;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
if (currentIndex > state.index) {
|
|
780
|
+
const route = state.routes[currentIndex];
|
|
781
|
+
|
|
782
|
+
if (route?.name !== action.payload.name) {
|
|
783
|
+
return null;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
return {
|
|
787
|
+
...state,
|
|
788
|
+
routes: state.routes.filter((r) => r.key !== route.key),
|
|
789
|
+
retainedRouteKeys: state.retainedRouteKeys.filter(
|
|
790
|
+
(key) => key !== route.key
|
|
791
|
+
),
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
if (routes[currentIndex]?.name !== action.payload.name) {
|
|
796
|
+
currentIndex = routes.findLastIndex(
|
|
797
|
+
(route) => route.name === action.payload.name
|
|
798
|
+
);
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
if (
|
|
802
|
+
currentIndex === -1 ||
|
|
803
|
+
routes.length === 1 ||
|
|
804
|
+
action.payload.count < 1
|
|
805
|
+
) {
|
|
806
|
+
return null;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
const count = Math.min(
|
|
810
|
+
action.payload.count,
|
|
811
|
+
currentIndex + 1,
|
|
812
|
+
routes.length - 1
|
|
813
|
+
);
|
|
814
|
+
|
|
815
|
+
const firstIndex = currentIndex - count + 1;
|
|
816
|
+
|
|
817
|
+
return retainRoutes(
|
|
818
|
+
state,
|
|
819
|
+
getStateWithRoutes(
|
|
820
|
+
state,
|
|
821
|
+
routes.slice(0, firstIndex).concat(routes.slice(currentIndex + 1))
|
|
822
|
+
)
|
|
823
|
+
);
|
|
824
|
+
}
|
|
825
|
+
|
|
780
826
|
case 'POP_TO_TOP': {
|
|
781
827
|
let route = routes[0];
|
|
782
828
|
|
|
@@ -799,19 +845,19 @@ export function StackRouter(options: StackRouterOptions) {
|
|
|
799
845
|
}
|
|
800
846
|
|
|
801
847
|
case 'POP_TO': {
|
|
848
|
+
if (!state.routeNames.includes(action.payload.name)) {
|
|
849
|
+
return null;
|
|
850
|
+
}
|
|
851
|
+
|
|
802
852
|
const currentIndex =
|
|
803
|
-
action.
|
|
804
|
-
? routes.
|
|
853
|
+
action.source !== undefined
|
|
854
|
+
? routes.findIndex((r) => r.key === action.source)
|
|
805
855
|
: state.index;
|
|
806
856
|
|
|
807
857
|
if (currentIndex === -1) {
|
|
808
858
|
return null;
|
|
809
859
|
}
|
|
810
860
|
|
|
811
|
-
if (!state.routeNames.includes(action.payload.name)) {
|
|
812
|
-
return null;
|
|
813
|
-
}
|
|
814
|
-
|
|
815
861
|
// If the route already exists, navigate to it
|
|
816
862
|
let index = -1;
|
|
817
863
|
let historyIndex: number | undefined;
|
|
@@ -971,26 +1017,16 @@ export function StackRouter(options: StackRouterOptions) {
|
|
|
971
1017
|
}
|
|
972
1018
|
|
|
973
1019
|
case 'GO_BACK': {
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
type: 'POP',
|
|
985
|
-
payload: { count: 1 },
|
|
986
|
-
target: action.target,
|
|
987
|
-
source: action.source,
|
|
988
|
-
},
|
|
989
|
-
options
|
|
990
|
-
);
|
|
991
|
-
}
|
|
992
|
-
|
|
993
|
-
return null;
|
|
1020
|
+
return router.getStateForAction(
|
|
1021
|
+
state,
|
|
1022
|
+
{
|
|
1023
|
+
type: 'POP',
|
|
1024
|
+
payload: { count: 1 },
|
|
1025
|
+
target: action.target,
|
|
1026
|
+
source: action.source,
|
|
1027
|
+
},
|
|
1028
|
+
options
|
|
1029
|
+
);
|
|
994
1030
|
}
|
|
995
1031
|
|
|
996
1032
|
case 'RETAIN': {
|
package/src/SwitchRouter.tsx
CHANGED
|
@@ -498,6 +498,39 @@ export function SwitchRouter<Type extends SwitchRouterType>({
|
|
|
498
498
|
}
|
|
499
499
|
|
|
500
500
|
case 'GO_BACK': {
|
|
501
|
+
if (action.source !== undefined) {
|
|
502
|
+
const sourceHistoryIndex = state.history.findLastIndex(
|
|
503
|
+
(item) => item.type === 'route' && item.key === action.source
|
|
504
|
+
);
|
|
505
|
+
|
|
506
|
+
if (sourceHistoryIndex === -1) {
|
|
507
|
+
// The source screen was never visited,
|
|
508
|
+
// so there's nothing before it to go back to
|
|
509
|
+
return null;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
const sourceIndex = state.routes.findIndex(
|
|
513
|
+
(route) => route.key === action.source
|
|
514
|
+
);
|
|
515
|
+
|
|
516
|
+
// Remove the routes visited after the source from the history
|
|
517
|
+
// Since we're going back from the source route
|
|
518
|
+
const history = state.history.filter(
|
|
519
|
+
(item, index) =>
|
|
520
|
+
item.type !== 'route' || index <= sourceHistoryIndex
|
|
521
|
+
);
|
|
522
|
+
|
|
523
|
+
state = {
|
|
524
|
+
...state,
|
|
525
|
+
...changeIndex<Type>(
|
|
526
|
+
{ routes: state.routes, history },
|
|
527
|
+
sourceIndex,
|
|
528
|
+
backBehavior,
|
|
529
|
+
initialRouteName
|
|
530
|
+
),
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
|
|
501
534
|
const focusedRoute = state.routes[state.index];
|
|
502
535
|
|
|
503
536
|
if (focusedRoute == null) {
|
|
@@ -528,6 +561,9 @@ export function SwitchRouter<Type extends SwitchRouterType>({
|
|
|
528
561
|
return {
|
|
529
562
|
...state,
|
|
530
563
|
routes,
|
|
564
|
+
preloadedRouteKeys: state.preloadedRouteKeys.filter(
|
|
565
|
+
(key) => key !== focusedRoute.key
|
|
566
|
+
),
|
|
531
567
|
};
|
|
532
568
|
}
|
|
533
569
|
|