@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,339 +0,0 @@
1
- "use strict";
2
-
3
- import { HeaderShownContext, SafeAreaProviderCompat } from '@amazon-devices/react-navigation__elements';
4
- import { CommonActions, StackActions } from '@amazon-devices/react-navigation__native';
5
- import * as React from 'react';
6
- import { StyleSheet, View } from 'react-native';
7
- import { SafeAreaInsetsContext } from '@amazon-devices/react-native-safe-area-context';
8
- import { ModalPresentationContext } from "../../utils/ModalPresentationContext.js";
9
- import { GestureHandlerRootView } from '../GestureHandler';
10
- import { HeaderContainer } from "../Header/HeaderContainer.js";
11
- import { CardStack, getAnimationEnabled } from "./CardStack.js";
12
- import { jsx as _jsx } from "react/jsx-runtime";
13
- const GestureHandlerWrapper = GestureHandlerRootView ?? View;
14
-
15
- /**
16
- * Compare two arrays with primitive values as the content.
17
- * We need to make sure that both values and order match.
18
- */
19
- const isArrayEqual = (a, b) => a.length === b.length && a.every((it, index) => Object.is(it, b[index]));
20
- export class StackView extends React.Component {
21
- static getDerivedStateFromProps(props, state) {
22
- // If there was no change in routes, we don't need to compute anything
23
- if ((props.state.routes === state.previousRoutes || isArrayEqual(props.state.routes.map(r => r.key), state.previousRoutes.map(r => r.key))) && state.routes.length) {
24
- let routes = state.routes;
25
- let previousRoutes = state.previousRoutes;
26
- let descriptors = props.descriptors;
27
- let previousDescriptors = state.previousDescriptors;
28
- if (props.descriptors !== state.previousDescriptors) {
29
- descriptors = state.routes.reduce((acc, route) => {
30
- acc[route.key] = props.descriptors[route.key] || state.descriptors[route.key];
31
- return acc;
32
- }, {});
33
- previousDescriptors = props.descriptors;
34
- }
35
- if (props.state.routes !== state.previousRoutes) {
36
- // if any route objects have changed, we should update them
37
- const map = props.state.routes.reduce((acc, route) => {
38
- acc[route.key] = route;
39
- return acc;
40
- }, {});
41
- routes = state.routes.map(route => map[route.key] || route);
42
- previousRoutes = props.state.routes;
43
- }
44
- return {
45
- routes,
46
- previousRoutes,
47
- descriptors,
48
- previousDescriptors
49
- };
50
- }
51
-
52
- // Here we determine which routes were added or removed to animate them
53
- // We keep a copy of the route being removed in local state to be able to animate it
54
-
55
- let routes = props.state.index < props.state.routes.length - 1 ?
56
- // Remove any extra routes from the state
57
- // The last visible route should be the focused route, i.e. at current index
58
- props.state.routes.slice(0, props.state.index + 1) : props.state.routes;
59
-
60
- // Now we need to determine which routes were added and removed
61
- const {
62
- previousRoutes
63
- } = state;
64
- let {
65
- openingRouteKeys,
66
- closingRouteKeys,
67
- replacingRouteKeys
68
- } = state;
69
- const previousFocusedRoute = previousRoutes[previousRoutes.length - 1];
70
- const nextFocusedRoute = routes[routes.length - 1];
71
- const isAnimationEnabled = key => {
72
- const descriptor = props.descriptors[key] || state.descriptors[key];
73
- return getAnimationEnabled(descriptor?.options.animation);
74
- };
75
- const getAnimationTypeForReplace = key => {
76
- const descriptor = props.descriptors[key] || state.descriptors[key];
77
- return descriptor.options.animationTypeForReplace ?? 'push';
78
- };
79
- if (previousFocusedRoute && previousFocusedRoute.key !== nextFocusedRoute.key) {
80
- // We only need to animate routes if the focused route changed
81
- // Animating previous routes won't be visible coz the focused route is on top of everything
82
-
83
- if (previousRoutes.some(r => r.key === nextFocusedRoute.key) && !routes.some(r => r.key === previousFocusedRoute.key)) {
84
- // The previously focused route was removed, and the new focused route was already present
85
- // We treat this as a pop
86
-
87
- if (isAnimationEnabled(previousFocusedRoute.key) && !closingRouteKeys.includes(previousFocusedRoute.key)) {
88
- closingRouteKeys = [...closingRouteKeys, previousFocusedRoute.key];
89
-
90
- // Sometimes a route can be closed before the opening animation finishes
91
- // So we also need to remove it from the opening list
92
- openingRouteKeys = openingRouteKeys.filter(key => key !== previousFocusedRoute.key);
93
- replacingRouteKeys = replacingRouteKeys.filter(key => key !== previousFocusedRoute.key);
94
-
95
- // Keep a copy of route being removed in the state to be able to animate it
96
- routes = [...routes, previousFocusedRoute];
97
- }
98
- } else {
99
- // A route has come to the focus, we treat this as a push
100
- // A replace or rearranging can also trigger this
101
- // The animation should look like push
102
-
103
- if (isAnimationEnabled(nextFocusedRoute.key) && !openingRouteKeys.includes(nextFocusedRoute.key)) {
104
- // In this case, we need to animate pushing the focused route
105
- // We don't care about animating any other added routes because they won't be visible
106
- openingRouteKeys = [...openingRouteKeys, nextFocusedRoute.key];
107
- closingRouteKeys = closingRouteKeys.filter(key => key !== nextFocusedRoute.key);
108
- replacingRouteKeys = replacingRouteKeys.filter(key => key !== nextFocusedRoute.key);
109
- if (!routes.some(r => r.key === previousFocusedRoute.key)) {
110
- // The previous focused route isn't present in state, we treat this as a replace
111
-
112
- openingRouteKeys = openingRouteKeys.filter(key => key !== previousFocusedRoute.key);
113
- if (getAnimationTypeForReplace(nextFocusedRoute.key) === 'pop') {
114
- closingRouteKeys = [...closingRouteKeys, previousFocusedRoute.key];
115
-
116
- // By default, new routes have a push animation, so we add it to `openingRouteKeys` before
117
- // But since user configured it to animate the old screen like a pop, we need to add this without animation
118
- // So remove it from `openingRouteKeys` which will remove the animation
119
- openingRouteKeys = openingRouteKeys.filter(key => key !== nextFocusedRoute.key);
120
-
121
- // Keep the route being removed at the end to animate it out
122
- routes = [...routes, previousFocusedRoute];
123
- } else {
124
- replacingRouteKeys = [...replacingRouteKeys, previousFocusedRoute.key];
125
- closingRouteKeys = closingRouteKeys.filter(key => key !== previousFocusedRoute.key);
126
-
127
- // Keep the old route in the state because it's visible under the new route, and removing it will feel abrupt
128
- // We need to insert it just before the focused one (the route being pushed)
129
- // After the push animation is completed, routes being replaced will be removed completely
130
- routes = routes.slice();
131
- routes.splice(routes.length - 1, 0, previousFocusedRoute);
132
- }
133
- }
134
- }
135
- }
136
- } else if (replacingRouteKeys.length || closingRouteKeys.length) {
137
- // Keep the routes we are closing or replacing if animation is enabled for them
138
- routes = routes.slice();
139
- routes.splice(routes.length - 1, 0, ...state.routes.filter(({
140
- key
141
- }) => isAnimationEnabled(key) ? replacingRouteKeys.includes(key) || closingRouteKeys.includes(key) : false));
142
- }
143
- if (!routes.length) {
144
- throw new Error('There should always be at least one route in the navigation state.');
145
- }
146
- const descriptors = routes.reduce((acc, route) => {
147
- acc[route.key] = props.descriptors[route.key] || state.descriptors[route.key];
148
- return acc;
149
- }, {});
150
- return {
151
- routes,
152
- previousRoutes: props.state.routes,
153
- previousDescriptors: props.descriptors,
154
- openingRouteKeys,
155
- closingRouteKeys,
156
- replacingRouteKeys,
157
- descriptors
158
- };
159
- }
160
- state = {
161
- routes: [],
162
- previousRoutes: [],
163
- previousDescriptors: {},
164
- openingRouteKeys: [],
165
- closingRouteKeys: [],
166
- replacingRouteKeys: [],
167
- descriptors: {}
168
- };
169
- getPreviousRoute = ({
170
- route
171
- }) => {
172
- const {
173
- closingRouteKeys,
174
- replacingRouteKeys
175
- } = this.state;
176
- const routes = this.state.routes.filter(r => r.key === route.key || !closingRouteKeys.includes(r.key) && !replacingRouteKeys.includes(r.key));
177
- const index = routes.findIndex(r => r.key === route.key);
178
- return routes[index - 1];
179
- };
180
- renderHeader = props => {
181
- return /*#__PURE__*/_jsx(HeaderContainer, {
182
- ...props
183
- });
184
- };
185
- handleOpenRoute = ({
186
- route
187
- }) => {
188
- const {
189
- state,
190
- navigation
191
- } = this.props;
192
- const {
193
- closingRouteKeys,
194
- replacingRouteKeys
195
- } = this.state;
196
- if (closingRouteKeys.some(key => key === route.key) && replacingRouteKeys.every(key => key !== route.key) && state.routeNames.includes(route.name) && !state.routes.some(r => r.key === route.key)) {
197
- // If route isn't present in current state, but was closing, assume that a close animation was cancelled
198
- // So we need to add this route back to the state
199
- navigation.dispatch(state => {
200
- const routes = [...state.routes.filter(r => r.key !== route.key), route];
201
- return CommonActions.reset({
202
- ...state,
203
- routes,
204
- index: routes.length - 1
205
- });
206
- });
207
- } else {
208
- this.setState(state => ({
209
- routes: state.replacingRouteKeys.length ? state.routes.filter(r => !state.replacingRouteKeys.includes(r.key)) : state.routes,
210
- openingRouteKeys: state.openingRouteKeys.filter(key => key !== route.key),
211
- closingRouteKeys: state.closingRouteKeys.filter(key => key !== route.key),
212
- replacingRouteKeys: []
213
- }));
214
- }
215
- };
216
- handleCloseRoute = ({
217
- route
218
- }) => {
219
- const {
220
- state,
221
- navigation
222
- } = this.props;
223
- if (state.routes.some(r => r.key === route.key)) {
224
- // If a route exists in state, trigger a pop
225
- // This will happen in when the route was closed from the card component
226
- // e.g. When the close animation triggered from a gesture ends
227
- navigation.dispatch({
228
- ...StackActions.pop(),
229
- source: route.key,
230
- target: state.key
231
- });
232
- } else {
233
- // We need to clean up any state tracking the route and pop it immediately
234
- this.setState(state => ({
235
- routes: state.routes.filter(r => r.key !== route.key),
236
- openingRouteKeys: state.openingRouteKeys.filter(key => key !== route.key),
237
- closingRouteKeys: state.closingRouteKeys.filter(key => key !== route.key)
238
- }));
239
- }
240
- };
241
- handleTransitionStart = ({
242
- route
243
- }, closing) => this.props.navigation.emit({
244
- type: 'transitionStart',
245
- data: {
246
- closing
247
- },
248
- target: route.key
249
- });
250
- handleTransitionEnd = ({
251
- route
252
- }, closing) => this.props.navigation.emit({
253
- type: 'transitionEnd',
254
- data: {
255
- closing
256
- },
257
- target: route.key
258
- });
259
- handleGestureStart = ({
260
- route
261
- }) => {
262
- this.props.navigation.emit({
263
- type: 'gestureStart',
264
- target: route.key
265
- });
266
- };
267
- handleGestureEnd = ({
268
- route
269
- }) => {
270
- this.props.navigation.emit({
271
- type: 'gestureEnd',
272
- target: route.key
273
- });
274
- };
275
- handleGestureCancel = ({
276
- route
277
- }) => {
278
- this.props.navigation.emit({
279
- type: 'gestureCancel',
280
- target: route.key
281
- });
282
- };
283
- render() {
284
- const {
285
- state,
286
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
287
- descriptors: _,
288
- ...rest
289
- } = this.props;
290
- const {
291
- routes,
292
- descriptors,
293
- openingRouteKeys,
294
- closingRouteKeys
295
- } = this.state;
296
- const preloadedDescriptors = state.preloadedRoutes.reduce((acc, route) => {
297
- acc[route.key] = acc[route.key] || this.props.describe(route, true);
298
- return acc;
299
- }, {});
300
- return /*#__PURE__*/_jsx(GestureHandlerWrapper, {
301
- style: styles.container,
302
- children: /*#__PURE__*/_jsx(SafeAreaProviderCompat, {
303
- children: /*#__PURE__*/_jsx(SafeAreaInsetsContext.Consumer, {
304
- children: insets => /*#__PURE__*/_jsx(ModalPresentationContext.Consumer, {
305
- children: isParentModal => /*#__PURE__*/_jsx(HeaderShownContext.Consumer, {
306
- children: isParentHeaderShown => /*#__PURE__*/_jsx(CardStack, {
307
- insets: insets,
308
- isParentHeaderShown: isParentHeaderShown,
309
- isParentModal: isParentModal,
310
- getPreviousRoute: this.getPreviousRoute,
311
- routes: routes,
312
- openingRouteKeys: openingRouteKeys,
313
- closingRouteKeys: closingRouteKeys,
314
- onOpenRoute: this.handleOpenRoute,
315
- onCloseRoute: this.handleCloseRoute,
316
- onTransitionStart: this.handleTransitionStart,
317
- onTransitionEnd: this.handleTransitionEnd,
318
- renderHeader: this.renderHeader,
319
- state: state,
320
- descriptors: descriptors,
321
- onGestureStart: this.handleGestureStart,
322
- onGestureEnd: this.handleGestureEnd,
323
- onGestureCancel: this.handleGestureCancel,
324
- preloadedDescriptors: preloadedDescriptors,
325
- ...rest
326
- })
327
- })
328
- })
329
- })
330
- })
331
- });
332
- }
333
- }
334
- const styles = StyleSheet.create({
335
- container: {
336
- flex: 1
337
- }
338
- });
339
- //# sourceMappingURL=StackView.js.map