@react-navigation/stack 7.0.0-alpha.2 → 7.0.0-alpha.20

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 (176) hide show
  1. package/lib/commonjs/TransitionConfigs/CardStyleInterpolators.js +29 -14
  2. package/lib/commonjs/TransitionConfigs/CardStyleInterpolators.js.map +1 -1
  3. package/lib/commonjs/TransitionConfigs/HeaderStyleInterpolators.js +19 -12
  4. package/lib/commonjs/TransitionConfigs/HeaderStyleInterpolators.js.map +1 -1
  5. package/lib/commonjs/TransitionConfigs/TransitionPresets.js +20 -22
  6. package/lib/commonjs/TransitionConfigs/TransitionPresets.js.map +1 -1
  7. package/lib/commonjs/TransitionConfigs/TransitionSpecs.js +7 -14
  8. package/lib/commonjs/TransitionConfigs/TransitionSpecs.js.map +1 -1
  9. package/lib/commonjs/index.js +2 -2
  10. package/lib/commonjs/index.js.map +1 -1
  11. package/lib/commonjs/navigators/createStackNavigator.js +35 -25
  12. package/lib/commonjs/navigators/createStackNavigator.js.map +1 -1
  13. package/lib/commonjs/types.js.map +1 -1
  14. package/lib/commonjs/utils/CardAnimationContext.js +3 -4
  15. package/lib/commonjs/utils/CardAnimationContext.js.map +1 -1
  16. package/lib/commonjs/utils/GestureHandlerRefContext.js +3 -4
  17. package/lib/commonjs/utils/GestureHandlerRefContext.js.map +1 -1
  18. package/lib/commonjs/utils/ModalPresentationContext.js +3 -4
  19. package/lib/commonjs/utils/ModalPresentationContext.js.map +1 -1
  20. package/lib/commonjs/utils/conditional.js.map +1 -1
  21. package/lib/commonjs/utils/debounce.js.map +1 -1
  22. package/lib/commonjs/utils/findLastIndex.js +1 -1
  23. package/lib/commonjs/utils/findLastIndex.js.map +1 -1
  24. package/lib/commonjs/utils/getDistanceForDirection.js +2 -2
  25. package/lib/commonjs/utils/getDistanceForDirection.js.map +1 -1
  26. package/lib/commonjs/utils/getInvertedMultiplier.js +3 -4
  27. package/lib/commonjs/utils/getInvertedMultiplier.js.map +1 -1
  28. package/lib/commonjs/utils/getModalRoutesKeys.js +17 -0
  29. package/lib/commonjs/utils/getModalRoutesKeys.js.map +1 -0
  30. package/lib/commonjs/utils/memoize.js.map +1 -1
  31. package/lib/commonjs/utils/useCardAnimation.js +2 -2
  32. package/lib/commonjs/utils/useCardAnimation.js.map +1 -1
  33. package/lib/commonjs/utils/useGestureHandlerRef.js +2 -2
  34. package/lib/commonjs/utils/useGestureHandlerRef.js.map +1 -1
  35. package/lib/commonjs/utils/useKeyboardManager.js +6 -6
  36. package/lib/commonjs/utils/useKeyboardManager.js.map +1 -1
  37. package/lib/commonjs/views/GestureHandler.android.js.map +1 -1
  38. package/lib/commonjs/views/GestureHandler.ios.js.map +1 -1
  39. package/lib/commonjs/views/GestureHandler.js +5 -8
  40. package/lib/commonjs/views/GestureHandler.js.map +1 -1
  41. package/lib/commonjs/views/GestureHandlerNative.js +2 -2
  42. package/lib/commonjs/views/GestureHandlerNative.js.map +1 -1
  43. package/lib/commonjs/views/Header/Header.js +4 -4
  44. package/lib/commonjs/views/Header/Header.js.map +1 -1
  45. package/lib/commonjs/views/Header/HeaderContainer.js +14 -11
  46. package/lib/commonjs/views/Header/HeaderContainer.js.map +1 -1
  47. package/lib/commonjs/views/Header/HeaderSegment.js +9 -2
  48. package/lib/commonjs/views/Header/HeaderSegment.js.map +1 -1
  49. package/lib/commonjs/views/Screens.js +2 -2
  50. package/lib/commonjs/views/Screens.js.map +1 -1
  51. package/lib/commonjs/views/Stack/Card.js +55 -48
  52. package/lib/commonjs/views/Stack/Card.js.map +1 -1
  53. package/lib/commonjs/views/Stack/CardContainer.js +27 -23
  54. package/lib/commonjs/views/Stack/CardContainer.js.map +1 -1
  55. package/lib/commonjs/views/Stack/CardSheet.js +24 -4
  56. package/lib/commonjs/views/Stack/CardSheet.js.map +1 -1
  57. package/lib/commonjs/views/Stack/CardStack.js +99 -73
  58. package/lib/commonjs/views/Stack/CardStack.js.map +1 -1
  59. package/lib/commonjs/views/Stack/StackView.js +27 -31
  60. package/lib/commonjs/views/Stack/StackView.js.map +1 -1
  61. package/lib/module/TransitionConfigs/CardStyleInterpolators.js +28 -14
  62. package/lib/module/TransitionConfigs/CardStyleInterpolators.js.map +1 -1
  63. package/lib/module/TransitionConfigs/HeaderStyleInterpolators.js +20 -13
  64. package/lib/module/TransitionConfigs/HeaderStyleInterpolators.js.map +1 -1
  65. package/lib/module/TransitionConfigs/TransitionPresets.js +10 -2
  66. package/lib/module/TransitionConfigs/TransitionPresets.js.map +1 -1
  67. package/lib/module/TransitionConfigs/TransitionSpecs.js.map +1 -1
  68. package/lib/module/index.js.map +1 -1
  69. package/lib/module/navigators/createStackNavigator.js +33 -22
  70. package/lib/module/navigators/createStackNavigator.js.map +1 -1
  71. package/lib/module/types.js.map +1 -1
  72. package/lib/module/utils/CardAnimationContext.js.map +1 -1
  73. package/lib/module/utils/GestureHandlerRefContext.js.map +1 -1
  74. package/lib/module/utils/ModalPresentationContext.js.map +1 -1
  75. package/lib/module/utils/conditional.js.map +1 -1
  76. package/lib/module/utils/debounce.js.map +1 -1
  77. package/lib/module/utils/findLastIndex.js +1 -1
  78. package/lib/module/utils/findLastIndex.js.map +1 -1
  79. package/lib/module/utils/getDistanceForDirection.js +2 -2
  80. package/lib/module/utils/getDistanceForDirection.js.map +1 -1
  81. package/lib/module/utils/getInvertedMultiplier.js +3 -4
  82. package/lib/module/utils/getInvertedMultiplier.js.map +1 -1
  83. package/lib/module/utils/getModalRoutesKeys.js +10 -0
  84. package/lib/module/utils/getModalRoutesKeys.js.map +1 -0
  85. package/lib/module/utils/memoize.js.map +1 -1
  86. package/lib/module/utils/useCardAnimation.js.map +1 -1
  87. package/lib/module/utils/useGestureHandlerRef.js.map +1 -1
  88. package/lib/module/utils/useKeyboardManager.js +4 -4
  89. package/lib/module/utils/useKeyboardManager.js.map +1 -1
  90. package/lib/module/views/GestureHandler.android.js.map +1 -1
  91. package/lib/module/views/GestureHandler.ios.js.map +1 -1
  92. package/lib/module/views/GestureHandler.js.map +1 -1
  93. package/lib/module/views/GestureHandlerNative.js.map +1 -1
  94. package/lib/module/views/Header/Header.js +1 -0
  95. package/lib/module/views/Header/Header.js.map +1 -1
  96. package/lib/module/views/Header/HeaderContainer.js +13 -10
  97. package/lib/module/views/Header/HeaderContainer.js.map +1 -1
  98. package/lib/module/views/Header/HeaderSegment.js +7 -0
  99. package/lib/module/views/Header/HeaderSegment.js.map +1 -1
  100. package/lib/module/views/Screens.js.map +1 -1
  101. package/lib/module/views/Stack/Card.js +52 -44
  102. package/lib/module/views/Stack/Card.js.map +1 -1
  103. package/lib/module/views/Stack/CardContainer.js +25 -20
  104. package/lib/module/views/Stack/CardContainer.js.map +1 -1
  105. package/lib/module/views/Stack/CardSheet.js +21 -0
  106. package/lib/module/views/Stack/CardSheet.js.map +1 -1
  107. package/lib/module/views/Stack/CardStack.js +95 -68
  108. package/lib/module/views/Stack/CardStack.js.map +1 -1
  109. package/lib/module/views/Stack/StackView.js +25 -29
  110. package/lib/module/views/Stack/StackView.js.map +1 -1
  111. package/lib/typescript/src/TransitionConfigs/CardStyleInterpolators.d.ts +4 -0
  112. package/lib/typescript/src/TransitionConfigs/CardStyleInterpolators.d.ts.map +1 -1
  113. package/lib/typescript/src/TransitionConfigs/HeaderStyleInterpolators.d.ts +3 -3
  114. package/lib/typescript/src/TransitionConfigs/HeaderStyleInterpolators.d.ts.map +1 -1
  115. package/lib/typescript/src/TransitionConfigs/TransitionPresets.d.ts +4 -0
  116. package/lib/typescript/src/TransitionConfigs/TransitionPresets.d.ts.map +1 -1
  117. package/lib/typescript/src/index.d.ts +1 -1
  118. package/lib/typescript/src/index.d.ts.map +1 -1
  119. package/lib/typescript/src/navigators/createStackNavigator.d.ts +15 -9
  120. package/lib/typescript/src/navigators/createStackNavigator.d.ts.map +1 -1
  121. package/lib/typescript/src/types.d.ts +70 -15
  122. package/lib/typescript/src/types.d.ts.map +1 -1
  123. package/lib/typescript/src/utils/getDistanceForDirection.d.ts +1 -1
  124. package/lib/typescript/src/utils/getDistanceForDirection.d.ts.map +1 -1
  125. package/lib/typescript/src/utils/getInvertedMultiplier.d.ts +1 -1
  126. package/lib/typescript/src/utils/getInvertedMultiplier.d.ts.map +1 -1
  127. package/lib/typescript/src/utils/getModalRoutesKeys.d.ts +4 -0
  128. package/lib/typescript/src/utils/getModalRoutesKeys.d.ts.map +1 -0
  129. package/lib/typescript/src/views/GestureHandlerNative.d.ts +3 -2
  130. package/lib/typescript/src/views/GestureHandlerNative.d.ts.map +1 -1
  131. package/lib/typescript/src/views/Header/Header.d.ts.map +1 -1
  132. package/lib/typescript/src/views/Header/HeaderContainer.d.ts +4 -3
  133. package/lib/typescript/src/views/Header/HeaderContainer.d.ts.map +1 -1
  134. package/lib/typescript/src/views/Header/HeaderSegment.d.ts +3 -1
  135. package/lib/typescript/src/views/Header/HeaderSegment.d.ts.map +1 -1
  136. package/lib/typescript/src/views/Screens.d.ts +4 -3
  137. package/lib/typescript/src/views/Screens.d.ts.map +1 -1
  138. package/lib/typescript/src/views/Stack/Card.d.ts +6 -5
  139. package/lib/typescript/src/views/Stack/Card.d.ts.map +1 -1
  140. package/lib/typescript/src/views/Stack/CardContainer.d.ts +3 -6
  141. package/lib/typescript/src/views/Stack/CardContainer.d.ts.map +1 -1
  142. package/lib/typescript/src/views/Stack/CardSheet.d.ts +1 -1
  143. package/lib/typescript/src/views/Stack/CardSheet.d.ts.map +1 -1
  144. package/lib/typescript/src/views/Stack/CardStack.d.ts +4 -5
  145. package/lib/typescript/src/views/Stack/CardStack.d.ts.map +1 -1
  146. package/lib/typescript/src/views/Stack/StackView.d.ts +9 -80
  147. package/lib/typescript/src/views/Stack/StackView.d.ts.map +1 -1
  148. package/package.json +19 -20
  149. package/src/TransitionConfigs/CardStyleInterpolators.tsx +18 -5
  150. package/src/TransitionConfigs/HeaderStyleInterpolators.tsx +32 -22
  151. package/src/TransitionConfigs/TransitionPresets.tsx +13 -4
  152. package/src/index.tsx +2 -0
  153. package/src/navigators/createStackNavigator.tsx +49 -14
  154. package/src/types.tsx +88 -15
  155. package/src/utils/findLastIndex.tsx +1 -1
  156. package/src/utils/getDistanceForDirection.tsx +3 -2
  157. package/src/utils/getInvertedMultiplier.tsx +4 -5
  158. package/src/utils/getModalRoutesKeys.ts +21 -0
  159. package/src/utils/useKeyboardManager.tsx +1 -1
  160. package/src/views/GestureHandlerNative.tsx +1 -1
  161. package/src/views/Header/Header.tsx +3 -2
  162. package/src/views/Header/HeaderContainer.tsx +19 -8
  163. package/src/views/Header/HeaderSegment.tsx +10 -3
  164. package/src/views/Screens.tsx +2 -1
  165. package/src/views/Stack/Card.tsx +82 -63
  166. package/src/views/Stack/CardContainer.tsx +20 -11
  167. package/src/views/Stack/CardSheet.tsx +25 -1
  168. package/src/views/Stack/CardStack.tsx +278 -193
  169. package/src/views/Stack/StackView.tsx +25 -28
  170. package/lib/commonjs/views/ModalStatusBarManager.js +0 -44
  171. package/lib/commonjs/views/ModalStatusBarManager.js.map +0 -1
  172. package/lib/module/views/ModalStatusBarManager.js +0 -36
  173. package/lib/module/views/ModalStatusBarManager.js.map +0 -1
  174. package/lib/typescript/src/views/ModalStatusBarManager.d.ts +0 -11
  175. package/lib/typescript/src/views/ModalStatusBarManager.d.ts.map +0 -1
  176. package/src/views/ModalStatusBarManager.tsx +0 -45
