@react-navigation/stack 8.0.0-alpha.12 → 8.0.0-alpha.14

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.
Files changed (33) hide show
  1. package/lib/module/views/Stack/CardA11yWrapper.js +1 -2
  2. package/lib/module/views/Stack/CardA11yWrapper.js.map +1 -1
  3. package/lib/module/views/Stack/CardContainer.js +3 -4
  4. package/lib/module/views/Stack/CardContainer.js.map +1 -1
  5. package/lib/module/views/Stack/CardStack.js +56 -117
  6. package/lib/module/views/Stack/CardStack.js.map +1 -1
  7. package/lib/module/views/Stack/StackView.js +13 -14
  8. package/lib/module/views/Stack/StackView.js.map +1 -1
  9. package/lib/typescript/src/types.d.ts +20 -42
  10. package/lib/typescript/src/types.d.ts.map +1 -1
  11. package/lib/typescript/src/utils/gestureActivationCriteria.d.ts +1 -1
  12. package/lib/typescript/src/utils/gestureActivationCriteria.d.ts.map +1 -1
  13. package/lib/typescript/src/views/Header/HeaderSegment.d.ts +2 -2
  14. package/lib/typescript/src/views/Header/HeaderSegment.d.ts.map +1 -1
  15. package/lib/typescript/src/views/Stack/Card.d.ts +3 -3
  16. package/lib/typescript/src/views/Stack/Card.d.ts.map +1 -1
  17. package/lib/typescript/src/views/Stack/CardA11yWrapper.d.ts +0 -1
  18. package/lib/typescript/src/views/Stack/CardA11yWrapper.d.ts.map +1 -1
  19. package/lib/typescript/src/views/Stack/CardContainer.d.ts +2 -2
  20. package/lib/typescript/src/views/Stack/CardContainer.d.ts.map +1 -1
  21. package/lib/typescript/src/views/Stack/CardStack.d.ts +1 -1
  22. package/lib/typescript/src/views/Stack/CardStack.d.ts.map +1 -1
  23. package/lib/typescript/src/views/Stack/StackView.d.ts +5 -15
  24. package/lib/typescript/src/views/Stack/StackView.d.ts.map +1 -1
  25. package/package.json +13 -13
  26. package/src/types.tsx +46 -61
  27. package/src/utils/gestureActivationCriteria.tsx +1 -1
  28. package/src/views/Header/HeaderSegment.tsx +2 -2
  29. package/src/views/Stack/Card.tsx +3 -3
  30. package/src/views/Stack/CardA11yWrapper.tsx +2 -14
  31. package/src/views/Stack/CardContainer.tsx +3 -4
  32. package/src/views/Stack/CardStack.tsx +82 -153
  33. package/src/views/Stack/StackView.tsx +24 -17
