@react-navigation/native-stack 7.0.0-alpha.4 → 7.0.0-alpha.6

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 (77) hide show
  1. package/lib/commonjs/index.js +7 -0
  2. package/lib/commonjs/index.js.map +1 -1
  3. package/lib/commonjs/navigators/createNativeStackNavigator.js +21 -23
  4. package/lib/commonjs/navigators/createNativeStackNavigator.js.map +1 -1
  5. package/lib/commonjs/types.js.map +1 -1
  6. package/lib/commonjs/utils/useAnimatedHeaderHeight.js +19 -0
  7. package/lib/commonjs/utils/useAnimatedHeaderHeight.js.map +1 -0
  8. package/lib/commonjs/utils/useDismissedRouteError.js +3 -4
  9. package/lib/commonjs/utils/useDismissedRouteError.js.map +1 -1
  10. package/lib/commonjs/utils/useInvalidPreventRemoveError.js +4 -5
  11. package/lib/commonjs/utils/useInvalidPreventRemoveError.js.map +1 -1
  12. package/lib/commonjs/views/DebugContainer.js +2 -2
  13. package/lib/commonjs/views/DebugContainer.js.map +1 -1
  14. package/lib/commonjs/views/DebugContainer.native.js +3 -3
  15. package/lib/commonjs/views/DebugContainer.native.js.map +1 -1
  16. package/lib/commonjs/views/FontProcessor.js.map +1 -1
  17. package/lib/commonjs/views/FontProcessor.native.js +2 -4
  18. package/lib/commonjs/views/FontProcessor.native.js.map +1 -1
  19. package/lib/commonjs/views/HeaderConfig.js +6 -22
  20. package/lib/commonjs/views/HeaderConfig.js.map +1 -1
  21. package/lib/commonjs/views/NativeStackView.js +15 -10
  22. package/lib/commonjs/views/NativeStackView.js.map +1 -1
  23. package/lib/commonjs/views/NativeStackView.native.js +70 -28
  24. package/lib/commonjs/views/NativeStackView.native.js.map +1 -1
  25. package/lib/module/index.js +5 -0
  26. package/lib/module/index.js.map +1 -1
  27. package/lib/module/navigators/createNativeStackNavigator.js +18 -19
  28. package/lib/module/navigators/createNativeStackNavigator.js.map +1 -1
  29. package/lib/module/types.js.map +1 -1
  30. package/lib/module/utils/useAnimatedHeaderHeight.js +10 -0
  31. package/lib/module/utils/useAnimatedHeaderHeight.js.map +1 -0
  32. package/lib/module/utils/useDismissedRouteError.js +1 -2
  33. package/lib/module/utils/useDismissedRouteError.js.map +1 -1
  34. package/lib/module/utils/useInvalidPreventRemoveError.js +2 -3
  35. package/lib/module/utils/useInvalidPreventRemoveError.js.map +1 -1
  36. package/lib/module/views/DebugContainer.js.map +1 -1
  37. package/lib/module/views/DebugContainer.native.js +1 -1
  38. package/lib/module/views/DebugContainer.native.js.map +1 -1
  39. package/lib/module/views/FontProcessor.js.map +1 -1
  40. package/lib/module/views/FontProcessor.native.js +2 -4
  41. package/lib/module/views/FontProcessor.native.js.map +1 -1
  42. package/lib/module/views/HeaderConfig.js +4 -20
  43. package/lib/module/views/HeaderConfig.js.map +1 -1
  44. package/lib/module/views/NativeStackView.js +13 -8
  45. package/lib/module/views/NativeStackView.js.map +1 -1
  46. package/lib/module/views/NativeStackView.native.js +69 -27
  47. package/lib/module/views/NativeStackView.native.js.map +1 -1
  48. package/lib/typescript/src/index.d.ts +4 -0
  49. package/lib/typescript/src/index.d.ts.map +1 -1
  50. package/lib/typescript/src/navigators/createNativeStackNavigator.d.ts +4 -3
  51. package/lib/typescript/src/navigators/createNativeStackNavigator.d.ts.map +1 -1
  52. package/lib/typescript/src/types.d.ts +8 -4
  53. package/lib/typescript/src/types.d.ts.map +1 -1
  54. package/lib/typescript/src/utils/useAnimatedHeaderHeight.d.ts +5 -0
  55. package/lib/typescript/src/utils/useAnimatedHeaderHeight.d.ts.map +1 -0
  56. package/lib/typescript/src/views/DebugContainer.d.ts +2 -2
  57. package/lib/typescript/src/views/DebugContainer.d.ts.map +1 -1
  58. package/lib/typescript/src/views/DebugContainer.native.d.ts +2 -2
  59. package/lib/typescript/src/views/DebugContainer.native.d.ts.map +1 -1
  60. package/lib/typescript/src/views/FontProcessor.native.d.ts.map +1 -1
  61. package/lib/typescript/src/views/HeaderConfig.d.ts +3 -2
  62. package/lib/typescript/src/views/HeaderConfig.d.ts.map +1 -1
  63. package/lib/typescript/src/views/NativeStackView.d.ts +3 -2
  64. package/lib/typescript/src/views/NativeStackView.d.ts.map +1 -1
  65. package/lib/typescript/src/views/NativeStackView.native.d.ts +3 -2
  66. package/lib/typescript/src/views/NativeStackView.native.d.ts.map +1 -1
  67. package/package.json +14 -15
  68. package/src/index.tsx +5 -0
  69. package/src/navigators/createNativeStackNavigator.tsx +7 -5
  70. package/src/types.tsx +10 -6
  71. package/src/utils/useAnimatedHeaderHeight.tsx +18 -0
  72. package/src/views/DebugContainer.native.tsx +2 -2
  73. package/src/views/DebugContainer.tsx +1 -1
  74. package/src/views/FontProcessor.native.tsx +1 -2
  75. package/src/views/HeaderConfig.tsx +100 -125
  76. package/src/views/NativeStackView.native.tsx +159 -91
  77. package/src/views/NativeStackView.tsx +12 -5
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@react-navigation/native-stack",
3
3
  "description": "Native stack navigator using react-native-screens",
