@react-navigation/stack 8.0.0-alpha.6 → 8.0.0-alpha.60

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 (147) hide show
  1. package/lib/module/TransitionConfigs/CardStyleInterpolators.js +280 -84
  2. package/lib/module/TransitionConfigs/CardStyleInterpolators.js.map +1 -1
  3. package/lib/module/TransitionConfigs/HeaderStyleInterpolators.js +11 -44
  4. package/lib/module/TransitionConfigs/HeaderStyleInterpolators.js.map +1 -1
  5. package/lib/module/TransitionConfigs/TransitionEasings.js +71 -0
  6. package/lib/module/TransitionConfigs/TransitionEasings.js.map +1 -0
  7. package/lib/module/TransitionConfigs/TransitionPresets.js +50 -10
  8. package/lib/module/TransitionConfigs/TransitionPresets.js.map +1 -1
  9. package/lib/module/TransitionConfigs/TransitionSpecs.js +69 -34
  10. package/lib/module/TransitionConfigs/TransitionSpecs.js.map +1 -1
  11. package/lib/module/index.js +2 -2
  12. package/lib/module/index.js.map +1 -1
  13. package/lib/module/navigators/createStackNavigator.js +37 -33
  14. package/lib/module/navigators/createStackNavigator.js.map +1 -1
  15. package/lib/module/utils/GestureHandlerContext.js +5 -0
  16. package/lib/module/utils/GestureHandlerContext.js.map +1 -0
  17. package/lib/module/utils/gestureActivationCriteria.js +10 -8
  18. package/lib/module/utils/gestureActivationCriteria.js.map +1 -1
  19. package/lib/module/utils/useCardAnimation.js +1 -1
  20. package/lib/module/utils/useCardAnimation.js.map +1 -1
  21. package/lib/module/utils/useGestureHandler.js +9 -0
  22. package/lib/module/utils/useGestureHandler.js.map +1 -0
  23. package/lib/module/utils/useKeyboardManager.js +71 -26
  24. package/lib/module/utils/useKeyboardManager.js.map +1 -1
  25. package/lib/module/views/GestureHandler.js +15 -14
  26. package/lib/module/views/GestureHandler.js.map +1 -1
  27. package/lib/module/views/GestureHandlerNative.js +16 -10
  28. package/lib/module/views/GestureHandlerNative.js.map +1 -1
  29. package/lib/module/views/Header/Header.js +4 -2
  30. package/lib/module/views/Header/Header.js.map +1 -1
  31. package/lib/module/views/Header/HeaderContainer.js +60 -21
  32. package/lib/module/views/Header/HeaderContainer.js.map +1 -1
  33. package/lib/module/views/Header/HeaderSegment.js +6 -9
  34. package/lib/module/views/Header/HeaderSegment.js.map +1 -1
  35. package/lib/module/views/Stack/Card.js +170 -123
  36. package/lib/module/views/Stack/Card.js.map +1 -1
  37. package/lib/module/views/Stack/CardContainer.js +96 -98
  38. package/lib/module/views/Stack/CardContainer.js.map +1 -1
  39. package/lib/module/views/Stack/CardContent.js +10 -37
  40. package/lib/module/views/Stack/CardContent.js.map +1 -1
  41. package/lib/module/views/Stack/CardStack.js +211 -147
  42. package/lib/module/views/Stack/CardStack.js.map +1 -1
  43. package/lib/module/views/Stack/StackView.js +106 -57
  44. package/lib/module/views/Stack/StackView.js.map +1 -1
  45. package/lib/typescript/src/TransitionConfigs/CardStyleInterpolators.d.ts +20 -12
  46. package/lib/typescript/src/TransitionConfigs/CardStyleInterpolators.d.ts.map +1 -1
  47. package/lib/typescript/src/TransitionConfigs/HeaderStyleInterpolators.d.ts +4 -4
  48. package/lib/typescript/src/TransitionConfigs/HeaderStyleInterpolators.d.ts.map +1 -1
  49. package/lib/typescript/src/TransitionConfigs/TransitionEasings.d.ts +38 -0
  50. package/lib/typescript/src/TransitionConfigs/TransitionEasings.d.ts.map +1 -0
  51. package/lib/typescript/src/TransitionConfigs/TransitionPresets.d.ts +15 -3
  52. package/lib/typescript/src/TransitionConfigs/TransitionPresets.d.ts.map +1 -1
  53. package/lib/typescript/src/TransitionConfigs/TransitionSpecs.d.ts +44 -15
  54. package/lib/typescript/src/TransitionConfigs/TransitionSpecs.d.ts.map +1 -1
  55. package/lib/typescript/src/index.d.ts +12 -12
  56. package/lib/typescript/src/index.d.ts.map +1 -1
  57. package/lib/typescript/src/navigators/createStackNavigator.d.ts +10 -15
  58. package/lib/typescript/src/navigators/createStackNavigator.d.ts.map +1 -1
  59. package/lib/typescript/src/types.d.ts +120 -108
  60. package/lib/typescript/src/types.d.ts.map +1 -1
  61. package/lib/typescript/src/utils/CardAnimationContext.d.ts +1 -1
  62. package/lib/typescript/src/utils/CardAnimationContext.d.ts.map +1 -1
  63. package/lib/typescript/src/utils/GestureHandlerContext.d.ts +3 -0
  64. package/lib/typescript/src/utils/GestureHandlerContext.d.ts.map +1 -0
  65. package/lib/typescript/src/utils/gestureActivationCriteria.d.ts +4 -51
  66. package/lib/typescript/src/utils/gestureActivationCriteria.d.ts.map +1 -1
  67. package/lib/typescript/src/utils/getDistanceForDirection.d.ts +1 -1
  68. package/lib/typescript/src/utils/getDistanceForDirection.d.ts.map +1 -1
  69. package/lib/typescript/src/utils/getInvertedMultiplier.d.ts +1 -1
  70. package/lib/typescript/src/utils/getInvertedMultiplier.d.ts.map +1 -1
  71. package/lib/typescript/src/utils/getModalRoutesKeys.d.ts +1 -1
  72. package/lib/typescript/src/utils/getModalRoutesKeys.d.ts.map +1 -1
  73. package/lib/typescript/src/utils/getShadowStyle.d.ts +5 -5
  74. package/lib/typescript/src/utils/useCardAnimation.d.ts +1 -1
  75. package/lib/typescript/src/utils/useCardAnimation.d.ts.map +1 -1
  76. package/lib/typescript/src/utils/useGestureHandler.d.ts +2 -0
  77. package/lib/typescript/src/utils/useGestureHandler.d.ts.map +1 -0
  78. package/lib/typescript/src/utils/useKeyboardManager.d.ts +12 -2
  79. package/lib/typescript/src/utils/useKeyboardManager.d.ts.map +1 -1
  80. package/lib/typescript/src/views/GestureHandler.android.d.ts +1 -1
  81. package/lib/typescript/src/views/GestureHandler.android.d.ts.map +1 -1
  82. package/lib/typescript/src/views/GestureHandler.d.ts +7 -11
  83. package/lib/typescript/src/views/GestureHandler.d.ts.map +1 -1
  84. package/lib/typescript/src/views/GestureHandler.ios.d.ts +1 -1
  85. package/lib/typescript/src/views/GestureHandler.ios.d.ts.map +1 -1
  86. package/lib/typescript/src/views/GestureHandlerNative.d.ts +9 -4
  87. package/lib/typescript/src/views/GestureHandlerNative.d.ts.map +1 -1
  88. package/lib/typescript/src/views/Header/Header.d.ts +2 -2
  89. package/lib/typescript/src/views/Header/Header.d.ts.map +1 -1
  90. package/lib/typescript/src/views/Header/HeaderContainer.d.ts +9 -3
  91. package/lib/typescript/src/views/Header/HeaderContainer.d.ts.map +1 -1
  92. package/lib/typescript/src/views/Header/HeaderSegment.d.ts +6 -4
  93. package/lib/typescript/src/views/Header/HeaderSegment.d.ts.map +1 -1
  94. package/lib/typescript/src/views/Stack/Card.d.ts +14 -8
  95. package/lib/typescript/src/views/Stack/Card.d.ts.map +1 -1
  96. package/lib/typescript/src/views/Stack/CardContainer.d.ts +7 -7
  97. package/lib/typescript/src/views/Stack/CardContainer.d.ts.map +1 -1
  98. package/lib/typescript/src/views/Stack/CardContent.d.ts +1 -1
  99. package/lib/typescript/src/views/Stack/CardContent.d.ts.map +1 -1
  100. package/lib/typescript/src/views/Stack/CardStack.d.ts +10 -6
  101. package/lib/typescript/src/views/Stack/CardStack.d.ts.map +1 -1
  102. package/lib/typescript/src/views/Stack/StackView.d.ts +14 -17
  103. package/lib/typescript/src/views/Stack/StackView.d.ts.map +1 -1
  104. package/package.json +23 -24
  105. package/src/TransitionConfigs/CardStyleInterpolators.tsx +399 -100
  106. package/src/TransitionConfigs/HeaderStyleInterpolators.tsx +15 -46
  107. package/src/TransitionConfigs/TransitionEasings.tsx +90 -0
  108. package/src/TransitionConfigs/TransitionPresets.tsx +56 -10
  109. package/src/TransitionConfigs/TransitionSpecs.tsx +68 -34
  110. package/src/index.tsx +3 -2
  111. package/src/navigators/createStackNavigator.tsx +74 -91
  112. package/src/types.tsx +149 -123
  113. package/src/utils/GestureHandlerContext.tsx +5 -0
  114. package/src/utils/gestureActivationCriteria.tsx +14 -10
  115. package/src/utils/useCardAnimation.tsx +1 -1
  116. package/src/utils/useGestureHandler.tsx +9 -0
  117. package/src/utils/useKeyboardManager.tsx +96 -33
  118. package/src/views/GestureHandler.tsx +24 -16
  119. package/src/views/GestureHandlerNative.tsx +24 -13
  120. package/src/views/Header/Header.tsx +4 -2
  121. package/src/views/Header/HeaderContainer.tsx +79 -37
  122. package/src/views/Header/HeaderSegment.tsx +10 -11
  123. package/src/views/Stack/Card.tsx +241 -154
  124. package/src/views/Stack/CardContainer.tsx +111 -127
  125. package/src/views/Stack/CardContent.tsx +13 -51
  126. package/src/views/Stack/CardStack.tsx +478 -335
  127. package/src/views/Stack/StackView.tsx +181 -82
  128. package/lib/module/utils/GestureHandlerRefContext.js +0 -5
  129. package/lib/module/utils/GestureHandlerRefContext.js.map +0 -1
  130. package/lib/module/utils/findLastIndex.js +0 -11
  131. package/lib/module/utils/findLastIndex.js.map +0 -1
  132. package/lib/module/utils/useGestureHandlerRef.js +0 -12
  133. package/lib/module/utils/useGestureHandlerRef.js.map +0 -1
  134. package/lib/module/views/Stack/CardA11yWrapper.js +0 -43
  135. package/lib/module/views/Stack/CardA11yWrapper.js.map +0 -1
  136. package/lib/typescript/src/utils/GestureHandlerRefContext.d.ts +0 -3
  137. package/lib/typescript/src/utils/GestureHandlerRefContext.d.ts.map +0 -1
  138. package/lib/typescript/src/utils/findLastIndex.d.ts +0 -2
  139. package/lib/typescript/src/utils/findLastIndex.d.ts.map +0 -1
  140. package/lib/typescript/src/utils/useGestureHandlerRef.d.ts +0 -3
  141. package/lib/typescript/src/utils/useGestureHandlerRef.d.ts.map +0 -1
  142. package/lib/typescript/src/views/Stack/CardA11yWrapper.d.ts +0 -15
  143. package/lib/typescript/src/views/Stack/CardA11yWrapper.d.ts.map +0 -1
  144. package/src/utils/GestureHandlerRefContext.tsx +0 -5
  145. package/src/utils/findLastIndex.tsx +0 -9
  146. package/src/utils/useGestureHandlerRef.tsx +0 -15
  147. package/src/views/Stack/CardA11yWrapper.tsx +0 -67
