@amazon-devices/react-navigation__stack 8.0.9000000001 → 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 (76) hide show
  1. package/kepler-compatibility.json +2 -1
  2. package/lib/module/index.js +0 -34
  3. package/lib/module/views/Stack/CardStack.js.map +1 -1
  4. package/lib/typescript/src/views/Stack/CardStack.d.ts.map +1 -1
  5. package/package.json +1 -1
  6. package/src/index.tsx +0 -56
  7. package/lib/module/TransitionConfigs/CardStyleInterpolators.js +0 -394
  8. package/lib/module/TransitionConfigs/HeaderStyleInterpolators.js +0 -262
  9. package/lib/module/TransitionConfigs/TransitionPresets.js +0 -156
  10. package/lib/module/TransitionConfigs/TransitionSpecs.js +0 -124
  11. package/lib/module/navigators/createStackNavigator.js +0 -71
  12. package/lib/module/types.js +0 -4
  13. package/lib/module/utils/CardAnimationContext.js +0 -5
  14. package/lib/module/utils/GestureHandlerRefContext.js +0 -5
  15. package/lib/module/utils/ModalPresentationContext.js +0 -5
  16. package/lib/module/utils/conditional.js +0 -28
  17. package/lib/module/utils/findLastIndex.js +0 -11
  18. package/lib/module/utils/gestureActivationCriteria.js +0 -60
  19. package/lib/module/utils/getDistanceForDirection.js +0 -15
  20. package/lib/module/utils/getInvertedMultiplier.js +0 -15
  21. package/lib/module/utils/getModalRoutesKeys.js +0 -12
  22. package/lib/module/utils/getShadowStyle.js +0 -24
  23. package/lib/module/utils/throttle.js +0 -14
  24. package/lib/module/utils/useCardAnimation.js +0 -12
  25. package/lib/module/utils/useGestureHandlerRef.js +0 -12
  26. package/lib/module/utils/useKeyboardManager.js +0 -90
  27. package/lib/module/views/GestureHandler.android.js +0 -4
  28. package/lib/module/views/GestureHandler.ios.js +0 -4
  29. package/lib/module/views/GestureHandler.js +0 -21
  30. package/lib/module/views/GestureHandler.kepler.js +0 -4
  31. package/lib/module/views/GestureHandlerNative.js +0 -18
  32. package/lib/module/views/Header/Header.js +0 -56
  33. package/lib/module/views/Header/HeaderContainer.js +0 -128
  34. package/lib/module/views/Header/HeaderSegment.js +0 -142
  35. package/lib/module/views/Screens.js +0 -42
  36. package/lib/module/views/Stack/Card.js +0 -433
  37. package/lib/module/views/Stack/CardA11yWrapper.js +0 -43
  38. package/lib/module/views/Stack/CardContainer.js +0 -276
  39. package/lib/module/views/Stack/CardContent.js +0 -74
  40. package/lib/module/views/Stack/CardStack.js +0 -498
  41. package/lib/module/views/Stack/StackView.js +0 -339
  42. package/src/TransitionConfigs/CardStyleInterpolators.tsx +0 -460
  43. package/src/TransitionConfigs/HeaderStyleInterpolators.tsx +0 -286
  44. package/src/TransitionConfigs/TransitionPresets.tsx +0 -182
  45. package/src/TransitionConfigs/TransitionSpecs.tsx +0 -124
  46. package/src/navigators/createStackNavigator.tsx +0 -120
  47. package/src/types.tsx +0 -639
  48. package/src/utils/CardAnimationContext.tsx +0 -7
  49. package/src/utils/GestureHandlerRefContext.tsx +0 -5
  50. package/src/utils/ModalPresentationContext.tsx +0 -3
  51. package/src/utils/conditional.tsx +0 -33
  52. package/src/utils/findLastIndex.tsx +0 -9
  53. package/src/utils/gestureActivationCriteria.tsx +0 -70
  54. package/src/utils/getDistanceForDirection.tsx +0 -19
  55. package/src/utils/getInvertedMultiplier.tsx +0 -17
  56. package/src/utils/getModalRoutesKeys.ts +0 -21
  57. package/src/utils/getShadowStyle.tsx +0 -37
  58. package/src/utils/throttle.tsx +0 -16
  59. package/src/utils/useCardAnimation.tsx +0 -15
  60. package/src/utils/useGestureHandlerRef.tsx +0 -15
  61. package/src/utils/useKeyboardManager.tsx +0 -103
  62. package/src/views/GestureHandler.android.tsx +0 -1
  63. package/src/views/GestureHandler.ios.tsx +0 -1
  64. package/src/views/GestureHandler.kepler.tsx +0 -1
  65. package/src/views/GestureHandler.tsx +0 -23
  66. package/src/views/GestureHandlerNative.tsx +0 -23
  67. package/src/views/Header/Header.tsx +0 -73
  68. package/src/views/Header/HeaderContainer.tsx +0 -191
  69. package/src/views/Header/HeaderSegment.tsx +0 -203
  70. package/src/views/Screens.tsx +0 -45
  71. package/src/views/Stack/Card.tsx +0 -646
  72. package/src/views/Stack/CardA11yWrapper.tsx +0 -67
  73. package/src/views/Stack/CardContainer.tsx +0 -339
  74. package/src/views/Stack/CardContent.tsx +0 -92
  75. package/src/views/Stack/CardStack.tsx +0 -849
  76. package/src/views/Stack/StackView.tsx +0 -485