4
- "version": "7.0.0-alpha.4",
4
+ "version": "7.0.0-alpha.6",
5
5
  "keywords": [
6
6
  "react-native-component",
7
7
  "react-component",
@@ -41,27 +41,26 @@
41
41
  "clean": "del lib"
42
42
  },
43
43
  "dependencies": {
44
- "@react-navigation/elements": "^2.0.0-alpha.1",
44
+ "@react-navigation/elements": "^2.0.0-alpha.3",
45
45
  "warn-once": "^0.1.1"
46
46
  },
47
47
  "devDependencies": {
48
- "@react-navigation/native": "^7.0.0-alpha.3",
49
- "@testing-library/react-native": "^11.5.0",
50
- "@types/react": "~18.0.27",
51
- "@types/react-native": "~0.70.8",
52
- "del-cli": "^5.0.0",
48
+ "@react-navigation/native": "^7.0.0-alpha.5",
49
+ "@testing-library/react-native": "^12.3.1",
50
+ "@types/react": "~18.2.33",
51
+ "del-cli": "^5.1.0",
53
52
  "react": "18.2.0",
54
- "react-native": "0.71.8",
55
- "react-native-builder-bob": "^0.21.0",
56
- "react-native-screens": "~3.20.0",
57
- "typescript": "^4.9.4"
53
+ "react-native": "0.72.6",
54
+ "react-native-builder-bob": "^0.23.1",
55
+ "react-native-screens": "~3.22.0",
56
+ "typescript": "^5.2.2"
58
57
  },
59
58
  "peerDependencies": {
60
59
  "@react-navigation/native": "^6.0.0",
61
60
  "react": "*",
62
- "react-native": "*",
63
- "react-native-safe-area-context": ">= 3.0.0",
64
- "react-native-screens": ">= 3.0.0"
61
+ "react-native": "0.72.6",
62
+ "react-native-safe-area-context": "4.6.3",
63
+ "react-native-screens": "~3.22.0"
65
64
  },
66
65
  "react-native-builder-bob": {
67
66
  "source": "src",
@@ -77,5 +76,5 @@
77
76
  ]
78
77
  ]
79
78
  },