package/src/types.tsx CHANGED
@@ -1,14 +1,13 @@
1
1
  import type {
2
- HeaderBackButton,
3
2
  HeaderBackButtonDisplayMode,
4
3
  HeaderBackButtonProps,
5
4
  HeaderOptions,
6
5
  HeaderTitleProps,
6
+ Icon,
7
7
  } from '@react-navigation/elements';
8
8
  import type {
9
9
  DefaultNavigatorOptions,
10
10
  Descriptor,
11
- LocaleDirection,
12
11
  NavigationHelpers,
13
12
  NavigationProp,
14
13
  ParamListBase,
@@ -53,6 +52,7 @@ export type StackNavigationEventMap = {
53
52
 
54
53
  export type StackNavigationHelpers = NavigationHelpers<
55
54
  ParamListBase,
55
+ StackNavigationState<ParamListBase>,
56
56
  StackNavigationEventMap
57
57
  > &
58
58
  StackActionHelpers<ParamListBase>;
@@ -97,6 +97,9 @@ export type StackAnimationName =
97
97
  | 'fade'
98
98
  | 'fade_from_bottom'
99
99
  | 'fade_from_right'
100
+ | 'flip'
101
+ | 'ios_from_left'
102
+ | 'ios_from_right'
100
103
  | 'none'
101
104
  | 'reveal_from_bottom'
102
105
  | 'scale_from_center'
@@ -107,7 +110,8 @@ export type StackAnimationName =
107
110
  type SceneOptionsDefaults = TransitionPreset & {
108
111
  animation: StackAnimationName;
109
112
  gestureEnabled: boolean;
110
- cardOverlayEnabled: boolean;
113
+ cardOverlayEnabled: boolean | undefined;
114
+ cardShadowEnabled: boolean | undefined;
111
115
  headerMode: StackHeaderMode;
112
116
  };
113
117
 
@@ -127,6 +131,10 @@ export type Scene = {
127
131
  * Animated nodes representing the progress of the animation.
128
132
  */
129
133
  progress: SceneProgress;
134
+ /**
135
+ * Animated node representing whether the screen is closing.
136
+ */
137
+ closing: Animated.Value;
130
138
  };
131
139
 
132
140
  export type SceneProgress = {
@@ -138,18 +146,16 @@ export type SceneProgress = {
138
146
  * Progress value for the screen after this one in the stack.
139
147
  * This can be `undefined` in case the screen animating is the last one.
140
148
  */
141
- next?: Animated.AnimatedInterpolation<number>;
149
+ next?: Animated.AnimatedInterpolation<number> | undefined;
142
150
  /**
143
151
  * Progress value for the screen before this one in the stack.
144
152
  * This can be `undefined` in case the screen animating is the first one.
145
153
  */
146
- previous?: Animated.AnimatedInterpolation<number>;
154
+ previous?: Animated.AnimatedInterpolation<number> | undefined;
147
155
  };
148
156
 
149
157
  export type StackHeaderMode = 'float' | 'screen';
150
158
 
151
- export type StackPresentationMode = 'card' | 'modal';
152
-
153
159
  export type StackHeaderOptions = Omit<
154
160
  HeaderOptions,
155
161
  'headerLeft' | 'headerTitle' | 'headerRight'
@@ -161,40 +167,43 @@ export type StackHeaderOptions = Omit<
161
167
  * It receives `allowFontScaling`, `tintColor`, `style` and `children` in the options object as an argument.
162
168
  * The title string is passed in `children`.
163
169
  */
164
- headerTitle?: string | ((props: HeaderTitleProps) => React.ReactNode);
170
+ headerTitle?:
171
+ | string
172
+ | ((props: HeaderTitleProps) => React.ReactNode)
173
+ | undefined;
165
174
  /**
166
175
  * Function which returns a React Element to display on the left side of the header.
167
176
  */
168
- headerLeft?: (props: StackHeaderLeftProps) => React.ReactNode;
177
+ headerLeft?: ((props: StackHeaderLeftProps) => React.ReactNode) | undefined;
169
178
  /**
170
179
  * Function which returns a React Element to display on the right side of the header.
171
180
  */
172
- headerRight?: (props: StackHeaderRightProps) => React.ReactNode;
181
+ headerRight?: ((props: StackHeaderRightProps) => React.ReactNode) | undefined;
173
182
  /**
174
183
  * Whether back button title font should scale to respect Text Size accessibility settings. Defaults to `false`.
175
184
  */
176
- headerBackAllowFontScaling?: boolean;
185
+ headerBackAllowFontScaling?: boolean | undefined;
177
186
  /**
178
187
  * Accessibility label for the header back button.
179
188
  */
180
- headerBackAccessibilityLabel?: string;
189
+ headerBackAccessibilityLabel?: string | undefined;
181
190
  /**
182
191
  * ID to locate this back button in tests.
183
192
  */
184
- headerBackTestID?: string;
193
+ headerBackTestID?: string | undefined;
185
194
  /**
186
195
  * Title string used by the back button on iOS.
187
196
  * Defaults to the previous screen's title, or "Back" if there's not enough space.
188
197
  * Use `headerBackButtonDisplayMode` to customize the behavior.
189
198
  */
190
- headerBackTitle?: string;
199
+ headerBackTitle?: string | undefined;
191
200
  /**
192
201
  * Title string used by the back button when `headerBackTitle` doesn't fit on the screen.
193
202
  * Use `headerBackButtonDisplayMode` to customize the behavior.
194
203
  *
195
204
  * Defaults to "Back".
196
205
  */
197
- headerBackTruncatedTitle?: string;
206
+ headerBackTruncatedTitle?: string | undefined;
198
207
  /**
199
208
  * How the back button displays icon and title.
200
209
  *
@@ -205,37 +214,62 @@ export type StackHeaderOptions = Omit<
205
214
  *
206
215
  * Defaults to "default" on iOS, and "minimal" on other platforms.
207
216
  */
208
- headerBackButtonDisplayMode?: HeaderBackButtonDisplayMode;
217
+ headerBackButtonDisplayMode?: HeaderBackButtonDisplayMode | undefined;
209
218
  /**
210
219
  * Style object for the back title.
211
220
  */
212
221
  headerBackTitleStyle?: StyleProp<TextStyle>;
213
222
  /**
214
- * Function which returns a React Element to display custom image in header's back button.
215
- * It receives the `tintColor` in in the options object as an argument. object.
216
- * Defaults to Image component with a the default back icon image for the platform (a chevron on iOS and an arrow on Android).
217
- */
218
- headerBackImage?: React.ComponentProps<typeof HeaderBackButton>['backImage'];
223
+ * Icon to display in the header in the back button.
224
+ *
225
+ * Supported types:
226
+ * - image: custom image source
227
+ * - sfSymbol: SF Symbol icon (iOS only)
228
+ * - materialSymbol: material symbol icon (Android only)
229
+ * - React Node: function that returns a React Element
230
+ *
231
+ * Defaults to back icon image for the platform
232
+ * - A chevron on iOS
233
+ * - An arrow on Android
234
+ *
235
+ * @example
236
+ * ```js
237
+ * headerBackIcon: {
238
+ * type: 'image',
239
+ * source: require('./back-icon.png'),
240
+ * }
241
+ * ```
242
+ */
243
+ headerBackIcon?:
244
+ | Icon
245
+ | ((props: { tintColor: ColorValue | undefined }) => React.ReactNode)
246
+ | undefined;
219
247
  };
220
248
 
221
249
  export type StackHeaderProps = {
222
250
  /**
223
251
  * Options for the back button.
224
252
  */
225
- back?: {
226
- /**
227
- * Title of the previous screen.
228
- */
229
- title: string | undefined;
230
- /**
231
- * The `href` to use for the anchor tag on web
232
- */
233
- href: string | undefined;
234
- };
253
+ back?:
254
+ | {
255
+ /**
256
+ * Title of the previous screen.
257
+ */
258
+ title: string | undefined;
259
+ /**
260
+ * The `href` to use for the anchor tag on web
261
+ */
262
+ href: string | undefined;
263
+ }
264
+ | undefined;
235
265
  /**
236
266
  * Animated nodes representing the progress of the animation.
237
267
  */
238
268
  progress: SceneProgress;
269
+ /**
270
+ * Direction multiplier for the transition.
271
+ */
272
+ inverted: 1 | -1;
239
273
  /**
240
274
  * Options for the current screen.
241
275
  */
@@ -258,26 +292,26 @@ export type StackHeaderRightProps = {
258
292
  /**
259
293
  * Tint color for the header button.
260
294
  */
261
- tintColor?: ColorValue;
295
+ tintColor?: ColorValue | undefined;
262
296
  /**
263
297
  * Color for material ripple (Android >= 5.0 only).
264
298
  */
265
- pressColor?: ColorValue;
299
+ pressColor?: ColorValue | undefined;
266
300
  /**
267
301
  * Opacity when the button is pressed, used when ripple is not supported.
268
302
  */
269
- pressOpacity?: number;
303
+ pressOpacity?: number | undefined;
270
304
  /**
271
305
  * Whether it's possible to navigate back in stack.
272
306
  */
273
- canGoBack?: boolean;
307
+ canGoBack?: boolean | undefined;
274
308
  };
275
309
 
276
310
  export type StackHeaderLeftProps = HeaderBackButtonProps & {
277
311
  /**
278
312
  * Whether it's possible to navigate back in stack.
279
313
  */
280
- canGoBack?: boolean;
314
+ canGoBack?: boolean | undefined;
281
315
  };
282
316
 
283
317
  export type StackDescriptor = Descriptor<
@@ -293,48 +327,45 @@ export type StackNavigationOptions = StackHeaderOptions &
293
327
  /**
294
328
  * String that can be displayed in the header as a fallback for `headerTitle`.
295
329
  */
296
- title?: string;
330
+ title?: string | undefined;
297
331
  /**
298
332
  * Function that given `HeaderProps` returns a React Element to display as a header.
299
333
  */
300
- header?: (props: StackHeaderProps) => React.ReactNode;
334
+ header?: ((props: StackHeaderProps) => React.ReactNode) | undefined;
301
335
  /**
302
336
  * Whether the header floats above the screen or part of the screen.
303
- * Defaults to `float` on iOS for non-modals, and `screen` for the rest.
337
+ * Defaults to `float` on iOS for animations where the header transitions
338
+ * separately, and `screen` otherwise.
304
339
  */
305
- headerMode?: StackHeaderMode;
340
+ headerMode?: StackHeaderMode | undefined;
306
341
  /**
307
342
  * Whether to show the header. The header is shown by default.
308
343
  * Setting this to `false` hides the header.
309
344
  */
310
- headerShown?: boolean;
345
+ headerShown?: boolean | undefined;
311
346
  /**
312
- * Whether a shadow is visible for the card during transitions. Defaults to `true`.
347
+ * Whether a shadow is visible for the card during transitions.
348
+ * Defaults to whether `cardStyleInterpolator` returns a `shadowStyle`.
349
+ * Setting this overrides the default behavior.
313
350
  */
314
- cardShadowEnabled?: boolean;
351
+ cardShadowEnabled?: boolean | undefined;
315
352
  /**
316
353
  * Whether to have a semi-transparent dark overlay visible under the card during transitions.
317
- * Defaults to `true` on Android and `false` on iOS.
354
+ * Defaults to whether `cardStyleInterpolator` returns an `overlayStyle`.
355
+ * Setting this overrides the default behavior.
318
356
  */
319
- cardOverlayEnabled?: boolean;
357
+ cardOverlayEnabled?: boolean | undefined;
320
358
  /**
321
359
  * Function that returns a React Element to display as a overlay for the card.
322
360
  */
323
- cardOverlay?: (props: {
324
- style: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
325
- }) => React.ReactNode;
361
+ cardOverlay?:
362
+ | ((props: {
363
+ style: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
364
+ }) => React.ReactNode)
365
+ | undefined;
326
366
  /**
327
367
  * Style object for the card in stack.
328
368
  * You can provide a custom background color to use instead of the default background here.
329
- *
330
- * You can also specify `{ backgroundColor: 'transparent' }` to make the previous screen visible underneath.
331
- * This is useful to implement things like modal dialogs.
332
- *
333
- * You should also specify `detachPreviousScreen: false` in options when using a transparent background
334
- * so that the previous screen isn't detached and stays below the current screen.
335
- *
336
- * You might also need to change the animation of the screen using `cardStyleInterpolator`
337
- * so that the previous screen isn't transformed or invisible.
338
369
  */
339
370
  cardStyle?: StyleProp<ViewStyle>;
340
371
  /**
@@ -348,130 +379,119 @@ export type StackNavigationOptions = StackHeaderOptions &
348
379
  * - `transparentModal`: Similar to `modal`. This changes following things:
349
380
  * - Sets `headerMode` to `screen` for the screen unless specified otherwise.
350
381
  * - Sets background color of the screen to transparent, so previous screen is visible
351
- * - Adjusts the `detachPreviousScreen` option so that the previous screen stays rendered.
352
382
  * - Prevents the previous screen from animating from its last position.
353
383
  * - Changes the screen animation to a vertical slide animation.
354
384
  *
355
385
  * Defaults to 'card'.
356
386
  */
357
- presentation?: 'card' | 'modal' | 'transparentModal';
387
+ presentation?: 'card' | 'modal' | 'transparentModal' | undefined;
358
388
  /**
359
389
  * How the screen should animate when pushed or popped.
360
390
  *
361
391
  * Supported values:
362
392
  * - 'none': don't animate the screen
363
393
  * - 'default': use the platform default animation
364
- * - 'fade': fade screen in or out
394
+ * - 'fade': fade between screens
365
395
  * - 'fade_from_bottom': fade screen in or out from bottom
396
+ * - 'fade_from_right': fade screen in from the right
397
+ * - 'flip': flip the screen horizontally
398
+ * - 'ios_from_left': use the iOS-style slide from left
399
+ * - 'ios_from_right': use the iOS-style slide from right
366
400
  * - 'slide_from_bottom': slide in the new screen from bottom
367
401
  * - 'slide_from_right': slide in the new screen from right
368
402
  * - 'slide_from_left': slide in the new screen from left
369
403
  * - 'reveal_from_bottom': reveal screen in from bottom to top
370
404
  * - 'scale_from_center': scale screen in from center
371
405
  */
372
- animation?: StackAnimationName;
406
+ animation?: StackAnimationName | undefined;
373
407
  /**
374
408
  * The type of animation to use when this screen replaces another screen. Defaults to `push`.
375
409
  * When `pop` is used, the `pop` animation is applied to the screen being replaced.
376
410
  */
377
- animationTypeForReplace?: 'push' | 'pop';
411
+ animationTypeForReplace?: 'push' | 'pop' | undefined;
378
412
  /**
379
- * Whether you can use gestures to dismiss this screen. Defaults to `true` on iOS, `false` on Android.
413
+ * Whether you can use gestures to dismiss this screen. Defaults to `true`
414
+ * on iOS for navigation-style transitions with an interactive dismissal,
415
+ * and `false` otherwise.
380
416
  * Not supported on Web.
381
417
  */
382
- gestureEnabled?: boolean;
418
+ gestureEnabled?: boolean | undefined;
383
419
  /**
384
420
  * Distance of touch start from the edge of the screen to recognize gestures.
385
421
  * Not supported on Web.
386
422
  */
387
- gestureResponseDistance?: number;
423
+ gestureResponseDistance?: number | undefined;
388
424
  /**
389
425
  * Number which determines the relevance of velocity for the gesture. Defaults to 0.3.
390
426
  * Not supported on Web.
391
427
  */
392
- gestureVelocityImpact?: number;
393
- /**
394
- * Whether to detach the previous screen from the view hierarchy to save memory.
395
- * Set it to `false` if you need the previous screen to be seen through the active screen.
396
- * Only applicable if `detachInactiveScreens` isn't set to `false`.
397
- * Defaults to `false` for the last screen for modals, otherwise `true`.
398
- */
399
- detachPreviousScreen?: boolean;
428
+ gestureVelocityImpact?: number | undefined;
400
429
  /**
401
430
  * If `false`, the keyboard will NOT automatically dismiss when navigating to a new screen from this screen.
402
431
  * Defaults to `true`.
403
432
  */
404
- keyboardHandlingEnabled?: boolean;
433
+ keyboardHandlingEnabled?: boolean | undefined;
434
+
405
435
  /**
406
- * Whether inactive screens should be suspended from re-rendering. Defaults to `false`.
407
- * Defaults to `true` when `enableFreeze()` is run at the top of the application.
408
- * Requires `react-native-screens` version >=3.16.0.
436
+ * What should happen when screens become inactive.
437
+ * - `pause`: Effects are cleaned up
438
+ * - `unmount`: Screen is unmounted
439
+ * - `none`: Screen renders normally
409
440
  *
410
- * Only supported on iOS and Android.
411
- */
412
- freezeOnBlur?: boolean;
413
- /**
414
- * Whether the home indicator should prefer to stay hidden on this screen. Defaults to `false`.
441
+ * Defaults to `pause`.
442
+ *
443
+ * Preloaded screens won't be paused until after navigated to.
444
+ * This makes sure that effects are run to initialize the screen.
415
445
  *
416
- * @platform ios
446
+ * Screens with nested navigators and last 2 screens won't be unmounted.
417
447
  */
418
- autoHideHomeIndicator?: boolean;
448
+ inactiveBehavior?: 'pause' | 'unmount' | 'none' | undefined;
419
449
  };
420
450
 
421
- export type StackNavigationConfig = {
422
- /**
423
- * Whether inactive screens should be detached from the view hierarchy to save memory.
424
- * This will have no effect if you disable `react-native-screens`.
425
- *
426
- * Defaults to `true`.
427
- */
428
- detachInactiveScreens?: boolean;
429
- };
451
+ export type StackNavigationConfig = {};
430
452
 
431
453
  export type TransitionSpec =
432
454
  | {
433
455
  animation: 'spring';
434
456
  config: Omit<
435
457
  Animated.SpringAnimationConfig,
436
- 'toValue' | keyof Animated.AnimationConfig
458
+ 'toValue' | 'useNativeDriver' | 'isInteraction' | 'velocity'
437
459
  >;
438
460
  }
439
461
  | {
440
462
  animation: 'timing';
441
463
  config: Omit<
442
464
  Animated.TimingAnimationConfig,
443
- 'toValue' | keyof Animated.AnimationConfig
465
+ 'toValue' | 'useNativeDriver' | 'isInteraction'
444
466
  >;
445
467
  };
446
468
 
469
+ type StackCardInterpolationState = {
470
+ /**
471
+ * Animated node representing the progress value of the screen.
472
+ */
473
+ progress: Animated.AnimatedInterpolation<number>;
474
+ /**
475
+ * Animated node representing whether the screen is using the closing or
476
+ * opening animation (1 - closing, 0 - opening).
477
+ */
478
+ closing: Animated.AnimatedInterpolation<0 | 1>;
479
+ };
480
+
447
481
  export type StackCardInterpolationProps = {
448
482
  /**
449
483
  * Values for the current screen.
450
484
  */
451
- current: {
452
- /**
453
- * Animated node representing the progress value of the current screen.
454
- */
455
- progress: Animated.AnimatedInterpolation<number>;
456
- };
485
+ current: StackCardInterpolationState;
457
486
  /**
458
487
  * Values for the screen after this one in the stack.
459
488
  * This can be `undefined` in case the screen animating is the last one.
460
489
  */
461
- next?: {
462
- /**
463
- * Animated node representing the progress value of the next screen.
464
- */
465
- progress: Animated.AnimatedInterpolation<number>;
466
- };
490
+ next?: StackCardInterpolationState | undefined;
467
491
  /**
468
492
  * The index of the card with this interpolation in the stack.
469
493
  */
470
494
  index: number;
471
- /**
472
- * Animated node representing whether the card is closing (1 - closing, 0 - not closing).
473
- */
474
- closing: Animated.AnimatedInterpolation<0 | 1>;
475
495
  /**
476
496
  * Animated node representing whether the card is being swiped (1 - swiping, 0 - not swiping).
477
497
  */
@@ -513,6 +533,10 @@ export type StackCardInterpolatedStyle = {
513
533
  * Interpolated style for the view representing the semi-transparent overlay below the card.
514
534
  */
515
535
  overlayStyle?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
536
+ /**
537
+ * Interpolated style for dim on top of the card content.
538
+ */
539
+ dimStyle?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
516
540
  /**
517
541
  * Interpolated style representing the card shadow.
518
542
  */
@@ -537,16 +561,18 @@ export type StackHeaderInterpolationProps = {
537
561
  * Values for the screen after this one in the stack.
538
562
  * This can be `undefined` in case the screen animating is the last one.
539
563
  */
540
- next?: {
541
- /**
542
- * Animated node representing the progress value of the next screen.
543
- */
544
- progress: Animated.AnimatedInterpolation<number>;
545
- };
564
+ next?:
565
+ | {
566
+ /**
567
+ * Animated node representing the progress value of the next screen.
568
+ */
569
+ progress: Animated.AnimatedInterpolation<number>;
570
+ }
571
+ | undefined;
546
572
  /**
547
- * Writing direction of the layout.
573
+ * Direction multiplier for the transition.
548
574
  */
549
- direction: LocaleDirection;
575
+ inverted: 1 | -1;
550
576
  /**
551
577
  * Layout measurements for various items we use for animation.
552
578
  */
@@ -566,19 +592,19 @@ export type StackHeaderInterpolatedStyle = {
566
592
  /**
567
593
  * Interpolated style for the left button (usually the back button).
568
594
  */
569
- leftButtonStyle?: Animated.WithAnimatedValue<ViewStyle>;
595
+ leftButtonStyle?: Animated.WithAnimatedValue<ViewStyle> | undefined;
570
596
  /**
571
597
  * Interpolated style for the right button.
572
598
  */
573
- rightButtonStyle?: Animated.WithAnimatedValue<ViewStyle>;
599
+ rightButtonStyle?: Animated.WithAnimatedValue<ViewStyle> | undefined;
574
600
  /**
575
601
  * Interpolated style for the header title text.
576
602
  */
577
- titleStyle?: Animated.WithAnimatedValue<TextStyle>;
603
+ titleStyle?: Animated.WithAnimatedValue<TextStyle> | undefined;
578
604
  /**
579
605
  * Interpolated style for the header background.
580
606
  */
581
- backgroundStyle?: Animated.WithAnimatedValue<ViewStyle>;
607
+ backgroundStyle?: Animated.WithAnimatedValue<ViewStyle> | undefined;
582
608
  };
583
609
 
584
610
  export type StackHeaderStyleInterpolator = (
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+
3
+ export const GestureHandlerContext = React.createContext<
4
+ import('react-native-gesture-handler').PanGesture | null
5
+ >(null);
@@ -1,4 +1,5 @@
1
1
  import type { LocaleDirection } from '@react-navigation/native';
2
+ import type { PanGestureConfig } from 'react-native-gesture-handler';
2
3
 
3
4
  import type { GestureDirection, Layout } from '../types';
4
5
  import { getInvertedMultiplier } from './getInvertedMultiplier';
@@ -17,9 +18,9 @@ export const gestureActivationCriteria = ({
17
18
  }: {
18
19
  direction: LocaleDirection;
19
20
  gestureDirection: GestureDirection;
20
- gestureResponseDistance?: number;
21
+ gestureResponseDistance?: number | undefined;
21
22
  layout: Layout;
22
- }) => {
23
+ }): PanGestureConfig => {
23
24
  const enableTrackpadTwoFingerGesture = true;
24
25
 
25
26
  const distance =
@@ -30,17 +31,20 @@ export const gestureActivationCriteria = ({
30
31
  ? GESTURE_RESPONSE_DISTANCE_VERTICAL
31
32
  : GESTURE_RESPONSE_DISTANCE_HORIZONTAL;
32
33
 
34
+ const failOffsetX: [number, number] = [-15, 15];
35
+ const failOffsetY: [number, number] = [-20, 20];
36
+
33
37
  if (gestureDirection === 'vertical') {
34
38
  return {
35
- maxDeltaX: 15,
36
- minOffsetY: 5,
39
+ failOffsetX,
40
+ activeOffsetY: 5,
37
41
  hitSlop: { bottom: -layout.height + distance },
38
42
  enableTrackpadTwoFingerGesture,
39
43
  };
40
44
  } else if (gestureDirection === 'vertical-inverted') {
41
45
  return {
42
- maxDeltaX: 15,
43
- minOffsetY: -5,
46
+ failOffsetX,
47
+ activeOffsetY: -5,
44
48
  hitSlop: { top: -layout.height + distance },
45
49
  enableTrackpadTwoFingerGesture,
46
50
  };
@@ -53,15 +57,15 @@ export const gestureActivationCriteria = ({
53
57
 
54
58
  if (invertedMultiplier === 1) {
55
59
  return {
56
- minOffsetX: 5,
57
- maxDeltaY: 20,
60
+ activeOffsetX: 5,
61
+ failOffsetY,
58
62
  hitSlop: { right: hitSlop },
59
63
  enableTrackpadTwoFingerGesture,
60
64
  };
61
65
  } else {
62
66
  return {
63
- minOffsetX: -5,
64
- maxDeltaY: 20,
67
+ activeOffsetX: -5,
68
+ failOffsetY,
65
69
  hitSlop: { left: hitSlop },
66
70
  enableTrackpadTwoFingerGesture,
67
71
  };
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  import { CardAnimationContext } from './CardAnimationContext';
4
4
 
5
5
  export function useCardAnimation() {
6
- const animation = React.useContext(CardAnimationContext);
6
+ const animation = React.use(CardAnimationContext);
7
7
 
8
8
  if (animation === undefined) {
9
9
  throw new Error(
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+
3
+ import { GestureHandlerContext } from './GestureHandlerContext';
4
+
5
+ export function useGestureHandler() {
6
+ const gesture = React.useContext(GestureHandlerContext);
7
+
8
+ return gesture;
9
+ }