@react-navigation/stack 8.0.0-alpha.3 → 8.0.0-alpha.31

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 (67) hide show
  1. package/lib/module/index.js.map +1 -1
  2. package/lib/module/navigators/createStackNavigator.js +3 -7
  3. package/lib/module/navigators/createStackNavigator.js.map +1 -1
  4. package/lib/module/utils/useCardAnimation.js +1 -1
  5. package/lib/module/utils/useCardAnimation.js.map +1 -1
  6. package/lib/module/utils/useGestureHandlerRef.js +1 -1
  7. package/lib/module/utils/useGestureHandlerRef.js.map +1 -1
  8. package/lib/module/utils/useKeyboardManager.js +50 -26
  9. package/lib/module/utils/useKeyboardManager.js.map +1 -1
  10. package/lib/module/views/Header/Header.js +2 -2
  11. package/lib/module/views/Header/Header.js.map +1 -1
  12. package/lib/module/views/Header/HeaderContainer.js +51 -17
  13. package/lib/module/views/Header/HeaderContainer.js.map +1 -1
  14. package/lib/module/views/Header/HeaderSegment.js +2 -2
  15. package/lib/module/views/Header/HeaderSegment.js.map +1 -1
  16. package/lib/module/views/Stack/Card.js +25 -20
  17. package/lib/module/views/Stack/Card.js.map +1 -1
  18. package/lib/module/views/Stack/CardContainer.js +69 -98
  19. package/lib/module/views/Stack/CardContainer.js.map +1 -1
  20. package/lib/module/views/Stack/CardStack.js +134 -116
  21. package/lib/module/views/Stack/CardStack.js.map +1 -1
  22. package/lib/module/views/Stack/StackView.js +82 -49
  23. package/lib/module/views/Stack/StackView.js.map +1 -1
  24. package/lib/typescript/src/index.d.ts +1 -1
  25. package/lib/typescript/src/index.d.ts.map +1 -1
  26. package/lib/typescript/src/navigators/createStackNavigator.d.ts +8 -14
  27. package/lib/typescript/src/navigators/createStackNavigator.d.ts.map +1 -1
  28. package/lib/typescript/src/types.d.ts +46 -53
  29. package/lib/typescript/src/types.d.ts.map +1 -1
  30. package/lib/typescript/src/utils/gestureActivationCriteria.d.ts +1 -1
  31. package/lib/typescript/src/utils/gestureActivationCriteria.d.ts.map +1 -1
  32. package/lib/typescript/src/utils/useKeyboardManager.d.ts +9 -2
  33. package/lib/typescript/src/utils/useKeyboardManager.d.ts.map +1 -1
  34. package/lib/typescript/src/views/Header/Header.d.ts +1 -1
  35. package/lib/typescript/src/views/Header/Header.d.ts.map +1 -1
  36. package/lib/typescript/src/views/Header/HeaderContainer.d.ts +7 -2
  37. package/lib/typescript/src/views/Header/HeaderContainer.d.ts.map +1 -1
  38. package/lib/typescript/src/views/Header/HeaderSegment.d.ts +2 -2
  39. package/lib/typescript/src/views/Header/HeaderSegment.d.ts.map +1 -1
  40. package/lib/typescript/src/views/Stack/Card.d.ts +3 -3
  41. package/lib/typescript/src/views/Stack/Card.d.ts.map +1 -1
  42. package/lib/typescript/src/views/Stack/CardContainer.d.ts +4 -6
  43. package/lib/typescript/src/views/Stack/CardContainer.d.ts.map +1 -1
  44. package/lib/typescript/src/views/Stack/CardStack.d.ts +4 -3
  45. package/lib/typescript/src/views/Stack/CardStack.d.ts.map +1 -1
  46. package/lib/typescript/src/views/Stack/StackView.d.ts +6 -9
  47. package/lib/typescript/src/views/Stack/StackView.d.ts.map +1 -1
  48. package/package.json +20 -22
  49. package/src/index.tsx +1 -0
  50. package/src/navigators/createStackNavigator.tsx +9 -40
  51. package/src/types.tsx +73 -73
  52. package/src/utils/gestureActivationCriteria.tsx +1 -1
  53. package/src/utils/useCardAnimation.tsx +1 -1
  54. package/src/utils/useGestureHandlerRef.tsx +1 -1
  55. package/src/utils/useKeyboardManager.tsx +67 -33
  56. package/src/views/Header/Header.tsx +2 -2
  57. package/src/views/Header/HeaderContainer.tsx +66 -20
  58. package/src/views/Header/HeaderSegment.tsx +4 -4
  59. package/src/views/Stack/Card.tsx +32 -23
  60. package/src/views/Stack/CardContainer.tsx +81 -127
  61. package/src/views/Stack/CardStack.tsx +334 -318
  62. package/src/views/Stack/StackView.tsx +138 -66
  63. package/lib/module/views/Stack/CardA11yWrapper.js +0 -43
  64. package/lib/module/views/Stack/CardA11yWrapper.js.map +0 -1
  65. package/lib/typescript/src/views/Stack/CardA11yWrapper.d.ts +0 -15
  66. package/lib/typescript/src/views/Stack/CardA11yWrapper.d.ts.map +0 -1
  67. package/src/views/Stack/CardA11yWrapper.tsx +0 -67