@@ -1,42 +0,0 @@
1
- "use strict";
2
-
3
- import * as React from 'react';
4
- import { View } from 'react-native';
5
- import { jsx as _jsx } from "react/jsx-runtime";
6
- let Screens;
7
- try {
8
- Screens = require('@amazon-devices/react-native-screens');
9
- } catch (e) {
10
- // Ignore
11
- }
12
- export const MaybeScreenContainer = ({
13
- enabled,
14
- ...rest
15
- }) => {
16
- if (Screens != null) {
17
- return /*#__PURE__*/_jsx(Screens.ScreenContainer, {
18
- enabled: enabled,
19
- ...rest
20
- });
21
- }
22
- return /*#__PURE__*/_jsx(View, {
23
- ...rest
24
- });
25
- };
26
- export const MaybeScreen = ({
27
- enabled,
28
- active,
29
- ...rest
30
- }) => {
31
- if (Screens != null) {
32
- return /*#__PURE__*/_jsx(Screens.Screen, {
33
- enabled: enabled,
34
- activityState: active,
35
- ...rest
36
- });
37
- }
38
- return /*#__PURE__*/_jsx(View, {
39
- ...rest
40
- });
41
- };
42
- //# sourceMappingURL=Screens.js.map
@@ -1,433 +0,0 @@
1
- "use strict";
2
-
3
- import Color from 'color';
4
- import * as React from 'react';
5
- import { Animated, InteractionManager, Platform, StyleSheet, View } from 'react-native';
6
- import useLatestCallback from 'use-latest-callback';
7
- import { CardAnimationContext } from "../../utils/CardAnimationContext.js";
8
- import { gestureActivationCriteria } from "../../utils/gestureActivationCriteria.js";
9
- import { getDistanceForDirection } from "../../utils/getDistanceForDirection.js";
10
- import { getInvertedMultiplier } from "../../utils/getInvertedMultiplier.js";
11
- import { getShadowStyle } from "../../utils/getShadowStyle.js";
12
- import { GestureState, PanGestureHandler } from '../GestureHandler';
13
- import { CardContent } from "./CardContent.js";
14
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
- const GESTURE_VELOCITY_IMPACT = 0.3;
16
- const TRUE = 1;
17
- const FALSE = 0;
18
- const useNativeDriver = Platform.OS !== 'web';
19
- const hasOpacityStyle = style => {
20
- if (style) {
21
- const flattenedStyle = StyleSheet.flatten(style);
22
- return 'opacity' in flattenedStyle && flattenedStyle.opacity != null;
23
- }
24
- return false;
25
- };
26
- const getAnimateToValue = ({
27
- closing: isClosing,
28
- layout: currentLayout,
29
- gestureDirection: currentGestureDirection,
30
- direction: currentDirection,
31
- preloaded: isPreloaded
32
- }) => {
33
- if (!isClosing && !isPreloaded) {
34
- return 0;
35
- }
36
- return getDistanceForDirection(currentLayout, currentGestureDirection, currentDirection === 'rtl');
37
- };
38
- const defaultOverlay = ({
39
- style
40
- }) => style ? /*#__PURE__*/_jsx(Animated.View, {
41
- pointerEvents: "none",
42
- style: [styles.overlay, style]
43
- }) : null;
44
- function Card({
45
- shadowEnabled = false,
46
- gestureEnabled = true,
47
- gestureVelocityImpact = GESTURE_VELOCITY_IMPACT,
48
- overlay = defaultOverlay,
49
- animated,
50
- interpolationIndex,
51
- opening,
52
- closing,
53
- next,
54
- current,
55
- gesture,
56
- layout,
57
- insets,
58
- direction,
59
- pageOverflowEnabled,
60
- gestureDirection,
61
- onOpen,
62
- onClose,
63
- onTransition,
64
- onGestureBegin,
65
- onGestureCanceled,
66
- onGestureEnd,
67
- children,
68
- overlayEnabled,
69
- gestureResponseDistance,
70
- transitionSpec,
71
- preloaded,
72
- styleInterpolator,
73
- containerStyle: customContainerStyle,
74
- contentStyle
75
- }) {
76
- const [, forceUpdate] = React.useReducer(x => x + 1, 0);
77
- const didInitiallyAnimate = React.useRef(false);
78
- const lastToValueRef = React.useRef(undefined);
79
- const interactionHandleRef = React.useRef(undefined);
80
- const animationHandleRef = React.useRef(undefined);
81
- const pendingGestureCallbackRef = React.useRef(undefined);
82
- const [isClosing] = React.useState(() => new Animated.Value(FALSE));
83
- const [inverted] = React.useState(() => new Animated.Value(getInvertedMultiplier(gestureDirection, direction === 'rtl')));
84
- const [layoutAnim] = React.useState(() => ({
85
- width: new Animated.Value(layout.width),
86
- height: new Animated.Value(layout.height)
87
- }));
88
- const [isSwiping] = React.useState(() => new Animated.Value(FALSE));
89
- const onStartInteraction = useLatestCallback(() => {
90
- if (interactionHandleRef.current === undefined) {
91
- interactionHandleRef.current = InteractionManager.createInteractionHandle();
92
- }
93
- });
94
- const onEndInteraction = useLatestCallback(() => {
95
- if (interactionHandleRef.current !== undefined) {
96
- InteractionManager.clearInteractionHandle(interactionHandleRef.current);
97
- interactionHandleRef.current = undefined;
98
- }
99
- });
100
- const animate = useLatestCallback(({
101
- closing: isClosingParam,
102
- velocity
103
- }) => {
104
- const toValue = getAnimateToValue({
105
- closing: isClosingParam,
106
- layout,
107
- gestureDirection,
108
- direction,
109
- preloaded
110
- });
111
- lastToValueRef.current = toValue;
112
- isClosing.setValue(isClosingParam ? TRUE : FALSE);
113
- const spec = isClosingParam ? transitionSpec.close : transitionSpec.open;
114
- const animation = spec.animation === 'spring' ? Animated.spring : Animated.timing;
115
- clearTimeout(pendingGestureCallbackRef.current);
116
- if (animationHandleRef.current !== undefined) {
117
- cancelAnimationFrame(animationHandleRef.current);
118
- }
119
- onTransition?.({
120
- closing: isClosingParam,
121
- gesture: velocity !== undefined
122
- });
123
- const onFinish = () => {
124
- if (isClosingParam) {
125
- onClose();
126
- } else {
127
- onOpen();
128
- }
129
- animationHandleRef.current = requestAnimationFrame(() => {
130
- if (didInitiallyAnimate.current) {
131
- // Make sure to re-open screen if it wasn't removed
132
- forceUpdate();
133
- }
134
- });
135
- };
136
- if (animated) {
137
- onStartInteraction();
138
- animation(gesture, {
139
- ...spec.config,
140
- velocity,
141
- toValue,
142
- useNativeDriver,
143
- isInteraction: false
144
- }).start(({
145
- finished
146
- }) => {
147
- onEndInteraction();
148
- clearTimeout(pendingGestureCallbackRef.current);
149
- if (finished) {
150
- onFinish();
151
- }
152
- });
153
- } else {
154
- onFinish();
155
- }
156
- });
157
- const onGestureStateChange = useLatestCallback(({
158
- nativeEvent
159
- }) => {
160
- switch (nativeEvent.state) {
161
- case GestureState.ACTIVE:
162
- isSwiping.setValue(TRUE);
163
- onStartInteraction();
164
- onGestureBegin?.();
165
- break;
166
- case GestureState.CANCELLED:
167
- case GestureState.FAILED:
168
- {
169
- isSwiping.setValue(FALSE);
170
- onEndInteraction();
171
- const velocity = gestureDirection === 'vertical' || gestureDirection === 'vertical-inverted' ? nativeEvent.velocityY : nativeEvent.velocityX;
172
- animate({
173
- closing,
174
- velocity
175
- });
176
- onGestureCanceled?.();
177
- break;
178
- }
179
- case GestureState.END:
180
- {
181
- isSwiping.setValue(FALSE);
182
- let distance;
183
- let translation;
184
- let velocity;
185
- if (gestureDirection === 'vertical' || gestureDirection === 'vertical-inverted') {
186
- distance = layout.height;
187
- translation = nativeEvent.translationY;
188
- velocity = nativeEvent.velocityY;
189
- } else {
190
- distance = layout.width;
191
- translation = nativeEvent.translationX;
192
- velocity = nativeEvent.velocityX;
193
- }
194
- const shouldClose = (translation + velocity * gestureVelocityImpact) * getInvertedMultiplier(gestureDirection, direction === 'rtl') > distance / 2 ? velocity !== 0 || translation !== 0 : closing;
195
- animate({
196
- closing: shouldClose,
197
- velocity
198
- });
199
- if (shouldClose) {
200
- // We call onClose with a delay to make sure that the animation has already started
201
- // This will make sure that the state update caused by this doesn't affect start of animation
202
- pendingGestureCallbackRef.current = setTimeout(() => {
203
- onClose();
204
-
205
- // Trigger an update after we dispatch the action to remove the screen
206
- // This will make sure that we check if the screen didn't get removed so we can cancel the animation
207
- forceUpdate();
208
- }, 32);
209
- }
210
- onGestureEnd?.();
211
- break;
212
- }
213
- }
214
- });
215
- React.useLayoutEffect(() => {
216
- layoutAnim.width.setValue(layout.width);
217
- layoutAnim.height.setValue(layout.height);
218
- inverted.setValue(getInvertedMultiplier(gestureDirection, direction === 'rtl'));
219
- }, [gestureDirection, direction, inverted, layoutAnim.width, layoutAnim.height, layout.width, layout.height]);
220
- const previousPropsRef = React.useRef(null);
221
- React.useEffect(() => {
222
- return () => {
223
- onEndInteraction();
224
- if (animationHandleRef.current) {
225
- cancelAnimationFrame(animationHandleRef.current);
226
- }
227
- clearTimeout(pendingGestureCallbackRef.current);
228
- };
229
-
230
- // We only want to clean up the animation on unmount
231
- // eslint-disable-next-line react-hooks/exhaustive-deps
232
- }, []);
233
- const timeoutRef = React.useRef(null);
234
- React.useEffect(() => {
235
- if (preloaded) {
236
- return;
237
- }
238
- if (!didInitiallyAnimate.current) {
239
- // Animate the card in on initial mount
240
- // Wrap in setTimeout to ensure animation starts after
241
- // rending of the screen is done. This is especially important
242
- // in the new architecture
243
- // cf., https://github.com/react-navigation/react-navigation/issues/12401
244
- if (timeoutRef.current) {
245
- clearTimeout(timeoutRef.current);
246
- }
247
- timeoutRef.current = setTimeout(() => {
248
- didInitiallyAnimate.current = true;
249
- animate({
250
- closing
251
- });
252
- }, 0);
253
- } else {
254
- const previousOpening = previousPropsRef.current?.opening;
255
- const previousToValue = previousPropsRef.current ? getAnimateToValue(previousPropsRef.current) : null;
256
- const toValue = getAnimateToValue({
257
- closing,
258
- layout,
259
- gestureDirection,
260
- direction,
261
- preloaded
262
- });
263
- if (previousToValue !== toValue || lastToValueRef.current !== toValue) {
264
- // We need to trigger the animation when route was closed
265
- // The route might have been closed by a `POP` action or by a gesture
266
- // When route was closed due to a gesture, the animation would've happened already
267
- // It's still important to trigger the animation so that `onClose` is called
268
- // If `onClose` is not called, cleanup step won't be performed for gestures
269
- animate({
270
- closing
271
- });
272
- } else if (typeof previousOpening === 'boolean' && opening && !previousOpening) {
273
- // This can happen when screen somewhere below in the stack comes into focus via rearranging
274
- // Also reset the animated value to make sure that the animation starts from the beginning
275
- gesture.setValue(getDistanceForDirection(layout, gestureDirection, direction === 'rtl'));
276
- animate({
277
- closing
278
- });
279
- }
280
- }
281
- previousPropsRef.current = {
282
- opening,
283
- closing,
284
- layout,
285
- gestureDirection,
286
- direction,
287
- preloaded
288
- };
289
- }, [animate, closing, direction, gesture, gestureDirection, layout, opening, preloaded]);
290
- const interpolationProps = React.useMemo(() => ({
291
- index: interpolationIndex,
292
- current: {
293
- progress: current
294
- },
295
- next: next && {
296
- progress: next
297
- },
298
- closing: isClosing,
299
- swiping: isSwiping,
300
- inverted,
301
- layouts: {
302
- screen: layout
303
- },
304
- insets: {
305
- top: insets.top,
306
- right: insets.right,
307
- bottom: insets.bottom,
308
- left: insets.left
309
- }
310
- }), [interpolationIndex, current, next, isClosing, isSwiping, inverted, layout, insets.top, insets.right, insets.bottom, insets.left]);
311
- const {
312
- containerStyle,
313
- cardStyle,
314
- overlayStyle,
315
- shadowStyle
316
- } = React.useMemo(() => styleInterpolator(interpolationProps), [styleInterpolator, interpolationProps]);
317
- const onGestureEvent = React.useMemo(() => gestureEnabled ? Animated.event([{
318
- nativeEvent: gestureDirection === 'vertical' || gestureDirection === 'vertical-inverted' ? {
319
- translationY: gesture
320
- } : {
321
- translationX: gesture
322
- }
323
- }], {
324
- useNativeDriver
325
- }) : undefined, [gesture, gestureDirection, gestureEnabled]);
326
- const {
327
- backgroundColor
328
- } = StyleSheet.flatten(contentStyle || {});
329
- const isTransparent = typeof backgroundColor === 'string' ? Color(backgroundColor).alpha() === 0 : false;
330
- return /*#__PURE__*/_jsxs(CardAnimationContext.Provider, {
331
- value: interpolationProps,
332
- children: [Platform.OS !== 'web' ? /*#__PURE__*/_jsx(Animated.View, {
333
- style: {
334
- // This is a dummy style that doesn't actually change anything visually.
335
- // Animated needs the animated value to be used somewhere, otherwise things don't update properly.
336
- // If we disable animations and hide header, it could end up making the value unused.
337
- // So we have this dummy style that will always be used regardless of what else changed.
338
- opacity: current
339
- }
340
- // Make sure that this view isn't removed. If this view is removed, our style with animated value won't apply
341
- ,
342
- collapsable: false
343
- }) : null, overlayEnabled ? /*#__PURE__*/_jsx(View, {
344
- pointerEvents: "box-none",
345
- style: StyleSheet.absoluteFill,
346
- children: overlay({
347
- style: overlayStyle
348
- })
349
- }) : null, /*#__PURE__*/_jsx(Animated.View, {
350
- pointerEvents: "box-none",
351
- style: [styles.container, containerStyle, customContainerStyle],
352
- children: /*#__PURE__*/_jsx(PanGestureHandler, {
353
- enabled: layout.width !== 0 && gestureEnabled,
354
- onGestureEvent: onGestureEvent,
355
- onHandlerStateChange: onGestureStateChange,
356
- ...gestureActivationCriteria({
357
- layout,
358
- direction,
359
- gestureDirection,
360
- gestureResponseDistance
361
- }),
362
- children: /*#__PURE__*/_jsxs(Animated.View, {
363
- pointerEvents: "box-none",
364
- needsOffscreenAlphaCompositing: hasOpacityStyle(cardStyle),
365
- style: [styles.container, cardStyle],
366
- children: [shadowEnabled && shadowStyle && !isTransparent ? /*#__PURE__*/_jsx(Animated.View, {
367
- pointerEvents: "none",
368
- style: [styles.shadow, gestureDirection === 'horizontal' ? [styles.shadowHorizontal, styles.shadowStart] : gestureDirection === 'horizontal-inverted' ? [styles.shadowHorizontal, styles.shadowEnd] : gestureDirection === 'vertical' ? [styles.shadowVertical, styles.shadowTop] : [styles.shadowVertical, styles.shadowBottom], {
369
- backgroundColor
370
- }, shadowStyle]
371
- }) : null, /*#__PURE__*/_jsx(CardContent, {
372
- enabled: pageOverflowEnabled,
373
- layout: layout,
374
- style: contentStyle,
375
- children: children
376
- })]
377
- })
378
- })
379
- })]
380
- });
381
- }
382
- export { Card };
383
- const styles = StyleSheet.create({
384
- container: {
385
- flex: 1
386
- },
387
- overlay: {
388
- flex: 1,
389
- backgroundColor: '#000'
390
- },
391
- shadow: {
392
- position: 'absolute'
393
- },
394
- shadowHorizontal: {
395
- top: 0,
396
- bottom: 0,
397
- width: 3,
398
- ...getShadowStyle({
399
- offset: {
400
- width: -1,
401
- height: 1
402
- },
403
- radius: 5,
404
- opacity: 0.3
405
- })
406
- },
407
- shadowStart: {
408
- start: 0
409
- },
410
- shadowEnd: {
411
- end: 0
412
- },
413
- shadowVertical: {
414
- start: 0,
415
- end: 0,
416
- height: 3,
417
- ...getShadowStyle({
418
- offset: {
419
- width: 1,
420
- height: -1
421
- },
422
- radius: 5,
423
- opacity: 0.3
424
- })
425
- },
426
- shadowTop: {
427
- top: 0
428
- },
429
- shadowBottom: {
430
- bottom: 0
431
- }
432
- });
433
- //# sourceMappingURL=Card.js.map
@@ -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
- pointerEvents: (animated ? inert : !focused) ? 'none' : 'box-none',
24
- style: [StyleSheet.absoluteFill, {
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