@@ -35,8 +35,8 @@ type Props = StackNavigationConfig & {
35
35
  type State = {
36
36
  // Local copy of the routes which are actually rendered
37
37
  routes: Route<string>[];
38
- // Previous routes, to compare whether routes have changed or not
39
- previousRoutes: Route<string>[];
38
+ // Previous navigation state for comparison
39
+ previousState: StackNavigationState<ParamListBase> | undefined;
40
40
  // Previous descriptors, to compare whether descriptors have changed or not
41
41
  previousDescriptors: StackDescriptorMap;
42
42
  // List of routes being opened, we need to animate pushing of these new routes
@@ -65,12 +65,15 @@ export class StackView extends React.Component<Props, State> {
65
65
  state: Readonly<State>
66
66
  ) {
67
67
  const allRoutes = [...props.state.routes, ...props.state.preloadedRoutes];
68
+ const previousRoutes = state.previousState
69
+ ? [...state.previousState.routes, ...state.previousState.preloadedRoutes]
70
+ : [];
68
71
 
69
72
  // If there was no change in routes, we don't need to compute anything
70
73
  if (
71
74
  isArrayEqual(
72
75
  allRoutes.map((r) => r.key),
73
- state.previousRoutes.map((r) => r.key)
76
+ previousRoutes.map((r) => r.key)
74
77
  ) &&
75
78
  state.routes.length
76
79
  ) {
@@ -103,7 +106,6 @@ export class StackView extends React.Component<Props, State> {
103
106
  routes.push(...closingRoutes);
104
107
  }
105
108
 
106
- let previousRoutes = state.previousRoutes;
107
109
  let descriptors = props.descriptors;
108
110
  let previousDescriptors = state.previousDescriptors;
109
111
 
@@ -118,7 +120,7 @@ export class StackView extends React.Component<Props, State> {
118
120
  previousDescriptors = props.descriptors;
119
121
  }
120
122
 
121
- if (!isArrayEqual(allRoutes, state.previousRoutes)) {
123
+ if (!isArrayEqual(allRoutes, previousRoutes)) {
122
124
  // if any route objects have changed, we should update them
123
125
  const map = allRoutes.reduce<Record<string, Route<string>>>(
124
126
  (acc, route) => {
@@ -129,12 +131,11 @@ export class StackView extends React.Component<Props, State> {
129
131
  );
130
132
 
131
133
  routes = routes.map((route) => map[route.key] || route);
132
- previousRoutes = allRoutes;
133
134
  }
134
135
 
135
136
  return {
136
137
  routes,
137
- previousRoutes,
138
+ previousState: props.state,
138
139
  descriptors,
139
140
  previousDescriptors,
140
141
  };
@@ -150,9 +151,6 @@ export class StackView extends React.Component<Props, State> {
150
151
  props.state.routes.slice(0, props.state.index + 1)
151
152
  : props.state.routes;
152
153
 
153
- // Now we need to determine which routes were added and removed
154
- const { previousRoutes } = state;
155
-
156
154
  let { openingRouteKeys, closingRouteKeys, replacingRouteKeys } = state;
157
155
 
158
156
  // If a route that was closing or being replaced is now back in the routes,
@@ -165,9 +163,12 @@ export class StackView extends React.Component<Props, State> {
165
163
  (key) => !routes.some((r) => r.key === key)
166
164
  );
167
165
 
168
- const previousFocusedRoute = previousRoutes[previousRoutes.length - 1] as
169
- | Route<string>
170
- | undefined;
166
+ // Get previous focused route from previousState (actual focused route, not last in previousRoutes
167
+ // which can be a preloaded route that was never focused)
168
+ const previousFocusedRoute = state.previousState
169
+ ? state.previousState.routes[state.previousState.index]
170
+ : undefined;
171
+
171
172
  const nextFocusedRoute = routes[routes.length - 1];
172
173
 
173
174
  const isAnimationEnabled = (key: string) => {
@@ -316,7 +317,7 @@ export class StackView extends React.Component<Props, State> {
316
317
 
317
318
  return {
318
319
  routes,
319
- previousRoutes: [...props.state.routes, ...props.state.preloadedRoutes],
320
+ previousState: props.state,
320
321
  previousDescriptors: props.descriptors,
321
322
  openingRouteKeys,
322
323
  closingRouteKeys,
@@ -327,7 +328,7 @@ export class StackView extends React.Component<Props, State> {
327
328
 
328
329
  state: State = {
329
330
  routes: [],
330
- previousRoutes: [],
331
+ previousState: undefined,
331
332
  previousDescriptors: {},
332
333
  openingRouteKeys: [],
333
334
  closingRouteKeys: [],
@@ -485,8 +486,13 @@ export class StackView extends React.Component<Props, State> {
485
486
  ...rest
486
487
  } = this.props;
487
488
 
488
- const { routes, descriptors, openingRouteKeys, closingRouteKeys } =
489
- this.state;
489
+ const {
490
+ routes,
491
+ descriptors,
492
+ openingRouteKeys,
493
+ closingRouteKeys,
494
+ replacingRouteKeys,
495
+ } = this.state;
490
496
 
491
497
  return (
492
498
  <GestureHandlerWrapper style={styles.container}>
@@ -505,6 +511,7 @@ export class StackView extends React.Component<Props, State> {
505
511
  routes={routes}
506
512
  openingRouteKeys={openingRouteKeys}
507
513
  closingRouteKeys={closingRouteKeys}
514
+ replacingRouteKeys={replacingRouteKeys}
508
515
  onOpenRoute={this.handleOpenRoute}
509
516
  onCloseRoute={this.handleCloseRoute}
510
517
  onTransitionStart={this.handleTransitionStart}