@amazon-devices/react-navigation__stack 8.0.9000000000 → 8.0.9000000002

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 (81) hide show
  1. package/SystemModules/amzn__react-navigation__stack-8.private.modules.txt +39 -34
  2. package/kepler-compatibility.json +4 -2
  3. package/lib/module/index.js +0 -34
  4. package/lib/typescript/src/index.d.ts +1 -1
  5. package/lib/typescript/src/index.d.ts.map +1 -1
  6. package/oss-attribution/attribution.txt +76 -0
  7. package/oss-attribution/licenseInfos.json +27 -0
  8. package/package.json +1 -1
  9. package/src/index.tsx +0 -55
  10. package/SystemBundles/98ca5eeb45684e3e5615c766e1d3a956fee53d14cd6c2318098c23c210bd76d7.bundle +0 -13464
  11. package/SystemBundles/98ca5eeb45684e3e5615c766e1d3a956fee53d14cd6c2318098c23c210bd76d7.map +0 -4638
  12. package/lib/module/TransitionConfigs/CardStyleInterpolators.js +0 -394
  13. package/lib/module/TransitionConfigs/HeaderStyleInterpolators.js +0 -262
  14. package/lib/module/TransitionConfigs/TransitionPresets.js +0 -156
  15. package/lib/module/TransitionConfigs/TransitionSpecs.js +0 -124
  16. package/lib/module/navigators/createStackNavigator.js +0 -71
  17. package/lib/module/types.js +0 -4
  18. package/lib/module/utils/CardAnimationContext.js +0 -5
  19. package/lib/module/utils/GestureHandlerRefContext.js +0 -5
  20. package/lib/module/utils/ModalPresentationContext.js +0 -5
  21. package/lib/module/utils/conditional.js +0 -28
  22. package/lib/module/utils/findLastIndex.js +0 -11
  23. package/lib/module/utils/gestureActivationCriteria.js +0 -60
  24. package/lib/module/utils/getDistanceForDirection.js +0 -15
  25. package/lib/module/utils/getInvertedMultiplier.js +0 -15
  26. package/lib/module/utils/getModalRoutesKeys.js +0 -12
  27. package/lib/module/utils/getShadowStyle.js +0 -24
  28. package/lib/module/utils/throttle.js +0 -14
  29. package/lib/module/utils/useCardAnimation.js +0 -12
  30. package/lib/module/utils/useGestureHandlerRef.js +0 -12
  31. package/lib/module/utils/useKeyboardManager.js +0 -90
  32. package/lib/module/views/GestureHandler.android.js +0 -4
  33. package/lib/module/views/GestureHandler.ios.js +0 -4
  34. package/lib/module/views/GestureHandler.js +0 -21
  35. package/lib/module/views/GestureHandler.kepler.js +0 -4
  36. package/lib/module/views/GestureHandlerNative.js +0 -18
  37. package/lib/module/views/Header/Header.js +0 -56
  38. package/lib/module/views/Header/HeaderContainer.js +0 -128
  39. package/lib/module/views/Header/HeaderSegment.js +0 -142
  40. package/lib/module/views/Screens.js +0 -42
  41. package/lib/module/views/Stack/Card.js +0 -433
  42. package/lib/module/views/Stack/CardA11yWrapper.js +0 -43
  43. package/lib/module/views/Stack/CardContainer.js +0 -276
  44. package/lib/module/views/Stack/CardContent.js +0 -74
  45. package/lib/module/views/Stack/CardStack.js +0 -493
  46. package/lib/module/views/Stack/StackView.js +0 -339
  47. package/src/TransitionConfigs/CardStyleInterpolators.tsx +0 -460
  48. package/src/TransitionConfigs/HeaderStyleInterpolators.tsx +0 -286
  49. package/src/TransitionConfigs/TransitionPresets.tsx +0 -182
  50. package/src/TransitionConfigs/TransitionSpecs.tsx +0 -124
  51. package/src/navigators/createStackNavigator.tsx +0 -120
  52. package/src/types.tsx +0 -639
  53. package/src/utils/CardAnimationContext.tsx +0 -7
  54. package/src/utils/GestureHandlerRefContext.tsx +0 -5
  55. package/src/utils/ModalPresentationContext.tsx +0 -3
  56. package/src/utils/conditional.tsx +0 -33
  57. package/src/utils/findLastIndex.tsx +0 -9
  58. package/src/utils/gestureActivationCriteria.tsx +0 -70
  59. package/src/utils/getDistanceForDirection.tsx +0 -19
  60. package/src/utils/getInvertedMultiplier.tsx +0 -17
  61. package/src/utils/getModalRoutesKeys.ts +0 -21
  62. package/src/utils/getShadowStyle.tsx +0 -37
  63. package/src/utils/throttle.tsx +0 -16
  64. package/src/utils/useCardAnimation.tsx +0 -15
  65. package/src/utils/useGestureHandlerRef.tsx +0 -15
  66. package/src/utils/useKeyboardManager.tsx +0 -103
  67. package/src/views/GestureHandler.android.tsx +0 -1
  68. package/src/views/GestureHandler.ios.tsx +0 -1
  69. package/src/views/GestureHandler.kepler.tsx +0 -1
  70. package/src/views/GestureHandler.tsx +0 -23
  71. package/src/views/GestureHandlerNative.tsx +0 -23
  72. package/src/views/Header/Header.tsx +0 -73
  73. package/src/views/Header/HeaderContainer.tsx +0 -191
  74. package/src/views/Header/HeaderSegment.tsx +0 -203
  75. package/src/views/Screens.tsx +0 -45
  76. package/src/views/Stack/Card.tsx +0 -646
  77. package/src/views/Stack/CardA11yWrapper.tsx +0 -67
  78. package/src/views/Stack/CardContainer.tsx +0 -339
  79. package/src/views/Stack/CardContent.tsx +0 -92
  80. package/src/views/Stack/CardStack.tsx +0 -844
  81. package/src/views/Stack/StackView.tsx +0 -485
