@react-navigation/stack 7.0.13 → 7.0.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.
@@ -17,19 +17,6 @@ var _CardContainer = require("./CardContainer.js");
17
17
  var _jsxRuntime = require("react/jsx-runtime");
18
18
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
19
19
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
20
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
21
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
22
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
23
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
24
- function _possibleConstructorReturn(t, e) { if (e && ("object" == typeof e || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
25
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
26
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); }
27
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
28
- function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
29
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
30
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
31
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
32
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
33
20
  const NAMED_TRANSITIONS_PRESETS = {
34
21
  default: _TransitionPresets.DefaultTransition,
35
22
  fade: _TransitionPresets.ModalFadeTransition,
@@ -124,79 +111,110 @@ const getProgressFromGesture = (gesture, layout, descriptor, isRTL) => {
124
111
  outputRange: [0, 1]
125
112
  });
126
113
  };
127
- let CardStack = exports.CardStack = /*#__PURE__*/function (_React$Component) {
128
- function CardStack(_props) {
129
- var _this;
130
- _classCallCheck(this, CardStack);
131
- _this = _callSuper(this, CardStack, [_props]);
132
- _defineProperty(_this, "handleLayout", e => {
133
- const {
134
- height,
135
- width
136
- } = e.nativeEvent.layout;
137
- const layout = {
138
- width,
139
- height
140
- };
141
- _this.setState((state, props) => {
142
- if (height === state.layout.height && width === state.layout.width) {
143
- return null;
144
- }
145
- return {
146
- layout,
147
- headerHeights: getHeaderHeights(state.scenes, props.insets, props.isParentHeaderShown, props.isParentModal, layout, state.headerHeights)
148
- };
149
- });
150
- });
151
- _defineProperty(_this, "handleHeaderLayout", ({
152
- route,
153
- height
154
- }) => {
155
- _this.setState(({
156
- headerHeights
157
- }) => {
158
- const previousHeight = headerHeights[route.key];
159
- if (previousHeight === height) {
160
- return null;
161
- }
162
- return {
163
- headerHeights: {
164
- ...headerHeights,
165
- [route.key]: height
166
- }
167
- };
168
- });
169
- });
170
- _defineProperty(_this, "getFocusedRoute", () => {
114
+ class CardStack extends React.Component {
115
+ static getDerivedStateFromProps(props, state) {
116
+ if (props.routes === state.routes && props.descriptors === state.descriptors) {
117
+ return null;
118
+ }
119
+ const gestures = [...props.routes, ...props.state.preloadedRoutes].reduce((acc, curr) => {
120
+ const descriptor = props.descriptors[curr.key] || props.preloadedDescriptors[curr.key];
171
121
  const {
172
- state
173
- } = _this.props;
174
- return state.routes[state.index];
122
+ animation
123
+ } = descriptor?.options || {};
124
+ acc[curr.key] = state.gestures[curr.key] || new _reactNative.Animated.Value(props.openingRouteKeys.includes(curr.key) && animation !== 'none' || props.state.preloadedRoutes.includes(curr) ? getDistanceFromOptions(state.layout, descriptor, props.direction === 'rtl') : 0);
125
+ return acc;
126
+ }, {});
127
+ const modalRouteKeys = (0, _getModalRoutesKeys.getModalRouteKeys)([...props.routes, ...props.state.preloadedRoutes], {
128
+ ...props.descriptors,
129
+ ...props.preloadedDescriptors
175
130
  });
176
- _defineProperty(_this, "getPreviousScene", ({
177
- route
178
- }) => {
179
- const {
180
- getPreviousRoute
181
- } = _this.props;
131
+ const scenes = [...props.routes, ...props.state.preloadedRoutes].map((route, index, self) => {
132
+ // For preloaded screens, we don't care about the previous and the next screen
133
+ const isPreloaded = props.state.preloadedRoutes.includes(route);
134
+ const previousRoute = isPreloaded ? undefined : self[index - 1];
135
+ const nextRoute = isPreloaded ? undefined : self[index + 1];
136
+ const oldScene = state.scenes[index];
137
+ const currentGesture = gestures[route.key];
138
+ const previousGesture = previousRoute ? gestures[previousRoute.key] : undefined;
139
+ const nextGesture = nextRoute ? gestures[nextRoute.key] : undefined;
140
+ const descriptor = (isPreloaded ? props.preloadedDescriptors : props.descriptors)[route.key] || state.descriptors[route.key] || (oldScene ? oldScene.descriptor : FALLBACK_DESCRIPTOR);
141
+ const nextDescriptor = nextRoute && (props.descriptors[nextRoute?.key] || state.descriptors[nextRoute?.key]);
142
+ const previousDescriptor = previousRoute && (props.descriptors[previousRoute?.key] || state.descriptors[previousRoute?.key]);
143
+
144
+ // When a screen is not the last, it should use next screen's transition config
145
+ // Many transitions also animate the previous screen, so using 2 different transitions doesn't look right
146
+ // For example combining a slide and a modal transition would look wrong otherwise
147
+ // With this approach, combining different transition styles in the same navigator mostly looks right
148
+ // This will still be broken when 2 transitions have different idle state (e.g. modal presentation),
149
+ // but the majority of the transitions look alright
150
+ const optionsForTransitionConfig = index !== self.length - 1 && nextDescriptor && nextDescriptor.options.presentation !== 'transparentModal' ? nextDescriptor.options : descriptor.options;
151
+
152
+ // Assume modal if there are already modal screens in the stack
153
+ // or current screen is a modal when no presentation is specified
154
+ const isModal = modalRouteKeys.includes(route.key);
155
+
156
+ // Disable screen transition animation by default on web, windows and macos to match the native behavior
157
+ const excludedPlatforms = _reactNative.Platform.OS !== 'web' && _reactNative.Platform.OS !== 'windows' && _reactNative.Platform.OS !== 'macos';
158
+ const animation = optionsForTransitionConfig.animation ?? (excludedPlatforms ? 'default' : 'none');
159
+ const isAnimationEnabled = animation !== 'none';
160
+ const transitionPreset = animation !== 'default' ? NAMED_TRANSITIONS_PRESETS[animation] : isModal || optionsForTransitionConfig.presentation === 'modal' ? _TransitionPresets.ModalTransition : optionsForTransitionConfig.presentation === 'transparentModal' ? _TransitionPresets.ModalFadeTransition : _TransitionPresets.DefaultTransition;
182
161
  const {
183
- scenes
184
- } = _this.state;
185
- const previousRoute = getPreviousRoute({
186
- route
187
- });
188
- if (previousRoute) {
189
- const previousScene = scenes.find(scene => scene.descriptor.route.key === previousRoute.key);
190
- return previousScene;
162
+ gestureEnabled = _reactNative.Platform.OS === 'ios' && isAnimationEnabled,
163
+ gestureDirection = transitionPreset.gestureDirection,
164
+ transitionSpec = transitionPreset.transitionSpec,
165
+ cardStyleInterpolator = isAnimationEnabled ? transitionPreset.cardStyleInterpolator : _CardStyleInterpolators.forNoAnimation,
166
+ headerStyleInterpolator = transitionPreset.headerStyleInterpolator,
167
+ cardOverlayEnabled = _reactNative.Platform.OS !== 'ios' && optionsForTransitionConfig.presentation !== 'transparentModal' || getIsModalPresentation(cardStyleInterpolator)
168
+ } = optionsForTransitionConfig;
169
+ const headerMode = descriptor.options.headerMode ?? (!(optionsForTransitionConfig.presentation === 'modal' || optionsForTransitionConfig.presentation === 'transparentModal' || nextDescriptor?.options.presentation === 'modal' || nextDescriptor?.options.presentation === 'transparentModal' || getIsModalPresentation(cardStyleInterpolator)) && _reactNative.Platform.OS === 'ios' && descriptor.options.header === undefined ? 'float' : 'screen');
170
+ const isRTL = props.direction === 'rtl';
171
+ const scene = {
172
+ route,
173
+ descriptor: {
174
+ ...descriptor,
175
+ options: {
176
+ ...descriptor.options,
177
+ animation,
178
+ cardOverlayEnabled,
179
+ cardStyleInterpolator,
180
+ gestureDirection,
181
+ gestureEnabled,
182
+ headerStyleInterpolator,
183
+ transitionSpec,
184
+ headerMode
185
+ }
186
+ },
187
+ progress: {
188
+ current: getProgressFromGesture(currentGesture, state.layout, descriptor, isRTL),
189
+ next: nextGesture && nextDescriptor?.options.presentation !== 'transparentModal' ? getProgressFromGesture(nextGesture, state.layout, nextDescriptor, isRTL) : undefined,
190
+ previous: previousGesture ? getProgressFromGesture(previousGesture, state.layout, previousDescriptor, isRTL) : undefined
191
+ },
192
+ __memo: [state.layout, descriptor, nextDescriptor, previousDescriptor, currentGesture, nextGesture, previousGesture]
193
+ };
194
+ if (oldScene && scene.__memo.every((it, i) => {
195
+ // @ts-expect-error: we haven't added __memo to the annotation to prevent usage elsewhere
196
+ return oldScene.__memo[i] === it;
197
+ })) {
198
+ return oldScene;
191
199
  }
192
- return undefined;
200
+ return scene;
193
201
  });
194
- _this.state = {
202
+ return {
203
+ routes: props.routes,
204
+ scenes,
205
+ gestures,
206
+ descriptors: props.descriptors,
207
+ headerHeights: getHeaderHeights(scenes, props.insets, props.isParentHeaderShown, props.isParentModal, state.layout, state.headerHeights)
208
+ };
209
+ }
210
+ constructor(props) {
211
+ super(props);
212
+ this.state = {
195
213
  routes: [],
196
214
  scenes: [],
197
215
  gestures: {},
198
216
  layout: _elements.SafeAreaProviderCompat.initialMetrics.frame,
199
- descriptors: _this.props.descriptors,
217
+ descriptors: this.props.descriptors,
200
218
  // Used when card's header is null and mode is float to make transition
201
219
  // between screens with headers and those without headers smooth.
202
220
  // This is not a great heuristic here. We don't know synchronously
@@ -204,289 +222,250 @@ let CardStack = exports.CardStack = /*#__PURE__*/function (_React$Component) {
204
222
  // common cases here.
205
223
  headerHeights: {}
206
224
  };
207
- return _this;
208
225
  }
209
- _inherits(CardStack, _React$Component);
210
- return _createClass(CardStack, [{
211
- key: "render",
212
- value: function render() {
213
- const {
214
- insets,
215
- state,
216
- routes,
217
- openingRouteKeys,
218
- closingRouteKeys,
219
- onOpenRoute,
220
- onCloseRoute,
221
- renderHeader,
222
- isParentHeaderShown,
223
- isParentModal,
224
- onTransitionStart,
225
- onTransitionEnd,
226
- onGestureStart,
227
- onGestureEnd,
228
- onGestureCancel,
229
- detachInactiveScreens = _reactNative.Platform.OS === 'web' || _reactNative.Platform.OS === 'android' || _reactNative.Platform.OS === 'ios'
230
- } = this.props;
231
- const {
232
- scenes,
226
+ handleLayout = e => {
227
+ const {
228
+ height,
229
+ width
230
+ } = e.nativeEvent.layout;
231
+ const layout = {
232
+ width,
233
+ height
234
+ };
235
+ this.setState((state, props) => {
236
+ if (height === state.layout.height && width === state.layout.width) {
237
+ return null;
238
+ }
239
+ return {
233
240
  layout,
234
- gestures,
235
- headerHeights
236
- } = this.state;
237
- const focusedRoute = state.routes[state.index];
238
- const focusedHeaderHeight = headerHeights[focusedRoute.key];
239
- const isFloatHeaderAbsolute = this.state.scenes.slice(-2).some(scene => {
240
- const options = scene.descriptor.options ?? {};
241
- const {
242
- headerMode,
243
- headerTransparent,
244
- headerShown = true
245
- } = options;
246
- if (headerTransparent || headerShown === false || headerMode === 'screen') {
247
- return true;
241
+ headerHeights: getHeaderHeights(state.scenes, props.insets, props.isParentHeaderShown, props.isParentModal, layout, state.headerHeights)
242
+ };
243
+ });
244
+ };
245
+ handleHeaderLayout = ({
246
+ route,
247
+ height
248
+ }) => {
249
+ this.setState(({
250
+ headerHeights
251
+ }) => {
252
+ const previousHeight = headerHeights[route.key];
253
+ if (previousHeight === height) {
254
+ return null;
255
+ }
256
+ return {
257
+ headerHeights: {
258
+ ...headerHeights,
259
+ [route.key]: height
248
260
  }
249
- return false;
250
- });
251
- let activeScreensLimit = 1;
252
- for (let i = scenes.length - 1; i >= 0; i--) {
253
- const {
254
- options
255
- } = scenes[i].descriptor;
256
- const {
257
- // By default, we don't want to detach the previous screen of the active one for modals
258
- detachPreviousScreen = options.presentation === 'transparentModal' ? false : getIsModalPresentation(options.cardStyleInterpolator) ? i !== (0, _findLastIndex.findLastIndex)(scenes, scene => {
259
- const {
260
- cardStyleInterpolator
261
- } = scene.descriptor.options;
262
- return cardStyleInterpolator === _CardStyleInterpolators.forModalPresentationIOS || cardStyleInterpolator?.name === 'forModalPresentationIOS';
263
- }) : true
264
- } = options;
265
- if (detachPreviousScreen === false) {
266
- activeScreensLimit++;
267
- } else {
268
- // Check at least last 2 screens before stopping
269
- // This will make sure that screen isn't detached when another screen is animating on top of the transparent one
270
- // For example, (Opaque -> Transparent -> Opaque)
271
- if (i <= scenes.length - 2) {
272
- break;
273
- }
261
+ };
262
+ });
263
+ };
264
+ getFocusedRoute = () => {
265
+ const {
266
+ state
267
+ } = this.props;
268
+ return state.routes[state.index];
269
+ };
270
+ getPreviousScene = ({
271
+ route
272
+ }) => {
273
+ const {
274
+ getPreviousRoute
275
+ } = this.props;
276
+ const {
277
+ scenes
278
+ } = this.state;
279
+ const previousRoute = getPreviousRoute({
280
+ route
281
+ });
282
+ if (previousRoute) {
283
+ const previousScene = scenes.find(scene => scene.descriptor.route.key === previousRoute.key);
284
+ return previousScene;
285
+ }
286
+ return undefined;
287
+ };
288
+ render() {
289
+ const {
290
+ insets,
291
+ state,
292
+ routes,
293
+ openingRouteKeys,
294
+ closingRouteKeys,
295
+ onOpenRoute,
296
+ onCloseRoute,
297
+ renderHeader,
298
+ isParentHeaderShown,
299
+ isParentModal,
300
+ onTransitionStart,
301
+ onTransitionEnd,
302
+ onGestureStart,
303
+ onGestureEnd,
304
+ onGestureCancel,
305
+ detachInactiveScreens = _reactNative.Platform.OS === 'web' || _reactNative.Platform.OS === 'android' || _reactNative.Platform.OS === 'ios'
306
+ } = this.props;
307
+ const {
308
+ scenes,
309
+ layout,
310
+ gestures,
311
+ headerHeights
312
+ } = this.state;
313
+ const focusedRoute = state.routes[state.index];
314
+ const focusedHeaderHeight = headerHeights[focusedRoute.key];
315
+ const isFloatHeaderAbsolute = this.state.scenes.slice(-2).some(scene => {
316
+ const options = scene.descriptor.options ?? {};
317
+ const {
318
+ headerMode,
319
+ headerTransparent,
320
+ headerShown = true
321
+ } = options;
322
+ if (headerTransparent || headerShown === false || headerMode === 'screen') {
323
+ return true;
324
+ }
325
+ return false;
326
+ });
327
+ let activeScreensLimit = 1;
328
+ for (let i = scenes.length - 1; i >= 0; i--) {
329
+ const {
330
+ options
331
+ } = scenes[i].descriptor;
332
+ const {
333
+ // By default, we don't want to detach the previous screen of the active one for modals
334
+ detachPreviousScreen = options.presentation === 'transparentModal' ? false : getIsModalPresentation(options.cardStyleInterpolator) ? i !== (0, _findLastIndex.findLastIndex)(scenes, scene => {
335
+ const {
336
+ cardStyleInterpolator
337
+ } = scene.descriptor.options;
338
+ return cardStyleInterpolator === _CardStyleInterpolators.forModalPresentationIOS || cardStyleInterpolator?.name === 'forModalPresentationIOS';
339
+ }) : true
340
+ } = options;
341
+ if (detachPreviousScreen === false) {
342
+ activeScreensLimit++;
343
+ } else {
344
+ // Check at least last 2 screens before stopping
345
+ // This will make sure that screen isn't detached when another screen is animating on top of the transparent one
346
+ // For example, (Opaque -> Transparent -> Opaque)
347
+ if (i <= scenes.length - 2) {
348
+ break;
274
349
  }
275
350
  }
276
- const floatingHeader = /*#__PURE__*/(0, _jsxRuntime.jsx)(React.Fragment, {
277
- children: renderHeader({
278
- mode: 'float',
279
- layout,
280
- scenes,
281
- getPreviousScene: this.getPreviousScene,
282
- getFocusedRoute: this.getFocusedRoute,
283
- onContentHeightChange: this.handleHeaderLayout,
284
- style: [styles.floating, isFloatHeaderAbsolute && [
285
- // Without this, the header buttons won't be touchable on Android when headerTransparent: true
286
- {
287
- height: focusedHeaderHeight
288
- }, styles.absolute]]
289
- })
290
- }, "header");
291
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
292
- style: styles.container,
293
- children: [isFloatHeaderAbsolute ? null : floatingHeader, /*#__PURE__*/(0, _jsxRuntime.jsx)(_Screens.MaybeScreenContainer, {
294
- enabled: detachInactiveScreens,
295
- style: styles.container,
296
- onLayout: this.handleLayout,
297
- children: [...routes, ...state.preloadedRoutes].map((route, index) => {
298
- const focused = focusedRoute.key === route.key;
299
- const gesture = gestures[route.key];
300
- const scene = scenes[index];
301
- // It is possible that for a short period the route appears in both arrays.
302
- // Particularly, if the screen is removed with `retain`, then it needs a moment to execute the animation.
303
- // However, due to the router action, it immediately populates the `preloadedRoutes` array.
304
- // Practically, the logic below takes care that it is rendered only once.
305
- const isPreloaded = state.preloadedRoutes.includes(route) && !routes.includes(route);
306
- if (state.preloadedRoutes.includes(route) && routes.includes(route) && index >= routes.length) {
307
- return null;
308
- }
309
-
310
- // For the screens that shouldn't be active, the value is 0
311
- // For those that should be active, but are not the top screen, the value is 1
312
- // For those on top of the stack and with interaction enabled, the value is 2
313
- // For the old implementation, it stays the same it was
314
- let isScreenActive = 1;
315
- if (index < routes.length - activeScreensLimit - 1 || isPreloaded) {
316
- // screen should be inactive because it is too deep in the stack
317
- isScreenActive = STATE_INACTIVE;
318
- } else {
319
- const sceneForActivity = scenes[routes.length - 1];
320
- const outputValue = index === routes.length - 1 ? STATE_ON_TOP // the screen is on top after the transition
321
- : index >= routes.length - activeScreensLimit ? STATE_TRANSITIONING_OR_BELOW_TOP // the screen should stay active after the transition, it is not on top but is in activeLimit
322
- : STATE_INACTIVE; // the screen should be active only during the transition, it is at the edge of activeLimit
323
- isScreenActive = sceneForActivity ? sceneForActivity.progress.current.interpolate({
324
- inputRange: [0, 1 - EPSILON, 1],
325
- outputRange: [1, 1, outputValue],
326
- extrapolate: 'clamp'
327
- }) : STATE_TRANSITIONING_OR_BELOW_TOP;
328
- }
329
- const {
330
- headerShown = true,
331
- headerTransparent,
332
- freezeOnBlur,
333
- autoHideHomeIndicator
334
- } = scene.descriptor.options;
335
- const safeAreaInsetTop = insets.top;
336
- const safeAreaInsetRight = insets.right;
337
- const safeAreaInsetBottom = insets.bottom;
338
- const safeAreaInsetLeft = insets.left;
339
- const headerHeight = headerShown !== false ? headerHeights[route.key] : 0;
340
-
341
- // Start from current card and count backwards the number of cards with same interpolation
342
- const interpolationIndex = getInterpolationIndex(scenes, index);
343
- const isModal = getIsModal(scene, interpolationIndex, isParentModal);
344
- const isNextScreenTransparent = scenes[index + 1]?.descriptor.options.presentation === 'transparentModal';
345
- const detachCurrentScreen = scenes[index + 1]?.descriptor.options.detachPreviousScreen !== false;
346
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Screens.MaybeScreen, {
347
- style: [_reactNative.StyleSheet.absoluteFill],
348
- enabled: detachInactiveScreens,
349
- active: isScreenActive,
350
- freezeOnBlur: freezeOnBlur,
351
- homeIndicatorHidden: autoHideHomeIndicator,
352
- pointerEvents: "box-none",
353
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CardContainer.CardContainer, {
354
- index: index,
355
- interpolationIndex: interpolationIndex,
356
- modal: isModal,
357
- active: index === routes.length - 1,
358
- focused: focused,
359
- opening: openingRouteKeys.includes(route.key),
360
- closing: closingRouteKeys.includes(route.key),
361
- layout: layout,
362
- gesture: gesture,
363
- scene: scene,
364
- safeAreaInsetTop: safeAreaInsetTop,
365
- safeAreaInsetRight: safeAreaInsetRight,
366
- safeAreaInsetBottom: safeAreaInsetBottom,
367
- safeAreaInsetLeft: safeAreaInsetLeft,
368
- onGestureStart: onGestureStart,
369
- onGestureCancel: onGestureCancel,
370
- onGestureEnd: onGestureEnd,
371
- headerHeight: headerHeight,
372
- isParentHeaderShown: isParentHeaderShown,
373
- onHeaderHeightChange: this.handleHeaderLayout,
374
- getPreviousScene: this.getPreviousScene,
375
- getFocusedRoute: this.getFocusedRoute,
376
- hasAbsoluteFloatHeader: isFloatHeaderAbsolute && !headerTransparent,
377
- renderHeader: renderHeader,
378
- onOpenRoute: onOpenRoute,
379
- onCloseRoute: onCloseRoute,
380
- onTransitionStart: onTransitionStart,
381
- onTransitionEnd: onTransitionEnd,
382
- isNextScreenTransparent: isNextScreenTransparent,
383
- detachCurrentScreen: detachCurrentScreen,
384
- preloaded: isPreloaded
385
- })
386
- }, route.key);
387
- })
388
- }), isFloatHeaderAbsolute ? floatingHeader : null]
389
- });
390
351
  }
391
- }], [{
392
- key: "getDerivedStateFromProps",
393
- value: function getDerivedStateFromProps(props, state) {
394
- if (props.routes === state.routes && props.descriptors === state.descriptors) {
395
- return null;
396
- }
397
- const gestures = [...props.routes, ...props.state.preloadedRoutes].reduce((acc, curr) => {
398
- const descriptor = props.descriptors[curr.key] || props.preloadedDescriptors[curr.key];
399
- const {
400
- animation
401
- } = descriptor?.options || {};
402
- acc[curr.key] = state.gestures[curr.key] || new _reactNative.Animated.Value(props.openingRouteKeys.includes(curr.key) && animation !== 'none' || props.state.preloadedRoutes.includes(curr) ? getDistanceFromOptions(state.layout, descriptor, props.direction === 'rtl') : 0);
403
- return acc;
404
- }, {});
405
- const modalRouteKeys = (0, _getModalRoutesKeys.getModalRouteKeys)([...props.routes, ...props.state.preloadedRoutes], {
406
- ...props.descriptors,
407
- ...props.preloadedDescriptors
408
- });
409
- const scenes = [...props.routes, ...props.state.preloadedRoutes].map((route, index, self) => {
410
- // For preloaded screens, we don't care about the previous and the next screen
411
- const isPreloaded = props.state.preloadedRoutes.includes(route);
412
- const previousRoute = isPreloaded ? undefined : self[index - 1];
413
- const nextRoute = isPreloaded ? undefined : self[index + 1];
414
- const oldScene = state.scenes[index];
415
- const currentGesture = gestures[route.key];
416
- const previousGesture = previousRoute ? gestures[previousRoute.key] : undefined;
417
- const nextGesture = nextRoute ? gestures[nextRoute.key] : undefined;
418
- const descriptor = (isPreloaded ? props.preloadedDescriptors : props.descriptors)[route.key] || state.descriptors[route.key] || (oldScene ? oldScene.descriptor : FALLBACK_DESCRIPTOR);
419
- const nextDescriptor = nextRoute && (props.descriptors[nextRoute?.key] || state.descriptors[nextRoute?.key]);
420
- const previousDescriptor = previousRoute && (props.descriptors[previousRoute?.key] || state.descriptors[previousRoute?.key]);
421
-
422
- // When a screen is not the last, it should use next screen's transition config
423
- // Many transitions also animate the previous screen, so using 2 different transitions doesn't look right
424
- // For example combining a slide and a modal transition would look wrong otherwise
425
- // With this approach, combining different transition styles in the same navigator mostly looks right
426
- // This will still be broken when 2 transitions have different idle state (e.g. modal presentation),
427
- // but the majority of the transitions look alright
428
- const optionsForTransitionConfig = index !== self.length - 1 && nextDescriptor && nextDescriptor.options.presentation !== 'transparentModal' ? nextDescriptor.options : descriptor.options;
352
+ const floatingHeader = /*#__PURE__*/(0, _jsxRuntime.jsx)(React.Fragment, {
353
+ children: renderHeader({
354
+ mode: 'float',
355
+ layout,
356
+ scenes,
357
+ getPreviousScene: this.getPreviousScene,
358
+ getFocusedRoute: this.getFocusedRoute,
359
+ onContentHeightChange: this.handleHeaderLayout,
360
+ style: [styles.floating, isFloatHeaderAbsolute && [
361
+ // Without this, the header buttons won't be touchable on Android when headerTransparent: true
362
+ {
363
+ height: focusedHeaderHeight
364
+ }, styles.absolute]]
365
+ })
366
+ }, "header");
367
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
368
+ style: styles.container,
369
+ children: [isFloatHeaderAbsolute ? null : floatingHeader, /*#__PURE__*/(0, _jsxRuntime.jsx)(_Screens.MaybeScreenContainer, {
370
+ enabled: detachInactiveScreens,
371
+ style: styles.container,
372
+ onLayout: this.handleLayout,
373
+ children: [...routes, ...state.preloadedRoutes].map((route, index) => {
374
+ const focused = focusedRoute.key === route.key;
375
+ const gesture = gestures[route.key];
376
+ const scene = scenes[index];
377
+ // It is possible that for a short period the route appears in both arrays.
378
+ // Particularly, if the screen is removed with `retain`, then it needs a moment to execute the animation.
379
+ // However, due to the router action, it immediately populates the `preloadedRoutes` array.
380
+ // Practically, the logic below takes care that it is rendered only once.
381
+ const isPreloaded = state.preloadedRoutes.includes(route) && !routes.includes(route);
382
+ if (state.preloadedRoutes.includes(route) && routes.includes(route) && index >= routes.length) {
383
+ return null;
384
+ }
429
385
 
430
- // Assume modal if there are already modal screens in the stack
431
- // or current screen is a modal when no presentation is specified
432
- const isModal = modalRouteKeys.includes(route.key);
386
+ // For the screens that shouldn't be active, the value is 0
387
+ // For those that should be active, but are not the top screen, the value is 1
388
+ // For those on top of the stack and with interaction enabled, the value is 2
389
+ // For the old implementation, it stays the same it was
390
+ let isScreenActive = 1;
391
+ if (index < routes.length - activeScreensLimit - 1 || isPreloaded) {
392
+ // screen should be inactive because it is too deep in the stack
393
+ isScreenActive = STATE_INACTIVE;
394
+ } else {
395
+ const sceneForActivity = scenes[routes.length - 1];
396
+ const outputValue = index === routes.length - 1 ? STATE_ON_TOP // the screen is on top after the transition
397
+ : index >= routes.length - activeScreensLimit ? STATE_TRANSITIONING_OR_BELOW_TOP // the screen should stay active after the transition, it is not on top but is in activeLimit
398
+ : STATE_INACTIVE; // the screen should be active only during the transition, it is at the edge of activeLimit
399
+ isScreenActive = sceneForActivity ? sceneForActivity.progress.current.interpolate({
400
+ inputRange: [0, 1 - EPSILON, 1],
401
+ outputRange: [1, 1, outputValue],
402
+ extrapolate: 'clamp'
403
+ }) : STATE_TRANSITIONING_OR_BELOW_TOP;
404
+ }
405
+ const {
406
+ headerShown = true,
407
+ headerTransparent,
408
+ freezeOnBlur,
409
+ autoHideHomeIndicator
410
+ } = scene.descriptor.options;
411
+ const safeAreaInsetTop = insets.top;
412
+ const safeAreaInsetRight = insets.right;
413
+ const safeAreaInsetBottom = insets.bottom;
414
+ const safeAreaInsetLeft = insets.left;
415
+ const headerHeight = headerShown !== false ? headerHeights[route.key] : 0;
433
416
 
434
- // Disable screen transition animation by default on web, windows and macos to match the native behavior
435
- const excludedPlatforms = _reactNative.Platform.OS !== 'web' && _reactNative.Platform.OS !== 'windows' && _reactNative.Platform.OS !== 'macos';
436
- const animation = optionsForTransitionConfig.animation ?? (excludedPlatforms ? 'default' : 'none');
437
- const isAnimationEnabled = animation !== 'none';
438
- const transitionPreset = animation !== 'default' ? NAMED_TRANSITIONS_PRESETS[animation] : isModal || optionsForTransitionConfig.presentation === 'modal' ? _TransitionPresets.ModalTransition : optionsForTransitionConfig.presentation === 'transparentModal' ? _TransitionPresets.ModalFadeTransition : _TransitionPresets.DefaultTransition;
439
- const {
440
- gestureEnabled = _reactNative.Platform.OS === 'ios' && isAnimationEnabled,
441
- gestureDirection = transitionPreset.gestureDirection,
442
- transitionSpec = transitionPreset.transitionSpec,
443
- cardStyleInterpolator = isAnimationEnabled ? transitionPreset.cardStyleInterpolator : _CardStyleInterpolators.forNoAnimation,
444
- headerStyleInterpolator = transitionPreset.headerStyleInterpolator,
445
- cardOverlayEnabled = _reactNative.Platform.OS !== 'ios' && optionsForTransitionConfig.presentation !== 'transparentModal' || getIsModalPresentation(cardStyleInterpolator)
446
- } = optionsForTransitionConfig;
447
- const headerMode = descriptor.options.headerMode ?? (!(optionsForTransitionConfig.presentation === 'modal' || optionsForTransitionConfig.presentation === 'transparentModal' || nextDescriptor?.options.presentation === 'modal' || nextDescriptor?.options.presentation === 'transparentModal' || getIsModalPresentation(cardStyleInterpolator)) && _reactNative.Platform.OS === 'ios' && descriptor.options.header === undefined ? 'float' : 'screen');
448
- const isRTL = props.direction === 'rtl';
449
- const scene = {
450
- route,
451
- descriptor: {
452
- ...descriptor,
453
- options: {
454
- ...descriptor.options,
455
- animation,
456
- cardOverlayEnabled,
457
- cardStyleInterpolator,
458
- gestureDirection,
459
- gestureEnabled,
460
- headerStyleInterpolator,
461
- transitionSpec,
462
- headerMode
463
- }
464
- },
465
- progress: {
466
- current: getProgressFromGesture(currentGesture, state.layout, descriptor, isRTL),
467
- next: nextGesture && nextDescriptor?.options.presentation !== 'transparentModal' ? getProgressFromGesture(nextGesture, state.layout, nextDescriptor, isRTL) : undefined,
468
- previous: previousGesture ? getProgressFromGesture(previousGesture, state.layout, previousDescriptor, isRTL) : undefined
469
- },
470
- __memo: [state.layout, descriptor, nextDescriptor, previousDescriptor, currentGesture, nextGesture, previousGesture]
471
- };
472
- if (oldScene && scene.__memo.every((it, i) => {
473
- // @ts-expect-error: we haven't added __memo to the annotation to prevent usage elsewhere
474
- return oldScene.__memo[i] === it;
475
- })) {
476
- return oldScene;
477
- }
478
- return scene;
479
- });
480
- return {
481
- routes: props.routes,
482
- scenes,
483
- gestures,
484
- descriptors: props.descriptors,
485
- headerHeights: getHeaderHeights(scenes, props.insets, props.isParentHeaderShown, props.isParentModal, state.layout, state.headerHeights)
486
- };
487
- }
488
- }]);
489
- }(React.Component);
417
+ // Start from current card and count backwards the number of cards with same interpolation
418
+ const interpolationIndex = getInterpolationIndex(scenes, index);
419
+ const isModal = getIsModal(scene, interpolationIndex, isParentModal);
420
+ const isNextScreenTransparent = scenes[index + 1]?.descriptor.options.presentation === 'transparentModal';
421
+ const detachCurrentScreen = scenes[index + 1]?.descriptor.options.detachPreviousScreen !== false;
422
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Screens.MaybeScreen, {
423
+ style: [_reactNative.StyleSheet.absoluteFill],
424
+ enabled: detachInactiveScreens,
425
+ active: isScreenActive,
426
+ freezeOnBlur: freezeOnBlur,
427
+ homeIndicatorHidden: autoHideHomeIndicator,
428
+ pointerEvents: "box-none",
429
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CardContainer.CardContainer, {
430
+ index: index,
431
+ interpolationIndex: interpolationIndex,
432
+ modal: isModal,
433
+ active: index === routes.length - 1,
434
+ focused: focused,
435
+ opening: openingRouteKeys.includes(route.key),
436
+ closing: closingRouteKeys.includes(route.key),
437
+ layout: layout,
438
+ gesture: gesture,
439
+ scene: scene,
440
+ safeAreaInsetTop: safeAreaInsetTop,
441
+ safeAreaInsetRight: safeAreaInsetRight,
442
+ safeAreaInsetBottom: safeAreaInsetBottom,
443
+ safeAreaInsetLeft: safeAreaInsetLeft,
444
+ onGestureStart: onGestureStart,
445
+ onGestureCancel: onGestureCancel,
446
+ onGestureEnd: onGestureEnd,
447
+ headerHeight: headerHeight,
448
+ isParentHeaderShown: isParentHeaderShown,
449
+ onHeaderHeightChange: this.handleHeaderLayout,
450
+ getPreviousScene: this.getPreviousScene,
451
+ getFocusedRoute: this.getFocusedRoute,
452
+ hasAbsoluteFloatHeader: isFloatHeaderAbsolute && !headerTransparent,
453
+ renderHeader: renderHeader,
454
+ onOpenRoute: onOpenRoute,
455
+ onCloseRoute: onCloseRoute,
456
+ onTransitionStart: onTransitionStart,
457
+ onTransitionEnd: onTransitionEnd,
458
+ isNextScreenTransparent: isNextScreenTransparent,
459
+ detachCurrentScreen: detachCurrentScreen,
460
+ preloaded: isPreloaded
461
+ })
462
+ }, route.key);
463
+ })
464
+ }), isFloatHeaderAbsolute ? floatingHeader : null]
465
+ });
466
+ }
467
+ }
468
+ exports.CardStack = CardStack;
490
469
  const styles = _reactNative.StyleSheet.create({
491
470
  container: {
492
471
  flex: 1