80
- "gitHead": "17d212fd04d2c8d000f9fc38ae7ab9e888a0111d"
79
+ "gitHead": "858a8746a5c007a623206c920f70d55935ed39b4"
81
80
  }
package/src/index.tsx CHANGED
@@ -8,6 +8,11 @@ export { createNativeStackNavigator } from './navigators/createNativeStackNaviga
8
8
  */
9
9
  export { NativeStackView } from './views/NativeStackView';
10
10
 
11
+ /**
12
+ * Hooks
13
+ */
14
+ export { useAnimatedHeaderHeight } from './utils/useAnimatedHeaderHeight';
15
+
11
16
  /**
12
17
  * Types
13
18
  */
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  createNavigatorFactory,
3
- EventArg,
4
- ParamListBase,
5
- StackActionHelpers,
3
+ type EventArg,
4
+ type ParamListBase,
5
+ type StackActionHelpers,
6
6
  StackActions,
7
- StackNavigationState,
7
+ type StackNavigationState,
8
8
  StackRouter,
9
- StackRouterOptions,
9
+ type StackRouterOptions,
10
10
  useNavigationBuilder,
11
11
  } from '@react-navigation/native';
12
12
  import * as React from 'react';
@@ -22,6 +22,7 @@ function NativeStackNavigator({
22
22
  id,
23
23
  initialRouteName,
24
24
  children,
25
+ layout,
25
26
  screenListeners,
26
27
  screenOptions,
27
28
  ...rest
@@ -37,6 +38,7 @@ function NativeStackNavigator({
37
38
  id,
38
39
  initialRouteName,
39
40
  children,
41
+ layout,
40
42
  screenListeners,
41
43
  screenOptions,
42
44
  });
package/src/types.tsx CHANGED
@@ -36,7 +36,7 @@ export type NativeStackNavigationEventMap = {
36
36
  export type NativeStackNavigationProp<
37
37
  ParamList extends ParamListBase,
38
38
  RouteName extends keyof ParamList = string,
39
- NavigatorID extends string | undefined = undefined
39
+ NavigatorID extends string | undefined = undefined,
40
40
  > = NavigationProp<
41
41
  ParamList,
42
42
  RouteName,
@@ -50,7 +50,7 @@ export type NativeStackNavigationProp<
50
50
  export type NativeStackScreenProps<
51
51
  ParamList extends ParamListBase,
52
52
  RouteName extends keyof ParamList = string,
53
- NavigatorID extends string | undefined = undefined
53
+ NavigatorID extends string | undefined = undefined,
54
54
  > = {
55
55
  navigation: NativeStackNavigationProp<ParamList, RouteName, NavigatorID>;
56
56
  route: RouteProp<ParamList, RouteName>;
@@ -72,7 +72,11 @@ export type NativeStackHeaderProps = {
72
72
  /**
73
73
  * Title of the previous screen.
74
74
  */
75
- title: string;
75
+ title: string | undefined;
76
+ /**
77
+ * The `href` to use for the anchor tag on web
78
+ */
79
+ href: string | undefined;
76
80
  };
77
81
  /**
78
82
  * Options for the current screen.
@@ -379,7 +383,7 @@ export type NativeStackNavigationOptions = {
379
383
  statusBarTranslucent?: boolean;
380
384
  /**
381
385
  * Sets the direction in which you should swipe to dismiss the screen.
382
- * When using `vertical` option, options `fullScreenGestureEnabled: true`, `customAnimationOnGesture: true` and `animation: 'slide_from_bottom'` are set by default.
386
+ * When using `vertical` option, options `fullScreenGestureEnabled: true`, `animationMatchesGesture: true` and `animation: 'slide_from_bottom'` are set by default.
383
387
  *
384
388
  * Supported values:
385
389
  * - `vertical` – dismiss screen vertically
@@ -399,10 +403,10 @@ export type NativeStackNavigationOptions = {
399
403
  *
400
404
  * @platform ios
401
405
  */
402
- customAnimationOnGesture?: boolean;
406
+ animationMatchesGesture?: boolean;
403
407
  /**
404
408
  * Whether the gesture to dismiss should work on the whole screen. Using gesture to dismiss with this option results in the same
405
- * transition animation as `simple_push`. This behavior can be changed by setting `customAnimationOnGesture` prop. Achieving the
409
+ * transition animation as `simple_push`. This behavior can be changed by setting `animationMatchesGesture` prop. Achieving the
406
410
  * default iOS animation isn't possible due to platform limitations. Defaults to `false`.
407
411
  *
408
412
  * Doesn't affect the behavior of screens presented modally.
@@ -0,0 +1,18 @@
1
+ import * as React from 'react';
2
+ import type { Animated } from 'react-native';
3
+
4
+ export const AnimatedHeaderHeightContext = React.createContext<
5
+ Animated.Value | undefined
6
+ >(undefined);
7
+
8
+ export function useAnimatedHeaderHeight() {
9
+ const animatedValue = React.useContext(AnimatedHeaderHeightContext);
10
+
11
+ if (animatedValue === undefined) {
12
+ throw new Error(
13
+ "Couldn't find the header height. Are you inside a screen in a native stack navigator?"
14
+ );
15
+ }
16
+
17
+ return animatedValue;
18
+ }
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
- import { Platform, View, ViewProps } from 'react-native';
3
- // @ts-ignore Getting private component
2
+ import { Platform, View, type ViewProps } from 'react-native';
3
+ // @ts-expect-error Getting private component
4
4
  import AppContainer from 'react-native/Libraries/ReactNative/AppContainer';
5
5
  import type { StackPresentationTypes } from 'react-native-screens';
6
6
 
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { View, ViewProps } from 'react-native';
2
+ import { View, type ViewProps } from 'react-native';
3
3
  import type { StackPresentationTypes } from 'react-native-screens';
4
4
 
5
5
  type ContainerProps = ViewProps & {
@@ -1,10 +1,9 @@
1
- // @ts-ignore: No declaration available
1
+ // @ts-expect-error importing private module
2
2
  import ReactNativeStyleAttributes from 'react-native/Libraries/Components/View/ReactNativeStyleAttributes';
3
3
 
4
4
  export function processFonts(
5
5
  fontFamilies: (string | undefined)[]
6
6
  ): (string | undefined)[] {
7
- // @ts-ignore: React Native types are incorrect here and don't consider fontFamily a style value
8
7
  const fontFamilyProcessor = ReactNativeStyleAttributes.fontFamily?.process;
9
8
  if (typeof fontFamilyProcessor === 'function') {
10
9
  return fontFamilies.map(fontFamilyProcessor);
@@ -1,7 +1,7 @@
1
1
  import { getHeaderTitle, HeaderTitle } from '@react-navigation/elements';
2
- import { Route, useLocale, useTheme } from '@react-navigation/native';
2
+ import { type Route, useLocale, useTheme } from '@react-navigation/native';
3
3
  import * as React from 'react';
4
- import { Platform, StyleSheet, TextStyle, View } from 'react-native';
4
+ import { Platform, StyleSheet, type TextStyle, View } from 'react-native';
5
5
  import {
6
6
  isSearchBarAvailableForCurrentPlatform,
7
7
  ScreenStackHeaderBackButtonImage,
@@ -24,7 +24,6 @@ type Props = NativeStackNavigationOptions & {
24
24
  };
25
25
 
26
26
  export function HeaderConfig({
27
- headerHeight,
28
27
  headerBackImageSource,
29
28
  headerBackButtonMenuEnabled,
30
29
  headerBackTitle,
@@ -177,118 +176,105 @@ export function HeaderConfig({
177
176
  headerTransparent !== false);
178
177
 
179
178
  return (
180
- <>
181
- {headerBackground != null ? (
182
- <View
183
- style={[
184
- styles.background,
185
- headerTransparent ? styles.translucent : null,
186
- { height: headerHeight },
187
- ]}
188
- >
189
- {headerBackground()}
190
- </View>
191
- ) : null}
192
- <ScreenStackHeaderConfig
193
- backButtonInCustomView={backButtonInCustomView}
194
- backgroundColor={headerBackgroundColor}
195
- backTitle={headerBackTitleVisible ? headerBackTitle : ' '}
196
- backTitleFontFamily={backTitleFontFamily}
197
- backTitleFontSize={backTitleFontSize}
198
- blurEffect={headerBlurEffect}
199
- color={tintColor}
200
- direction={direction}
201
- disableBackButtonMenu={headerBackButtonMenuEnabled === false}
202
- hidden={headerShown === false}
203
- hideBackButton={headerBackVisible === false}
204
- hideShadow={
205
- headerShadowVisible === false ||
206
- headerBackground != null ||
207
- (headerTransparent && headerShadowVisible !== true)
208
- }
209
- largeTitle={headerLargeTitle}
210
- largeTitleBackgroundColor={largeTitleBackgroundColor}
211
- largeTitleColor={largeTitleColor}
212
- largeTitleFontFamily={largeTitleFontFamily}
213
- largeTitleFontSize={largeTitleFontSize}
214
- largeTitleFontWeight={largeTitleFontWeight}
215
- largeTitleHideShadow={headerLargeTitleShadowVisible === false}
216
- title={titleText}
217
- titleColor={titleColor}
218
- titleFontFamily={titleFontFamily}
219
- titleFontSize={titleFontSize}
220
- titleFontWeight={titleFontWeight}
221
- topInsetEnabled={headerTopInsetEnabled}
222
- translucent={
223
- // This defaults to `true`, so we can't pass `undefined`
224
- translucent === true
225
- }
226
- >
227
- {Platform.OS === 'ios' ? (
228
- <>
229
- {headerLeftElement != null ? (
230
- <ScreenStackHeaderLeftView>
179
+ <ScreenStackHeaderConfig
180
+ backButtonInCustomView={backButtonInCustomView}
181
+ backgroundColor={headerBackgroundColor}
182
+ backTitle={headerBackTitleVisible ? headerBackTitle : ' '}
183
+ backTitleFontFamily={backTitleFontFamily}
184
+ backTitleFontSize={backTitleFontSize}
185
+ blurEffect={headerBlurEffect}
186
+ color={tintColor}
187
+ direction={direction}
188
+ disableBackButtonMenu={headerBackButtonMenuEnabled === false}
189
+ hidden={headerShown === false}
190
+ hideBackButton={headerBackVisible === false}
191
+ hideShadow={
192
+ headerShadowVisible === false ||
193
+ headerBackground != null ||
194
+ (headerTransparent && headerShadowVisible !== true)
195
+ }
196
+ largeTitle={headerLargeTitle}
197
+ largeTitleBackgroundColor={largeTitleBackgroundColor}
198
+ largeTitleColor={largeTitleColor}
199
+ largeTitleFontFamily={largeTitleFontFamily}
200
+ largeTitleFontSize={largeTitleFontSize}
201
+ largeTitleFontWeight={largeTitleFontWeight}
202
+ largeTitleHideShadow={headerLargeTitleShadowVisible === false}
203
+ title={titleText}
204
+ titleColor={titleColor}
205
+ titleFontFamily={titleFontFamily}
206
+ titleFontSize={titleFontSize}
207
+ titleFontWeight={titleFontWeight}
208
+ topInsetEnabled={headerTopInsetEnabled}
209
+ translucent={
210
+ // This defaults to `true`, so we can't pass `undefined`
211
+ translucent === true
212
+ }
213
+ >
214
+ {Platform.OS === 'ios' ? (
215
+ <>
216
+ {headerLeftElement != null ? (
217
+ <ScreenStackHeaderLeftView>
218
+ {headerLeftElement}
219
+ </ScreenStackHeaderLeftView>
220
+ ) : null}
221
+ {headerTitleElement != null ? (
222
+ <ScreenStackHeaderCenterView>
223
+ {headerTitleElement}
224
+ </ScreenStackHeaderCenterView>
225
+ ) : null}
226
+ </>
227
+ ) : (
228
+ <>
229
+ {headerLeftElement != null || typeof headerTitle === 'function' ? (
230
+ <ScreenStackHeaderLeftView>
231
+ <View style={styles.row}>
231
232
  {headerLeftElement}
232
- </ScreenStackHeaderLeftView>
233
- ) : null}
234
- {headerTitleElement != null ? (
235
- <ScreenStackHeaderCenterView>
236
- {headerTitleElement}
237
- </ScreenStackHeaderCenterView>
238
- ) : null}
239
- </>
240
- ) : (
241
- <>
242
- {headerLeftElement != null || typeof headerTitle === 'function' ? (
243
- <ScreenStackHeaderLeftView>
244
- <View style={styles.row}>
245
- {headerLeftElement}
246
- {headerTitleAlign !== 'center' ? (
247
- typeof headerTitle === 'function' ? (
248
- headerTitleElement
249
- ) : (
250
- <HeaderTitle
251
- tintColor={tintColor}
252
- style={headerTitleStyleSupported}
253
- >
254
- {titleText}
255
- </HeaderTitle>
256
- )
257
- ) : null}
258
- </View>
259
- </ScreenStackHeaderLeftView>
260
- ) : null}
261
- {headerTitleAlign === 'center' ? (
262
- <ScreenStackHeaderCenterView>
263
- {typeof headerTitle === 'function' ? (
264
- headerTitleElement
265
- ) : (
266
- <HeaderTitle
267
- tintColor={tintColor}
268
- style={headerTitleStyleSupported}
269
- >
270
- {titleText}
271
- </HeaderTitle>
272
- )}
273
- </ScreenStackHeaderCenterView>
274
- ) : null}
275
- </>
276
- )}
277
- {headerBackImageSource !== undefined ? (
278
- <ScreenStackHeaderBackButtonImage source={headerBackImageSource} />
279
- ) : null}
280
- {headerRightElement != null ? (
281
- <ScreenStackHeaderRightView>
282
- {headerRightElement}
283
- </ScreenStackHeaderRightView>
284
- ) : null}
285
- {hasHeaderSearchBar ? (
286
- <ScreenStackHeaderSearchBarView>
287
- <SearchBar {...headerSearchBarOptions} />
288
- </ScreenStackHeaderSearchBarView>
289
- ) : null}
290
- </ScreenStackHeaderConfig>
291
- </>
233
+ {headerTitleAlign !== 'center' ? (
234
+ typeof headerTitle === 'function' ? (
235
+ headerTitleElement
236
+ ) : (
237
+ <HeaderTitle
238
+ tintColor={tintColor}
239
+ style={headerTitleStyleSupported}
240
+ >
241
+ {titleText}
242
+ </HeaderTitle>
243
+ )
244
+ ) : null}
245
+ </View>
246
+ </ScreenStackHeaderLeftView>
247
+ ) : null}
248
+ {headerTitleAlign === 'center' ? (
249
+ <ScreenStackHeaderCenterView>
250
+ {typeof headerTitle === 'function' ? (
251
+ headerTitleElement
252
+ ) : (
253
+ <HeaderTitle
254
+ tintColor={tintColor}
255
+ style={headerTitleStyleSupported}
256
+ >
257
+ {titleText}
258
+ </HeaderTitle>
259
+ )}
260
+ </ScreenStackHeaderCenterView>
261
+ ) : null}
262
+ </>
263
+ )}
264
+ {headerBackImageSource !== undefined ? (
265
+ <ScreenStackHeaderBackButtonImage source={headerBackImageSource} />
266
+ ) : null}
267
+ {headerRightElement != null ? (
268
+ <ScreenStackHeaderRightView>
269
+ {headerRightElement}
270
+ </ScreenStackHeaderRightView>
271
+ ) : null}
272
+ {hasHeaderSearchBar ? (
273
+ <ScreenStackHeaderSearchBarView>
274
+ <SearchBar {...headerSearchBarOptions} />
275
+ </ScreenStackHeaderSearchBarView>
276
+ ) : null}
277
+ </ScreenStackHeaderConfig>
292
278
  );
293
279
  }
294
280
 
@@ -297,15 +283,4 @@ const styles = StyleSheet.create({
297
283
  flexDirection: 'row',
298
284
  alignItems: 'center',
299
285
  },
300
- translucent: {
301
- position: 'absolute',
302
- top: 0,
303
- left: 0,
304
- right: 0,
305
- zIndex: 1,
306
- elevation: 1,
307
- },
308
- background: {
309
- overflow: 'hidden',
310
- },
311
286
  });