@@ -1,646 +0,0 @@
1
- import type { LocaleDirection } from '@amazon-devices/react-navigation__native';
2
- import Color from 'color';
3
- import * as React from 'react';
4
- import {
5
- Animated,
6
- InteractionManager,
7
- Platform,
8
- type StyleProp,
9
- StyleSheet,
10
- View,
11
- type ViewStyle,
12
- } from 'react-native';
13
- import type { EdgeInsets } from '@amazon-devices/react-native-safe-area-context';
14
- import useLatestCallback from 'use-latest-callback';
15
-
16
- import type {
17
- GestureDirection,
18
- Layout,
19
- StackCardStyleInterpolator,
20
- TransitionSpec,
21
- } from '../../types';
22
- import { CardAnimationContext } from '../../utils/CardAnimationContext';
23
- import { gestureActivationCriteria } from '../../utils/gestureActivationCriteria';
24
- import { getDistanceForDirection } from '../../utils/getDistanceForDirection';
25
- import { getInvertedMultiplier } from '../../utils/getInvertedMultiplier';
26
- import { getShadowStyle } from '../../utils/getShadowStyle';
27
- import {
28
- GestureState,
29
- PanGestureHandler,
30
- type PanGestureHandlerGestureEvent,
31
- } from '../GestureHandler';
32
- import { CardContent } from './CardContent';
33
-
34
- type Props = {
35
- animated: boolean;
36
- interpolationIndex: number;
37
- opening: boolean;
38
- closing: boolean;
39
- next: Animated.AnimatedInterpolation<number> | undefined;
40
- current: Animated.AnimatedInterpolation<number>;
41
- gesture: Animated.Value;
42
- layout: Layout;
43
- insets: EdgeInsets;
44
- direction: LocaleDirection;
45
- pageOverflowEnabled: boolean;
46
- gestureDirection: GestureDirection;
47
- onOpen: () => void;
48
- onClose: () => void;
49
- onTransition: (props: { closing: boolean; gesture: boolean }) => void;
50
- onGestureBegin: () => void;
51
- onGestureCanceled: () => void;
52
- onGestureEnd: () => void;
53
- children: React.ReactNode;
54
- overlay:
55
- | ((props: {
56
- style: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
57
- }) => React.ReactNode)
58
- | undefined;
59
- overlayEnabled: boolean;
60
- shadowEnabled: boolean | undefined;
61
- gestureEnabled: boolean;
62
- gestureResponseDistance?: number;
63
- gestureVelocityImpact: number | undefined;
64
- transitionSpec: {
65
- open: TransitionSpec;
66
- close: TransitionSpec;
67
- };
68
- preloaded: boolean;
69
- styleInterpolator: StackCardStyleInterpolator;
70
- containerStyle?: StyleProp<ViewStyle>;
71
- contentStyle?: StyleProp<ViewStyle>;
72
- };
73
-
74
- const GESTURE_VELOCITY_IMPACT = 0.3;
75
-
76
- const TRUE = 1;
77
- const FALSE = 0;
78
-
79
- const useNativeDriver = Platform.OS !== 'web';
80
-
81
- const hasOpacityStyle = (
82
- style: Animated.WithAnimatedValue<StyleProp<ViewStyle>>
83
- ) => {
84
- if (style) {
85
- const flattenedStyle = StyleSheet.flatten(style);
86
-
87
- return 'opacity' in flattenedStyle && flattenedStyle.opacity != null;
88
- }
89
-
90
- return false;
91
- };
92
-
93
- const getAnimateToValue = ({
94
- closing: isClosing,
95
- layout: currentLayout,
96
- gestureDirection: currentGestureDirection,
97
- direction: currentDirection,
98
- preloaded: isPreloaded,
99
- }: {
100
- closing?: boolean;
101
- layout: Layout;
102
- gestureDirection: GestureDirection;
103
- direction: LocaleDirection;
104
- preloaded: boolean;
105
- }) => {
106
- if (!isClosing && !isPreloaded) {
107
- return 0;
108
- }
109
-
110
- return getDistanceForDirection(
111
- currentLayout,
112
- currentGestureDirection,
113
- currentDirection === 'rtl'
114
- );
115
- };
116
-
117
- const defaultOverlay = ({
118
- style,
119
- }: {
120
- style: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
121
- }) =>
122
- style ? (
123
- <Animated.View pointerEvents="none" style={[styles.overlay, style]} />
124
- ) : null;
125
-
126
- function Card({
127
- shadowEnabled = false,
128
- gestureEnabled = true,
129
- gestureVelocityImpact = GESTURE_VELOCITY_IMPACT,
130
- overlay = defaultOverlay,
131
- animated,
132
- interpolationIndex,
133
- opening,
134
- closing,
135
- next,
136
- current,
137
- gesture,
138
- layout,
139
- insets,
140
- direction,
141
- pageOverflowEnabled,
142
- gestureDirection,
143
- onOpen,
144
- onClose,
145
- onTransition,
146
- onGestureBegin,
147
- onGestureCanceled,
148
- onGestureEnd,
149
- children,
150
- overlayEnabled,
151
- gestureResponseDistance,
152
- transitionSpec,
153
- preloaded,
154
- styleInterpolator,
155
- containerStyle: customContainerStyle,
156
- contentStyle,
157
- }: Props) {
158
- const [, forceUpdate] = React.useReducer((x) => x + 1, 0);
159
-
160
- const didInitiallyAnimate = React.useRef(false);
161
- const lastToValueRef = React.useRef<number | undefined>(undefined);
162
-
163
- const interactionHandleRef = React.useRef<number | undefined>(undefined);
164
- const animationHandleRef = React.useRef<number | undefined>(undefined);
165
- const pendingGestureCallbackRef =
166
- React.useRef<ReturnType<typeof setTimeout>>(undefined);
167
-
168
- const [isClosing] = React.useState(() => new Animated.Value(FALSE));
169
-
170
- const [inverted] = React.useState(
171
- () =>
172
- new Animated.Value(
173
- getInvertedMultiplier(gestureDirection, direction === 'rtl')
174
- )
175
- );
176
-
177
- const [layoutAnim] = React.useState(() => ({
178
- width: new Animated.Value(layout.width),
179
- height: new Animated.Value(layout.height),
180
- }));
181
-
182
- const [isSwiping] = React.useState(() => new Animated.Value(FALSE));
183
-
184
- const onStartInteraction = useLatestCallback(() => {
185
- if (interactionHandleRef.current === undefined) {
186
- interactionHandleRef.current =
187
- InteractionManager.createInteractionHandle();
188
- }
189
- });
190
-
191
- const onEndInteraction = useLatestCallback(() => {
192
- if (interactionHandleRef.current !== undefined) {
193
- InteractionManager.clearInteractionHandle(interactionHandleRef.current);
194
- interactionHandleRef.current = undefined;
195
- }
196
- });
197
-
198
- const animate = useLatestCallback(
199
- ({
200
- closing: isClosingParam,
201
- velocity,
202
- }: {
203
- closing: boolean;
204
- velocity?: number;
205
- }) => {
206
- const toValue = getAnimateToValue({
207
- closing: isClosingParam,
208
- layout,
209
- gestureDirection,
210
- direction,
211
- preloaded,
212
- });
213
-
214
- lastToValueRef.current = toValue;
215
- isClosing.setValue(isClosingParam ? TRUE : FALSE);
216
-
217
- const spec = isClosingParam ? transitionSpec.close : transitionSpec.open;
218
- const animation =
219
- spec.animation === 'spring' ? Animated.spring : Animated.timing;
220
-
221
- clearTimeout(pendingGestureCallbackRef.current);
222
-
223
- if (animationHandleRef.current !== undefined) {
224
- cancelAnimationFrame(animationHandleRef.current);
225
- }
226
-
227
- onTransition?.({
228
- closing: isClosingParam,
229
- gesture: velocity !== undefined,
230
- });
231
-
232
- const onFinish = () => {
233
- if (isClosingParam) {
234
- onClose();
235
- } else {
236
- onOpen();
237
- }
238
-
239
- animationHandleRef.current = requestAnimationFrame(() => {
240
- if (didInitiallyAnimate.current) {
241
- // Make sure to re-open screen if it wasn't removed
242
- forceUpdate();
243
- }
244
- });
245
- };
246
-
247
- if (animated) {
248
- onStartInteraction();
249
- animation(gesture, {
250
- ...spec.config,
251
- velocity,
252
- toValue,
253
- useNativeDriver,
254
- isInteraction: false,
255
- }).start(({ finished }) => {
256
- onEndInteraction();
257
- clearTimeout(pendingGestureCallbackRef.current);
258
-
259
- if (finished) {
260
- onFinish();
261
- }
262
- });
263
- } else {
264
- onFinish();
265
- }
266
- }
267
- );
268
-
269
- const onGestureStateChange = useLatestCallback(
270
- ({ nativeEvent }: PanGestureHandlerGestureEvent) => {
271
- switch (nativeEvent.state) {
272
- case GestureState.ACTIVE:
273
- isSwiping.setValue(TRUE);
274
- onStartInteraction();
275
- onGestureBegin?.();
276
- break;
277
- case GestureState.CANCELLED:
278
- case GestureState.FAILED: {
279
- isSwiping.setValue(FALSE);
280
- onEndInteraction();
281
-
282
- const velocity =
283
- gestureDirection === 'vertical' ||
284
- gestureDirection === 'vertical-inverted'
285
- ? nativeEvent.velocityY
286
- : nativeEvent.velocityX;
287
-
288
- animate({
289
- closing,
290
- velocity,
291
- });
292
-
293
- onGestureCanceled?.();
294
- break;
295
- }
296
- case GestureState.END: {
297
- isSwiping.setValue(FALSE);
298
-
299
- let distance;
300
- let translation;
301
- let velocity;
302
-
303
- if (
304
- gestureDirection === 'vertical' ||
305
- gestureDirection === 'vertical-inverted'
306
- ) {
307
- distance = layout.height;
308
- translation = nativeEvent.translationY;
309
- velocity = nativeEvent.velocityY;
310
- } else {
311
- distance = layout.width;
312
- translation = nativeEvent.translationX;
313
- velocity = nativeEvent.velocityX;
314
- }
315
-
316
- const shouldClose =
317
- (translation + velocity * gestureVelocityImpact) *
318
- getInvertedMultiplier(gestureDirection, direction === 'rtl') >
319
- distance / 2
320
- ? velocity !== 0 || translation !== 0
321
- : closing;
322
-
323
- animate({ closing: shouldClose, velocity });
324
-
325
- if (shouldClose) {
326
- // We call onClose with a delay to make sure that the animation has already started
327
- // This will make sure that the state update caused by this doesn't affect start of animation
328
- pendingGestureCallbackRef.current = setTimeout(() => {
329
- onClose();
330
-
331
- // Trigger an update after we dispatch the action to remove the screen
332
- // This will make sure that we check if the screen didn't get removed so we can cancel the animation
333
- forceUpdate();
334
- }, 32);
335
- }
336
-
337
- onGestureEnd?.();
338
- break;
339
- }
340
- }
341
- }
342
- );
343
-
344
- React.useLayoutEffect(() => {
345
- layoutAnim.width.setValue(layout.width);
346
- layoutAnim.height.setValue(layout.height);
347
- inverted.setValue(
348
- getInvertedMultiplier(gestureDirection, direction === 'rtl')
349
- );
350
- }, [
351
- gestureDirection,
352
- direction,
353
- inverted,
354
- layoutAnim.width,
355
- layoutAnim.height,
356
- layout.width,
357
- layout.height,
358
- ]);
359
-
360
- const previousPropsRef = React.useRef<{
361
- opening: boolean;
362
- closing: boolean;
363
- layout: Layout;
364
- direction: LocaleDirection;
365
- gestureDirection: GestureDirection;
366
- preloaded: boolean;
367
- } | null>(null);
368
-
369
- React.useEffect(() => {
370
- return () => {
371
- onEndInteraction();
372
-
373
- if (animationHandleRef.current) {
374
- cancelAnimationFrame(animationHandleRef.current);
375
- }
376
-
377
- clearTimeout(pendingGestureCallbackRef.current);
378
- };
379
-
380
- // We only want to clean up the animation on unmount
381
- // eslint-disable-next-line react-hooks/exhaustive-deps
382
- }, []);
383
-
384
- const timeoutRef = React.useRef<ReturnType<typeof setTimeout> | null>(null);
385
-
386
- React.useEffect(() => {
387
- if (preloaded) {
388
- return;
389
- }
390
-
391
- if (!didInitiallyAnimate.current) {
392
- // Animate the card in on initial mount
393
- // Wrap in setTimeout to ensure animation starts after
394
- // rending of the screen is done. This is especially important
395
- // in the new architecture
396
- // cf., https://github.com/react-navigation/react-navigation/issues/12401
397
- if (timeoutRef.current) {
398
- clearTimeout(timeoutRef.current);
399
- }
400
- timeoutRef.current = setTimeout(() => {
401
- didInitiallyAnimate.current = true;
402
- animate({ closing });
403
- }, 0);
404
- } else {
405
- const previousOpening = previousPropsRef.current?.opening;
406
- const previousToValue = previousPropsRef.current
407
- ? getAnimateToValue(previousPropsRef.current)
408
- : null;
409
-
410
- const toValue = getAnimateToValue({
411
- closing,
412
- layout,
413
- gestureDirection,
414
- direction,
415
- preloaded,
416
- });
417
-
418
- if (previousToValue !== toValue || lastToValueRef.current !== toValue) {
419
- // We need to trigger the animation when route was closed
420
- // The route might have been closed by a `POP` action or by a gesture
421
- // When route was closed due to a gesture, the animation would've happened already
422
- // It's still important to trigger the animation so that `onClose` is called
423
- // If `onClose` is not called, cleanup step won't be performed for gestures
424
- animate({ closing });
425
- } else if (
426
- typeof previousOpening === 'boolean' &&
427
- opening &&
428
- !previousOpening
429
- ) {
430
- // This can happen when screen somewhere below in the stack comes into focus via rearranging
431
- // Also reset the animated value to make sure that the animation starts from the beginning
432
- gesture.setValue(
433
- getDistanceForDirection(layout, gestureDirection, direction === 'rtl')
434
- );
435
-
436
- animate({ closing });
437
- }
438
- }
439
-
440
- previousPropsRef.current = {
441
- opening,
442
- closing,
443
- layout,
444
- gestureDirection,
445
- direction,
446
- preloaded,
447
- };
448
- }, [
449
- animate,
450
- closing,
451
- direction,
452
- gesture,
453
- gestureDirection,
454
- layout,
455
- opening,
456
- preloaded,
457
- ]);
458
-
459
- const interpolationProps = React.useMemo(
460
- () => ({
461
- index: interpolationIndex,
462
- current: { progress: current },
463
- next: next && { progress: next },
464
- closing: isClosing,
465
- swiping: isSwiping,
466
- inverted,
467
- layouts: {
468
- screen: layout,
469
- },
470
- insets: {
471
- top: insets.top,
472
- right: insets.right,
473
- bottom: insets.bottom,
474
- left: insets.left,
475
- },
476
- }),
477
- [
478
- interpolationIndex,
479
- current,
480
- next,
481
- isClosing,
482
- isSwiping,
483
- inverted,
484
- layout,
485
- insets.top,
486
- insets.right,
487
- insets.bottom,
488
- insets.left,
489
- ]
490
- );
491
-
492
- const { containerStyle, cardStyle, overlayStyle, shadowStyle } =
493
- React.useMemo(
494
- () => styleInterpolator(interpolationProps),
495
- [styleInterpolator, interpolationProps]
496
- );
497
-
498
- const onGestureEvent = React.useMemo(
499
- () =>
500
- gestureEnabled
501
- ? Animated.event(
502
- [
503
- {
504
- nativeEvent:
505
- gestureDirection === 'vertical' ||
506
- gestureDirection === 'vertical-inverted'
507
- ? { translationY: gesture }
508
- : { translationX: gesture },
509
- },
510
- ],
511
- { useNativeDriver }
512
- )
513
- : undefined,
514
- [gesture, gestureDirection, gestureEnabled]
515
- );
516
-
517
- const { backgroundColor } = StyleSheet.flatten(contentStyle || {});
518
-
519
- const isTransparent =
520
- typeof backgroundColor === 'string'
521
- ? Color(backgroundColor).alpha() === 0
522
- : false;
523
-
524
- return (
525
- <CardAnimationContext.Provider value={interpolationProps}>
526
- {Platform.OS !== 'web' ? (
527
- <Animated.View
528
- style={{
529
- // This is a dummy style that doesn't actually change anything visually.
530
- // Animated needs the animated value to be used somewhere, otherwise things don't update properly.
531
- // If we disable animations and hide header, it could end up making the value unused.
532
- // So we have this dummy style that will always be used regardless of what else changed.
533
- opacity: current,
534
- }}
535
- // Make sure that this view isn't removed. If this view is removed, our style with animated value won't apply
536
- collapsable={false}
537
- />
538
- ) : null}
539
- {overlayEnabled ? (
540
- <View pointerEvents="box-none" style={StyleSheet.absoluteFill}>
541
- {overlay({ style: overlayStyle })}
542
- </View>
543
- ) : null}
544
- <Animated.View
545
- pointerEvents="box-none"
546
- style={[styles.container, containerStyle, customContainerStyle]}
547
- >
548
- <PanGestureHandler
549
- enabled={layout.width !== 0 && gestureEnabled}
550
- onGestureEvent={onGestureEvent}
551
- onHandlerStateChange={onGestureStateChange}
552
- {...gestureActivationCriteria({
553
- layout,
554
- direction,
555
- gestureDirection,
556
- gestureResponseDistance,
557
- })}
558
- >
559
- <Animated.View
560
- pointerEvents="box-none"
561
- needsOffscreenAlphaCompositing={hasOpacityStyle(cardStyle)}
562
- style={[styles.container, cardStyle]}
563
- >
564
- {shadowEnabled && shadowStyle && !isTransparent ? (
565
- <Animated.View
566
- pointerEvents="none"
567
- style={[
568
- styles.shadow,
569
- gestureDirection === 'horizontal'
570
- ? [styles.shadowHorizontal, styles.shadowStart]
571
- : gestureDirection === 'horizontal-inverted'
572
- ? [styles.shadowHorizontal, styles.shadowEnd]
573
- : gestureDirection === 'vertical'
574
- ? [styles.shadowVertical, styles.shadowTop]
575
- : [styles.shadowVertical, styles.shadowBottom],
576
- { backgroundColor },
577
- shadowStyle,
578
- ]}
579
- />
580
- ) : null}
581
- <CardContent
582
- enabled={pageOverflowEnabled}
583
- layout={layout}
584
- style={contentStyle}
585
- >
586
- {children}
587
- </CardContent>
588
- </Animated.View>
589
- </PanGestureHandler>
590
- </Animated.View>
591
- </CardAnimationContext.Provider>
592
- );
593
- }
594
-
595
- export { Card };
596
-
597
- const styles = StyleSheet.create({
598
- container: {
599
- flex: 1,
600
- },
601
- overlay: {
602
- flex: 1,
603
- backgroundColor: '#000',
604
- },
605
- shadow: {
606
- position: 'absolute',
607
- },
608
- shadowHorizontal: {
609
- top: 0,
610
- bottom: 0,
611
- width: 3,
612
- ...getShadowStyle({
613
- offset: {
614
- width: -1,
615
- height: 1,
616
- },
617
- radius: 5,
618
- opacity: 0.3,
619
- }),
620
- },
621
- shadowStart: {
622
- start: 0,
623
- },
624
- shadowEnd: {
625
- end: 0,
626
- },
627
- shadowVertical: {
628
- start: 0,
629
- end: 0,
630
- height: 3,
631
- ...getShadowStyle({
632
- offset: {
633
- width: 1,
634
- height: -1,
635
- },
636
- radius: 5,
637
- opacity: 0.3,
638
- }),
639
- },
640
- shadowTop: {
641
- top: 0,
642
- },
643
- shadowBottom: {
644
- bottom: 0,
645
- },
646
- });
@@ -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
- pointerEvents={(animated ? inert : !focused) ? 'none' : 'box-none'}
43
- style={[
44
- StyleSheet.absoluteFill,
45
- {
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';