@@ -35,10 +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>[];
40
- // Previous descriptors, to compare whether descriptors have changed or not
41
- previousDescriptors: StackDescriptorMap;
38
+ // Previous navigation state for comparison
39
+ previousState: StackNavigationState<ParamListBase> | undefined;
42
40
  // List of routes being opened, we need to animate pushing of these new routes
43
41
  openingRouteKeys: string[];
44
42
  // List of routes being closed, we need to animate popping of these routes
@@ -64,33 +62,53 @@ export class StackView extends React.Component<Props, State> {
64
62
  props: Readonly<Props>,
65
63
  state: Readonly<State>
66
64
  ) {
67
- const allRoutes = [...props.state.routes, ...props.state.preloadedRoutes];
65
+ const allRoutes = props.state.routes;
66
+ const previousRoutes = state.previousState?.routes ?? [];
67
+ const previousFocusedRoute = state.previousState
68
+ ? state.previousState.routes[state.previousState.index]
69
+ : undefined;
70
+ const nextFocusedRouteFromState = props.state.routes[props.state.index];
71
+ const activeRoutes = props.state.routes.slice(0, props.state.index + 1);
68
72
 
69
73
  // If there was no change in routes, we don't need to compute anything
70
74
  if (
71
75
  isArrayEqual(
72
76
  allRoutes.map((r) => r.key),
73
- state.previousRoutes.map((r) => r.key)
77
+ previousRoutes.map((r) => r.key)
74
78
  ) &&
79
+ previousFocusedRoute?.key === nextFocusedRouteFromState?.key &&
75
80
  state.routes.length
76
81
  ) {
77
- let routes = props.state.routes;
78
- let previousRoutes = state.previousRoutes;
79
- let descriptors = props.descriptors;
80
- let previousDescriptors = state.previousDescriptors;
82
+ // If there were any routes being closed or replaced,
83
+ // We need to make sure they are preserved in the new state from props.state
84
+ // So first we get all such routes from the previous state (that included the animating routes)
85
+ // Then we add them back to the new state if they don't already exist
86
+
87
+ const closingRoutes = state.routes.filter(
88
+ (r) =>
89
+ state.closingRouteKeys.includes(r.key) &&
90
+ !activeRoutes.some((pr) => pr.key === r.key)
91
+ );
81
92
 
82
- if (props.descriptors !== state.previousDescriptors) {
83
- descriptors = state.routes.reduce<StackDescriptorMap>((acc, route) => {
84
- acc[route.key] =
85
- props.descriptors[route.key] || state.descriptors[route.key];
93
+ const replacingRoutes = state.routes.filter(
94
+ (r) =>
95
+ state.replacingRouteKeys.includes(r.key) &&
96
+ !activeRoutes.some((pr) => pr.key === r.key)
97
+ );
86
98
 
87
- return acc;
88
- }, {});
99
+ let routes: Route<string>[] = activeRoutes.slice();
89
100
 
90
- previousDescriptors = props.descriptors;
101
+ // Replacing routes go before the focused route (they're being covered)
102
+ if (replacingRoutes.length) {
103
+ routes.splice(routes.length - 1, 0, ...replacingRoutes);
91
104
  }
92
105
 
93
- if (!isArrayEqual(allRoutes, state.previousRoutes)) {
106
+ // Closing routes go at the end (they're animating out on top)
107
+ if (closingRoutes.length) {
108
+ routes.push(...closingRoutes);
109
+ }
110
+
111
+ if (!isArrayEqual(allRoutes, previousRoutes)) {
94
112
  // if any route objects have changed, we should update them
95
113
  const map = allRoutes.reduce<Record<string, Route<string>>>(
96
114
  (acc, route) => {
@@ -100,37 +118,44 @@ export class StackView extends React.Component<Props, State> {
100
118
  {}
101
119
  );
102
120
 
103
- routes = props.state.routes.map((route) => map[route.key] || route);
104
- previousRoutes = allRoutes;
121
+ routes = routes.map((route) => map[route.key] || route);
105
122
  }
106
123
 
124
+ const routeKeys = new Set(routes.map((route) => route.key));
125
+ const descriptors = [
126
+ ...routes,
127
+ ...props.state.routes.filter((route) => !routeKeys.has(route.key)),
128
+ ].reduce<StackDescriptorMap>((acc, route) => {
129
+ acc[route.key] =
130
+ props.descriptors[route.key] || state.descriptors[route.key];
131
+
132
+ return acc;
133
+ }, {});
134
+
107
135
  return {
108
136
  routes,
109
- previousRoutes,
137
+ previousState: props.state,
110
138
  descriptors,
111
- previousDescriptors,
112
139
  };
113
140
  }
114
141
 
115
142
  // Here we determine which routes were added or removed to animate them
116
143
  // We keep a copy of the route being removed in local state to be able to animate it
117
144
 
118
- let routes =
119
- props.state.index < props.state.routes.length - 1
120
- ? // Remove any extra routes from the state
121
- // The last visible route should be the focused route, i.e. at current index
122
- props.state.routes.slice(0, props.state.index + 1)
123
- : props.state.routes;
145
+ let { openingRouteKeys, closingRouteKeys, replacingRouteKeys } = state;
124
146
 
125
- // Now we need to determine which routes were added and removed
126
- const { previousRoutes } = state;
147
+ // If a route that was closing or being replaced is now back in the routes,
148
+ // it was added back before the animation finished, so stop tracking it
149
+ closingRouteKeys = closingRouteKeys.filter(
150
+ (key) => !activeRoutes.some((r) => r.key === key)
151
+ );
127
152
 
128
- let { openingRouteKeys, closingRouteKeys, replacingRouteKeys } = state;
153
+ replacingRouteKeys = replacingRouteKeys.filter(
154
+ (key) => !activeRoutes.some((r) => r.key === key)
155
+ );
129
156
 
130
- const previousFocusedRoute = previousRoutes[previousRoutes.length - 1] as
131
- | Route<string>
132
- | undefined;
133
- const nextFocusedRoute = routes[routes.length - 1];
157
+ // Get previous focused route from previous active routes
158
+ const nextFocusedRoute = activeRoutes[activeRoutes.length - 1];
134
159
 
135
160
  const isAnimationEnabled = (key: string) => {
136
161
  const descriptor = props.descriptors[key] || state.descriptors[key];
@@ -144,6 +169,8 @@ export class StackView extends React.Component<Props, State> {
144
169
  return descriptor.options.animationTypeForReplace ?? 'push';
145
170
  };
146
171
 
172
+ let routes = activeRoutes;
173
+
147
174
  if (
148
175
  previousFocusedRoute &&
149
176
  previousFocusedRoute.key !== nextFocusedRoute.key
@@ -233,6 +260,18 @@ export class StackView extends React.Component<Props, State> {
233
260
  // After the push animation is completed, routes being replaced will be removed completely
234
261
  routes = routes.slice();
235
262
  routes.splice(routes.length - 1, 0, previousFocusedRoute);
263
+
264
+ // Preserve any other routes still being replaced from previous transitions
265
+ const previousReplacingRoutes = state.routes.filter(
266
+ (r) =>
267
+ replacingRouteKeys.includes(r.key) &&
268
+ !routes.some((existing) => existing.key === r.key)
269
+ );
270
+
271
+ if (previousReplacingRoutes.length) {
272
+ // Insert before the route we just added (previousFocusedRoute)
273
+ routes.splice(routes.length - 2, 0, ...previousReplacingRoutes);
274
+ }
236
275
  }
237
276
  }
238
277
  }
@@ -257,7 +296,11 @@ export class StackView extends React.Component<Props, State> {
257
296
  );
258
297
  }
259
298
 
260
- const descriptors = allRoutes.reduce<StackDescriptorMap>((acc, route) => {
299
+ const routeKeys = new Set(routes.map((route) => route.key));
300
+ const descriptors = [
301
+ ...routes,
302
+ ...props.state.routes.filter((route) => !routeKeys.has(route.key)),
303
+ ].reduce<StackDescriptorMap>((acc, route) => {
261
304
  acc[route.key] =
262
305
  props.descriptors[route.key] || state.descriptors[route.key];
263
306
 
@@ -266,8 +309,7 @@ export class StackView extends React.Component<Props, State> {
266
309
 
267
310
  return {
268
311
  routes,
269
- previousRoutes: [...props.state.routes, ...props.state.preloadedRoutes],
270
- previousDescriptors: props.descriptors,
312
+ previousState: props.state,
271
313
  openingRouteKeys,
272
314
  closingRouteKeys,
273
315
  replacingRouteKeys,
@@ -277,8 +319,7 @@ export class StackView extends React.Component<Props, State> {
277
319
 
278
320
  state: State = {
279
321
  routes: [],
280
- previousRoutes: [],
281
- previousDescriptors: {},
322
+ previousState: undefined,
282
323
  openingRouteKeys: [],
283
324
  closingRouteKeys: [],
284
325
  replacingRouteKeys: [],
@@ -307,48 +348,73 @@ export class StackView extends React.Component<Props, State> {
307
348
  const { state, navigation } = this.props;
308
349
  const { closingRouteKeys, replacingRouteKeys } = this.state;
309
350
 
351
+ const activeRoutes = state.routes.slice(0, state.index + 1);
352
+
310
353
  if (
311
354
  closingRouteKeys.some((key) => key === route.key) &&
312
355
  replacingRouteKeys.every((key) => key !== route.key) &&
313
356
  state.routeNames.includes(route.name) &&
314
- !state.routes.some((r) => r.key === route.key)
357
+ !activeRoutes.some((r) => r.key === route.key)
315
358
  ) {
316
- // If route isn't present in current state, but was closing, assume that a close animation was cancelled
359
+ // If route is no longer active, but was closing, assume that a close animation was cancelled
317
360
  // So we need to add this route back to the state
318
361
  navigation.dispatch((state) => {
319
- const routes = [
320
- ...state.routes.filter((r) => r.key !== route.key),
321
- route,
322
- ];
362
+ const activeRoutes = state.routes
363
+ .slice(0, state.index + 1)
364
+ .filter((r) => r.key !== route.key);
365
+ const inactiveRoutes = state.routes
366
+ .slice(state.index + 1)
367
+ .filter((r) => r.key !== route.key);
323
368
 
324
- return CommonActions.reset({
369
+ const routes = [...activeRoutes, route];
370
+
371
+ const resetState = {
325
372
  ...state,
326
- routes,
327
373
  index: routes.length - 1,
328
- });
374
+ routes: routes.concat(inactiveRoutes),
375
+ };
376
+
377
+ return CommonActions.reset(resetState);
329
378
  });
330
379
  } else {
331
- this.setState((state) => ({
332
- routes: state.replacingRouteKeys.length
333
- ? state.routes.filter(
334
- (r) => !state.replacingRouteKeys.includes(r.key)
335
- )
336
- : state.routes,
337
- openingRouteKeys: state.openingRouteKeys.filter(
338
- (key) => key !== route.key
339
- ),
340
- closingRouteKeys: state.closingRouteKeys.filter(
341
- (key) => key !== route.key
342
- ),
343
- replacingRouteKeys: [],
344
- }));
380
+ this.setState((state) => {
381
+ const routeIndex = state.routes.findIndex((r) => r.key === route.key);
382
+
383
+ // Remove replacing routes that were before the route that just opened
384
+ // Those were replaced by this or earlier routes and should be cleaned up
385
+ const replacingRoutesToRemove = new Set(
386
+ state.routes
387
+ .slice(0, routeIndex)
388
+ .filter((r) => state.replacingRouteKeys.includes(r.key))
389
+ .map((r) => r.key)
390
+ );
391
+
392
+ const newRoutes = state.routes.filter(
393
+ (r) => !replacingRoutesToRemove.has(r.key)
394
+ );
395
+
396
+ return {
397
+ routes: newRoutes,
398
+ openingRouteKeys: state.openingRouteKeys.filter(
399
+ (key) => key !== route.key
400
+ ),
401
+ closingRouteKeys: state.closingRouteKeys.filter(
402
+ (key) => key !== route.key
403
+ ),
404
+ replacingRouteKeys: state.replacingRouteKeys.filter(
405
+ (key) => !replacingRoutesToRemove.has(key)
406
+ ),
407
+ };
408
+ });
345
409
  }
346
410
  };
347
411
 
348
412
  private handleCloseRoute = ({ route }: { route: Route<string> }) => {
349
413
  const { state, navigation } = this.props;
350
414
 
351
- if (state.routes.some((r) => r.key === route.key)) {
415
+ const activeRoutes = state.routes.slice(0, state.index + 1);
416
+
417
+ if (activeRoutes.some((r) => r.key === route.key)) {
352
418
  // If a route exists in state, trigger a pop
353
419
  // This will happen in when the route was closed from the card component
354
420
  // e.g. When the close animation triggered from a gesture ends
@@ -420,8 +486,13 @@ export class StackView extends React.Component<Props, State> {
420
486
  ...rest
421
487
  } = this.props;
422
488
 
423
- const { routes, descriptors, openingRouteKeys, closingRouteKeys } =
424
- this.state;
489
+ const {
490
+ routes,
491
+ descriptors,
492
+ openingRouteKeys,
493
+ closingRouteKeys,
494
+ replacingRouteKeys,
495
+ } = this.state;
425
496
 
426
497
  return (
427
498
  <GestureHandlerWrapper style={styles.container}>
@@ -440,6 +511,7 @@ export class StackView extends React.Component<Props, State> {
440
511
  routes={routes}
441
512
  openingRouteKeys={openingRouteKeys}
442
513
  closingRouteKeys={closingRouteKeys}
514
+ replacingRouteKeys={replacingRouteKeys}
443
515
  onOpenRoute={this.handleOpenRoute}
444
516
  onCloseRoute={this.handleCloseRoute}
445
517
  onTransitionStart={this.handleTransitionStart}
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- import * as React from 'react';
4
- import { Platform, StyleSheet, View } from 'react-native';
5
- import { jsx as _jsx } from "react/jsx-runtime";
6
- export const CardA11yWrapper = /*#__PURE__*/React.forwardRef(({
7
- focused,
8
- active,
9
- animated,
10
- isNextScreenTransparent,
11
- detachCurrentScreen,
12
- children
13
- }, ref) => {
14
- // Manage this in separate component to avoid re-rendering card during gestures
15
- // Otherwise the gesture animation will be interrupted as state hasn't updated yet
16
- const [inert, setInert] = React.useState(false);
17
- React.useImperativeHandle(ref, () => ({
18
- setInert
19
- }), []);
20
- const isHidden = !animated && isNextScreenTransparent === false && detachCurrentScreen !== false && !focused;
21
- return /*#__PURE__*/_jsx(View, {
22
- "aria-hidden": !focused,
23
- style: [StyleSheet.absoluteFill, {
24
- pointerEvents: (animated ? inert : !focused) ? 'none' : 'box-none',
25
- // This is necessary to avoid unfocused larger pages increasing scroll area
26
- // The issue can be seen on the web when a smaller screen is pushed over a larger one
27
- overflow: active ? undefined : 'hidden',
28
- // We use visibility on web
29
- display: Platform.OS !== 'web' && isHidden ? 'none' : 'flex',
30
- // Hide unfocused screens when animation isn't enabled
31
- // This is also necessary for a11y on web
32
- // @ts-expect-error visibility is only available on web
33
- visibility: isHidden ? 'hidden' : 'visible'
34
- }]
35
- // Make sure this view is not removed on the new architecture, as it causes focus loss during navigation on Android.
36
- // This can happen when the view flattening results in different trees - due to `overflow` style changing in a parent.
37
- ,
38
- collapsable: false,
39
- children: children
40
- });
41
- });
42
- CardA11yWrapper.displayName = 'CardA11yWrapper';
43
- //# sourceMappingURL=CardA11yWrapper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["React","Platform","StyleSheet","View","jsx","_jsx","CardA11yWrapper","forwardRef","focused","active","animated","isNextScreenTransparent","detachCurrentScreen","children","ref","inert","setInert","useState","useImperativeHandle","isHidden","style","absoluteFill","pointerEvents","overflow","undefined","display","OS","visibility","collapsable","displayName"],"sourceRoot":"../../../../src","sources":["views/Stack/CardA11yWrapper.tsx"],"mappings":";;AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,QAAQ,EAAEC,UAAU,EAAEC,IAAI,QAAQ,cAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAa1D,OAAO,MAAMC,eAAe,gBAAGN,KAAK,CAACO,UAAU,CAC7C,CACE;EACEC,OAAO;EACPC,MAAM;EACNC,QAAQ;EACRC,uBAAuB;EACvBC,mBAAmB;EACnBC;AACK,CAAC,EACRC,GAAkC,KAC/B;EACH;EACA;EACA,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGhB,KAAK,CAACiB,QAAQ,CAAC,KAAK,CAAC;EAE/CjB,KAAK,CAACkB,mBAAmB,CAACJ,GAAG,EAAE,OAAO;IAAEE;EAAS,CAAC,CAAC,EAAE,EAAE,CAAC;EAExD,MAAMG,QAAQ,GACZ,CAACT,QAAQ,IACTC,uBAAuB,KAAK,KAAK,IACjCC,mBAAmB,KAAK,KAAK,IAC7B,CAACJ,OAAO;EAEV,oBACEH,IAAA,CAACF,IAAI;IACH,eAAa,CAACK,OAAQ;IACtBY,KAAK,EAAE,CACLlB,UAAU,CAACmB,YAAY,EACvB;MACEC,aAAa,EAAE,CAACZ,QAAQ,GAAGK,KAAK,GAAG,CAACP,OAAO,IAAI,MAAM,GAAG,UAAU;MAClE;MACA;MACAe,QAAQ,EAAEd,MAAM,GAAGe,SAAS,GAAG,QAAQ;MACvC;MACAC,OAAO,EAAExB,QAAQ,CAACyB,EAAE,KAAK,KAAK,IAAIP,QAAQ,GAAG,MAAM,GAAG,MAAM;MAC5D;MACA;MACA;MACAQ,UAAU,EAAER,QAAQ,GAAG,QAAQ,GAAG;IACpC,CAAC;IAEH;IACA;IAAA;IACAS,WAAW,EAAE,KAAM;IAAAf,QAAA,EAElBA;EAAQ,CACL,CAAC;AAEX,CACF,CAAC;AAEDP,eAAe,CAACuB,WAAW,GAAG,iBAAiB","ignoreList":[]}
@@ -1,15 +0,0 @@
1
- import * as React from 'react';
2
- type Props = {
3
- focused: boolean;
4
- active: boolean;
5
- animated: boolean;
6
- isNextScreenTransparent: boolean;
7
- detachCurrentScreen: boolean;
8
- children: React.ReactNode;
9
- };
10
- export type CardA11yWrapperRef = {
11
- setInert: (value: boolean) => void;
12
- };
13
- export declare const CardA11yWrapper: React.ForwardRefExoticComponent<Props & React.RefAttributes<CardA11yWrapperRef>>;
14
- export {};
15
- //# sourceMappingURL=CardA11yWrapper.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CardA11yWrapper.d.ts","sourceRoot":"","sources":["../../../../../src/views/Stack/CardA11yWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,KAAK,KAAK,GAAG;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,uBAAuB,EAAE,OAAO,CAAC;IACjC,mBAAmB,EAAE,OAAO,CAAC;IAC7B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CAAE,CAAC;AAExE,eAAO,MAAM,eAAe,kFAkD3B,CAAC"}
@@ -1,67 +0,0 @@
1
- import * as React from 'react';
2
- import { Platform, StyleSheet, View } from 'react-native';
3
-
4
- type Props = {
5
- focused: boolean;
6
- active: boolean;
7
- animated: boolean;
8
- isNextScreenTransparent: boolean;
9
- detachCurrentScreen: boolean;
10
- children: React.ReactNode;
11
- };
12
-
13
- export type CardA11yWrapperRef = { setInert: (value: boolean) => void };
14
-
15
- export const CardA11yWrapper = React.forwardRef(
16
- (
17
- {
18
- focused,
19
- active,
20
- animated,
21
- isNextScreenTransparent,
22
- detachCurrentScreen,
23
- children,
24
- }: Props,
25
- ref: React.Ref<CardA11yWrapperRef>
26
- ) => {
27
- // Manage this in separate component to avoid re-rendering card during gestures
28
- // Otherwise the gesture animation will be interrupted as state hasn't updated yet
29
- const [inert, setInert] = React.useState(false);
30
-
31
- React.useImperativeHandle(ref, () => ({ setInert }), []);
32
-
33
- const isHidden =
34
- !animated &&
35
- isNextScreenTransparent === false &&
36
- detachCurrentScreen !== false &&
37
- !focused;
38
-
39
- return (
40
- <View
41
- aria-hidden={!focused}
42
- style={[
43
- StyleSheet.absoluteFill,
44
- {
45
- pointerEvents: (animated ? inert : !focused) ? 'none' : 'box-none',
46
- // This is necessary to avoid unfocused larger pages increasing scroll area
47
- // The issue can be seen on the web when a smaller screen is pushed over a larger one
48
- overflow: active ? undefined : 'hidden',
49
- // We use visibility on web
50
- display: Platform.OS !== 'web' && isHidden ? 'none' : 'flex',
51
- // Hide unfocused screens when animation isn't enabled
52
- // This is also necessary for a11y on web
53
- // @ts-expect-error visibility is only available on web
54
- visibility: isHidden ? 'hidden' : 'visible',
55
- },
56
- ]}
57
- // Make sure this view is not removed on the new architecture, as it causes focus loss during navigation on Android.
58
- // This can happen when the view flattening results in different trees - due to `overflow` style changing in a parent.
59
- collapsable={false}
60
- >
61
- {children}
62
- </View>
63
- );
64
- }
65
- );
66
-
67
- CardA11yWrapper.displayName = 'CardA11yWrapper';