@@ -1,18 +1,18 @@
1
+ import type { LocaleDirection } from '@react-navigation/native';
1
2
  import Color from 'color';
2
3
  import * as React from 'react';
3
4
  import {
4
5
  Animated,
5
6
  InteractionManager,
6
7
  Platform,
7
- StyleProp,
8
+ type StyleProp,
8
9
  StyleSheet,
9
10
  View,
10
- ViewProps,
11
- ViewStyle,
11
+ type ViewProps,
12
+ type ViewStyle,
12
13
  } from 'react-native';
13
14
  import type { EdgeInsets } from 'react-native-safe-area-context';
14
15
 
15
- import { forModalPresentationIOS } from '../../TransitionConfigs/CardStyleInterpolators';
16
16
  import type {
17
17
  GestureDirection,
18
18
  Layout,
@@ -27,10 +27,9 @@ import { memoize } from '../../utils/memoize';
27
27
  import {
28
28
  GestureState,
29
29
  PanGestureHandler,
30
- PanGestureHandlerGestureEvent,
30
+ type PanGestureHandlerGestureEvent,
31
31
  } from '../GestureHandler';
32
- import { ModalStatusBarManager } from '../ModalStatusBarManager';
33
- import { CardSheet, CardSheetRef } from './CardSheet';
32
+ import { CardSheet, type CardSheetRef } from './CardSheet';
34
33
 
35
34
  type Props = ViewProps & {
36
35
  interpolationIndex: number;
@@ -40,7 +39,7 @@ type Props = ViewProps & {
40
39
  gesture: Animated.Value;
41
40
  layout: Layout;
42
41
  insets: EdgeInsets;
43
- headerDarkContent: boolean | undefined;
42
+ direction: LocaleDirection;
44
43
  pageOverflowEnabled: boolean;
45
44
  gestureDirection: GestureDirection;
46
45
  onOpen: () => void;
@@ -62,6 +61,7 @@ type Props = ViewProps & {
62
61
  open: TransitionSpec;
63
62
  close: TransitionSpec;
64
63
  };
64
+ preloaded: boolean;
65
65
  styleInterpolator: StackCardStyleInterpolator;
66
66
  containerStyle?: StyleProp<ViewStyle>;
67
67
  contentStyle?: StyleProp<ViewStyle>;
@@ -105,12 +105,16 @@ export class Card extends React.Component<Props> {
105
105
  };
106
106
 
107
107
  componentDidMount() {
108
- this.animate({ closing: this.props.closing });
108
+ if (!this.props.preloaded) {
109
+ this.animate({
110
+ closing: this.props.closing,
111
+ });
112
+ }
109
113
  this.isCurrentlyMounted = true;
110
114
  }
111
115
 
112
116
  componentDidUpdate(prevProps: Props) {
113
- const { layout, gestureDirection, closing } = this.props;
117
+ const { direction, layout, gestureDirection, closing } = this.props;
114
118
  const { width, height } = layout;
115
119
 
116
120
  if (width !== prevProps.layout.width) {
@@ -122,7 +126,9 @@ export class Card extends React.Component<Props> {
122
126
  }
123
127
 
124
128
  if (gestureDirection !== prevProps.gestureDirection) {
125
- this.inverted.setValue(getInvertedMultiplier(gestureDirection));
129
+ this.inverted.setValue(
130
+ getInvertedMultiplier(gestureDirection, direction === 'rtl')
131
+ );
126
132
  }
127
133
 
128
134
  const toValue = this.getAnimateToValue(this.props);
@@ -132,7 +138,7 @@ export class Card extends React.Component<Props> {
132
138
  this.lastToValue !== toValue
133
139
  ) {
134
140
  // We need to trigger the animation when route was closed
135
- // Thr route might have been closed by a `POP` action or by a gesture
141
+ // The route might have been closed by a `POP` action or by a gesture
136
142
  // When route was closed due to a gesture, the animation would've happened already
137
143
  // It's still important to trigger the animation so that `onClose` is called
138
144
  // If `onClose` is not called, cleanup step won't be performed for gestures
@@ -141,7 +147,7 @@ export class Card extends React.Component<Props> {
141
147
  }
142
148
 
143
149
  componentWillUnmount() {
144
- this.props.gesture.stopAnimation();
150
+ this.props.gesture?.stopAnimation();
145
151
  this.isCurrentlyMounted = false;
146
152
  this.handleEndInteraction();
147
153
  }
@@ -151,7 +157,10 @@ export class Card extends React.Component<Props> {
151
157
  private isClosing = new Animated.Value(FALSE);
152
158
 
153
159
  private inverted = new Animated.Value(
154
- getInvertedMultiplier(this.props.gestureDirection)
160
+ getInvertedMultiplier(
161
+ this.props.gestureDirection,
162
+ this.props.direction === 'rtl'
163
+ )
155
164
  );
156
165
 
157
166
  private layout = {
@@ -174,7 +183,7 @@ export class Card extends React.Component<Props> {
174
183
  closing: boolean;
175
184
  velocity?: number;
176
185
  }) => {
177
- const { gesture, transitionSpec, onOpen, onClose, onTransition } =
186
+ const { transitionSpec, onOpen, onClose, onTransition, gesture } =
178
187
  this.props;
179
188
 
180
189
  const toValue = this.getAnimateToValue({
@@ -227,16 +236,24 @@ export class Card extends React.Component<Props> {
227
236
  closing,
228
237
  layout,
229
238
  gestureDirection,
239
+ direction,
240
+ preloaded,
230
241
  }: {
231
242
  closing?: boolean;
232
243
  layout: Layout;
233
244
  gestureDirection: GestureDirection;
245
+ direction: LocaleDirection;
246
+ preloaded: boolean;
234
247
  }) => {
235
- if (!closing) {
248
+ if (!closing && !preloaded) {
236
249
  return 0;
237
250
  }
238
251
 
239
- return getDistanceForDirection(layout, gestureDirection);
252
+ return getDistanceForDirection(
253
+ layout,
254
+ gestureDirection,
255
+ direction === 'rtl'
256
+ );
240
257
  };
241
258
 
242
259
  private setPointerEventsEnabled = (enabled: boolean) => {
@@ -262,6 +279,7 @@ export class Card extends React.Component<Props> {
262
279
  nativeEvent,
263
280
  }: PanGestureHandlerGestureEvent) => {
264
281
  const {
282
+ direction,
265
283
  layout,
266
284
  onClose,
267
285
  onGestureBegin,
@@ -277,7 +295,8 @@ export class Card extends React.Component<Props> {
277
295
  this.handleStartInteraction();
278
296
  onGestureBegin?.();
279
297
  break;
280
- case GestureState.CANCELLED: {
298
+ case GestureState.CANCELLED:
299
+ case GestureState.FAILED: {
281
300
  this.isSwiping.setValue(FALSE);
282
301
  this.handleEndInteraction();
283
302
 
@@ -287,7 +306,10 @@ export class Card extends React.Component<Props> {
287
306
  ? nativeEvent.velocityY
288
307
  : nativeEvent.velocityX;
289
308
 
290
- this.animate({ closing: this.props.closing, velocity });
309
+ this.animate({
310
+ closing: this.props.closing,
311
+ velocity,
312
+ });
291
313
 
292
314
  onGestureCanceled?.();
293
315
  break;
@@ -314,7 +336,7 @@ export class Card extends React.Component<Props> {
314
336
 
315
337
  const closing =
316
338
  (translation + velocity * gestureVelocityImpact) *
317
- getInvertedMultiplier(gestureDirection) >
339
+ getInvertedMultiplier(gestureDirection, direction === 'rtl') >
318
340
  distance / 2
319
341
  ? velocity !== 0 || translation !== 0
320
342
  : this.props.closing;
@@ -378,16 +400,17 @@ export class Card extends React.Component<Props> {
378
400
  );
379
401
 
380
402
  private gestureActivationCriteria() {
381
- const { layout, gestureDirection, gestureResponseDistance } = this.props;
403
+ const { direction, layout, gestureDirection, gestureResponseDistance } =
404
+ this.props;
382
405
  const enableTrackpadTwoFingerGesture = true;
383
406
 
384
407
  const distance =
385
408
  gestureResponseDistance !== undefined
386
409
  ? gestureResponseDistance
387
410
  : gestureDirection === 'vertical' ||
388
- gestureDirection === 'vertical-inverted'
389
- ? GESTURE_RESPONSE_DISTANCE_VERTICAL
390
- : GESTURE_RESPONSE_DISTANCE_HORIZONTAL;
411
+ gestureDirection === 'vertical-inverted'
412
+ ? GESTURE_RESPONSE_DISTANCE_VERTICAL
413
+ : GESTURE_RESPONSE_DISTANCE_HORIZONTAL;
391
414
 
392
415
  if (gestureDirection === 'vertical') {
393
416
  return {
@@ -405,7 +428,10 @@ export class Card extends React.Component<Props> {
405
428
  };
406
429
  } else {
407
430
  const hitSlop = -layout.width + distance;
408
- const invertedMultiplier = getInvertedMultiplier(gestureDirection);
431
+ const invertedMultiplier = getInvertedMultiplier(
432
+ gestureDirection,
433
+ direction === 'rtl'
434
+ );
409
435
 
410
436
  if (invertedMultiplier === 1) {
411
437
  return {
@@ -442,10 +468,22 @@ export class Card extends React.Component<Props> {
442
468
  gestureEnabled,
443
469
  gestureDirection,
444
470
  pageOverflowEnabled,
445
- headerDarkContent,
446
471
  children,
447
472
  containerStyle: customContainerStyle,
448
473
  contentStyle,
474
+ /* eslint-disable @typescript-eslint/no-unused-vars */
475
+ closing,
476
+ direction,
477
+ gestureResponseDistance,
478
+ gestureVelocityImpact,
479
+ onClose,
480
+ onGestureBegin,
481
+ onGestureCanceled,
482
+ onGestureEnd,
483
+ onOpen,
484
+ onTransition,
485
+ transitionSpec,
486
+ /* eslint-enable @typescript-eslint/no-unused-vars */
449
487
  ...rest
450
488
  } = this.props;
451
489
 
@@ -491,21 +529,6 @@ export class Card extends React.Component<Props> {
491
529
 
492
530
  return (
493
531
  <CardAnimationContext.Provider value={interpolationProps}>
494
- {
495
- // StatusBar messes with translucent status bar on Android
496
- // So we should only enable it on iOS
497
- Platform.OS === 'ios' &&
498
- overlayEnabled &&
499
- next &&
500
- getIsModalPresentation(styleInterpolator) ? (
501
- <ModalStatusBarManager
502
- dark={headerDarkContent}
503
- layout={layout}
504
- insets={insets}
505
- style={cardStyle}
506
- />
507
- ) : null
508
- }
509
532
  <Animated.View
510
533
  style={{
511
534
  // This is a dummy style that doesn't actually change anything visually.
@@ -517,7 +540,13 @@ export class Card extends React.Component<Props> {
517
540
  // Make sure that this view isn't removed. If this view is removed, our style with animated value won't apply
518
541
  collapsable={false}
519
542
  />
520
- <View pointerEvents="box-none" {...rest}>
543
+ <View
544
+ pointerEvents="box-none"
545
+ // Make sure this view is not removed on the new architecture, as it causes focus loss during navigation on Android.
546
+ // This can happen when the view flattening results in different trees - due to `overflow` style changing in a parent.
547
+ collapsable={false}
548
+ {...rest}
549
+ >
521
550
  {overlayEnabled ? (
522
551
  <View pointerEvents="box-none" style={StyleSheet.absoluteFill}>
523
552
  {overlay({ style: overlayStyle })}
@@ -542,12 +571,12 @@ export class Card extends React.Component<Props> {
542
571
  style={[
543
572
  styles.shadow,
544
573
  gestureDirection === 'horizontal'
545
- ? [styles.shadowHorizontal, styles.shadowLeft]
574
+ ? [styles.shadowHorizontal, styles.shadowStart]
546
575
  : gestureDirection === 'horizontal-inverted'
547
- ? [styles.shadowHorizontal, styles.shadowRight]
548
- : gestureDirection === 'vertical'
549
- ? [styles.shadowVertical, styles.shadowTop]
550
- : [styles.shadowVertical, styles.shadowBottom],
576
+ ? [styles.shadowHorizontal, styles.shadowEnd]
577
+ : gestureDirection === 'vertical'
578
+ ? [styles.shadowVertical, styles.shadowTop]
579
+ : [styles.shadowVertical, styles.shadowBottom],
551
580
  { backgroundColor },
552
581
  shadowStyle,
553
582
  ]}
@@ -571,16 +600,6 @@ export class Card extends React.Component<Props> {
571
600
  }
572
601
  }
573
602
 
574
- export const getIsModalPresentation = (
575
- cardStyleInterpolator: StackCardStyleInterpolator
576
- ) => {
577
- return (
578
- cardStyleInterpolator === forModalPresentationIOS ||
579
- // Handle custom modal presentation interpolators as well
580
- cardStyleInterpolator.name === 'forModalPresentationIOS'
581
- );
582
- };
583
-
584
603
  const styles = StyleSheet.create({
585
604
  container: {
586
605
  flex: 1,
@@ -601,15 +620,15 @@ const styles = StyleSheet.create({
601
620
  width: 3,
602
621
  shadowOffset: { width: -1, height: 1 },
603
622
  },
604
- shadowLeft: {
605
- left: 0,
623
+ shadowStart: {
624
+ start: 0,
606
625
  },
607
- shadowRight: {
608
- right: 0,
626
+ shadowEnd: {
627
+ end: 0,
609
628
  },
610
629
  shadowVertical: {
611
- left: 0,
612
- right: 0,
630
+ start: 0,
631
+ end: 0,
613
632
  height: 3,
614
633
  shadowOffset: { width: 1, height: -1 },
615
634
  },
@@ -4,7 +4,12 @@ import {
4
4
  HeaderHeightContext,
5
5
  HeaderShownContext,
6
6
  } from '@react-navigation/elements';
7
- import { Route, useTheme } from '@react-navigation/native';
7
+ import {
8
+ type Route,
9
+ useLinkBuilder,
10
+ useLocale,
11
+ useTheme,
12
+ } from '@react-navigation/native';
8
13
  import * as React from 'react';
9
14
  import { Animated, StyleSheet, View } from 'react-native';
10
15
 
@@ -23,8 +28,8 @@ type Props = {
23
28
  modal: boolean;
24
29
  layout: Layout;
25
30
  gesture: Animated.Value;
31
+ preloaded: boolean;
26
32
  scene: Scene;
27
- headerDarkContent: boolean | undefined;
28
33
  safeAreaInsetTop: number;
29
34
  safeAreaInsetRight: number;
30
35
  safeAreaInsetBottom: number;
@@ -32,7 +37,6 @@ type Props = {
32
37
  getPreviousScene: (props: { route: Route<string> }) => Scene | undefined;
33
38
  getFocusedRoute: () => Route<string>;
34
39
  renderHeader: (props: HeaderContainerProps) => React.ReactNode;
35
- renderScene: (props: { route: Route<string> }) => React.ReactNode;
36
40
  onOpenRoute: (props: { route: Route<string> }) => void;
37
41
  onCloseRoute: (props: { route: Route<string> }) => void;
38
42
  onTransitionStart: (
@@ -66,7 +70,6 @@ function CardContainerInner({
66
70
  modal,
67
71
  getPreviousScene,
68
72
  getFocusedRoute,
69
- headerDarkContent,
70
73
  hasAbsoluteFloatHeader,
71
74
  headerHeight,
72
75
  onHeaderHeightChange,
@@ -81,14 +84,16 @@ function CardContainerInner({
81
84
  onGestureStart,
82
85
  onTransitionEnd,
83
86
  onTransitionStart,
87
+ preloaded,
84
88
  renderHeader,
85
- renderScene,
86
89
  safeAreaInsetBottom,
87
90
  safeAreaInsetLeft,
88
91
  safeAreaInsetRight,
89
92
  safeAreaInsetTop,
90
93
  scene,
91
94
  }: Props) {
95
+ const { direction } = useLocale();
96
+
92
97
  const parentHeaderHeight = React.useContext(HeaderHeightContext);
93
98
 
94
99
  const { onPageChangeStart, onPageChangeCancel, onPageChangeConfirm } =
@@ -185,7 +190,7 @@ function CardContainerInner({
185
190
 
186
191
  const {
187
192
  presentation,
188
- animationEnabled,
193
+ animation,
189
194
  cardOverlay,
190
195
  cardOverlayEnabled,
191
196
  cardShadowEnabled,
@@ -200,19 +205,22 @@ function CardContainerInner({
200
205
  transitionSpec,
201
206
  } = scene.descriptor.options;
202
207
 
208
+ const { buildHref } = useLinkBuilder();
203
209
  const previousScene = getPreviousScene({ route: scene.descriptor.route });
204
210
 
205
211
  let backTitle: string | undefined;
212
+ let href: string | undefined;
206
213
 
207
214
  if (previousScene) {
208
215
  const { options, route } = previousScene.descriptor;
209
216
 
210
217
  backTitle = getHeaderTitle(options, route.name);
218
+ href = buildHref(route.name, route.params);
211
219
  }
212
220
 
213
221
  const headerBack = React.useMemo(
214
- () => (backTitle !== undefined ? { title: backTitle } : undefined),
215
- [backTitle]
222
+ () => ({ title: backTitle, href }),
223
+ [backTitle, href]
216
224
  );
217
225
 
218
226
  return (
@@ -221,6 +229,7 @@ function CardContainerInner({
221
229
  gestureDirection={gestureDirection}
222
230
  layout={layout}
223
231
  insets={insets}
232
+ direction={direction}
224
233
  gesture={gesture}
225
234
  current={scene.progress.current}
226
235
  next={scene.progress.next}
@@ -243,7 +252,7 @@ function CardContainerInner({
243
252
  importantForAccessibility={focused ? 'auto' : 'no-hide-descendants'}
244
253
  pointerEvents={active ? 'box-none' : pointerEvents}
245
254
  pageOverflowEnabled={headerMode !== 'float' && presentation !== 'modal'}
246
- headerDarkContent={headerDarkContent}
255
+ preloaded={preloaded}
247
256
  containerStyle={
248
257
  hasAbsoluteFloatHeader && headerMode !== 'screen'
249
258
  ? { marginTop: headerHeight }
@@ -266,7 +275,7 @@ function CardContainerInner({
266
275
  display:
267
276
  // Hide unfocused screens when animation isn't enabled
268
277
  // This is also necessary for a11y on web
269
- animationEnabled === false &&
278
+ animation === 'none' &&
270
279
  isNextScreenTransparent === false &&
271
280
  detachCurrentScreen !== false &&
272
281
  !focused
@@ -286,7 +295,7 @@ function CardContainerInner({
286
295
  <HeaderHeightContext.Provider
287
296
  value={headerShown ? headerHeight : parentHeaderHeight ?? 0}
288
297
  >
289
- {renderScene({ route: scene.descriptor.route })}
298
+ {scene.descriptor.render()}
290
299
  </HeaderHeightContext.Provider>
291
300
  </HeaderShownContext.Provider>
292
301
  </HeaderBackContext.Provider>
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { StyleSheet, View, ViewProps } from 'react-native';
2
+ import { StyleSheet, View, type ViewProps } from 'react-native';
3
3
 
4
4
  type Props = ViewProps & {
5
5
  enabled: boolean;
@@ -27,6 +27,7 @@ export const CardSheet = React.forwardRef<CardSheetRef, Props>(
27
27
  return { setPointerEvents };
28
28
  });
29
29
 
30
+ const workaroundApplied = React.useRef(false);
30
31
  React.useEffect(() => {
31
32
  if (typeof document === 'undefined' || !document.body) {
32
33
  // Only run when DOM is available
@@ -36,6 +37,29 @@ export const CardSheet = React.forwardRef<CardSheetRef, Props>(
36
37
  const width = document.body.clientWidth;
37
38
  const height = document.body.clientHeight;
38
39
 
40
+ // Workaround for mobile Chrome, necessary when a navigation happens
41
+ // when the address bar has already collapsed, which resulted in an
42
+ // empty space at the bottom of the page (matching the height of the
43
+ // address bar). To fix this, it's necessary to update the height of
44
+ // the DOM with the current height of the window.
45
+ // See https://css-tricks.com/the-trick-to-viewport-units-on-mobile/
46
+ const fillHeight = height === layout.height;
47
+ if (fillHeight) {
48
+ const vh = window.innerHeight * 0.01;
49
+ document.documentElement.style.setProperty('--vh', `${vh}px`);
50
+ document.body.setAttribute(
51
+ 'style',
52
+ `height: calc(var(--vh, 1vh) * 100);`
53
+ );
54
+ workaroundApplied.current = true;
55
+ } else {
56
+ // Revert the workaround if the stack does not occupy the whole
57
+ // height of the page
58
+ if (workaroundApplied.current) {
59
+ document.documentElement.style.removeProperty('--vh');
60
+ }
61
+ }
62
+
39
63
  setFill(width === layout.width && height === layout.height);
40
64
  }, [layout.height, layout.width]);
41
65