@react-navigation/native-stack 6.2.0

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 (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/lib/commonjs/index.js +16 -0
  4. package/lib/commonjs/index.js.map +1 -0
  5. package/lib/commonjs/navigators/createNativeStackNavigator.js +67 -0
  6. package/lib/commonjs/navigators/createNativeStackNavigator.js.map +1 -0
  7. package/lib/commonjs/types.js +6 -0
  8. package/lib/commonjs/types.js.map +1 -0
  9. package/lib/commonjs/views/DebugContainer.js +24 -0
  10. package/lib/commonjs/views/DebugContainer.js.map +1 -0
  11. package/lib/commonjs/views/DebugContainer.native.js +43 -0
  12. package/lib/commonjs/views/DebugContainer.native.js.map +1 -0
  13. package/lib/commonjs/views/FontProcessor.js +11 -0
  14. package/lib/commonjs/views/FontProcessor.js.map +1 -0
  15. package/lib/commonjs/views/FontProcessor.native.js +25 -0
  16. package/lib/commonjs/views/FontProcessor.native.js.map +1 -0
  17. package/lib/commonjs/views/HeaderConfig.js +157 -0
  18. package/lib/commonjs/views/HeaderConfig.js.map +1 -0
  19. package/lib/commonjs/views/NativeStackView.js +133 -0
  20. package/lib/commonjs/views/NativeStackView.js.map +1 -0
  21. package/lib/commonjs/views/NativeStackView.native.js +247 -0
  22. package/lib/commonjs/views/NativeStackView.native.js.map +1 -0
  23. package/lib/module/index.js +8 -0
  24. package/lib/module/index.js.map +1 -0
  25. package/lib/module/navigators/createNativeStackNavigator.js +50 -0
  26. package/lib/module/navigators/createNativeStackNavigator.js.map +1 -0
  27. package/lib/module/types.js +2 -0
  28. package/lib/module/types.js.map +1 -0
  29. package/lib/module/views/DebugContainer.js +11 -0
  30. package/lib/module/views/DebugContainer.js.map +1 -0
  31. package/lib/module/views/DebugContainer.native.js +26 -0
  32. package/lib/module/views/DebugContainer.native.js.map +1 -0
  33. package/lib/module/views/FontProcessor.js +4 -0
  34. package/lib/module/views/FontProcessor.js.map +1 -0
  35. package/lib/module/views/FontProcessor.native.js +15 -0
  36. package/lib/module/views/FontProcessor.native.js.map +1 -0
  37. package/lib/module/views/HeaderConfig.js +138 -0
  38. package/lib/module/views/HeaderConfig.js.map +1 -0
  39. package/lib/module/views/NativeStackView.js +118 -0
  40. package/lib/module/views/NativeStackView.js.map +1 -0
  41. package/lib/module/views/NativeStackView.native.js +224 -0
  42. package/lib/module/views/NativeStackView.native.js.map +1 -0
  43. package/lib/typescript/src/index.d.ts +8 -0
  44. package/lib/typescript/src/navigators/createNativeStackNavigator.d.ts +6 -0
  45. package/lib/typescript/src/types.d.ts +373 -0
  46. package/lib/typescript/src/views/DebugContainer.d.ts +9 -0
  47. package/lib/typescript/src/views/DebugContainer.native.d.ts +9 -0
  48. package/lib/typescript/src/views/FontProcessor.d.ts +1 -0
  49. package/lib/typescript/src/views/FontProcessor.native.d.ts +1 -0
  50. package/lib/typescript/src/views/HeaderConfig.d.ts +9 -0
  51. package/lib/typescript/src/views/NativeStackView.d.ts +10 -0
  52. package/lib/typescript/src/views/NativeStackView.native.d.ts +10 -0
  53. package/package.json +80 -0
  54. package/src/index.tsx +14 -0
  55. package/src/navigators/createNativeStackNavigator.tsx +81 -0
  56. package/src/types.tsx +425 -0
  57. package/src/views/DebugContainer.native.tsx +33 -0
  58. package/src/views/DebugContainer.tsx +14 -0
  59. package/src/views/FontProcessor.native.tsx +13 -0
  60. package/src/views/FontProcessor.tsx +5 -0
  61. package/src/views/HeaderConfig.tsx +234 -0
  62. package/src/views/NativeStackView.native.tsx +331 -0
  63. package/src/views/NativeStackView.tsx +173 -0
@@ -0,0 +1,373 @@
1
+ /// <reference types="react" />
2
+ import type { DefaultNavigatorOptions, Descriptor, NavigationHelpers, NavigationProp, ParamListBase, Route, RouteProp, StackActionHelpers, StackNavigationState, StackRouterOptions } from '@react-navigation/native';
3
+ import type { ImageSourcePropType, StyleProp, TextStyle, ViewStyle } from 'react-native';
4
+ import type { ScreenProps, ScreenStackHeaderConfigProps, SearchBarProps } from 'react-native-screens';
5
+ export declare type NativeStackNavigationEventMap = {
6
+ /**
7
+ * Event which fires when a transition animation starts.
8
+ */
9
+ transitionStart: {
10
+ data: {
11
+ closing: boolean;
12
+ };
13
+ };
14
+ /**
15
+ * Event which fires when a transition animation ends.
16
+ */
17
+ transitionEnd: {
18
+ data: {
19
+ closing: boolean;
20
+ };
21
+ };
22
+ };
23
+ export declare type NativeStackNavigationProp<ParamList extends ParamListBase, RouteName extends keyof ParamList = string> = NavigationProp<ParamList, RouteName, StackNavigationState<ParamList>, NativeStackNavigationOptions, NativeStackNavigationEventMap> & StackActionHelpers<ParamList>;
24
+ export declare type NativeStackScreenProps<ParamList extends ParamListBase, RouteName extends keyof ParamList = string> = {
25
+ navigation: NativeStackNavigationProp<ParamList, RouteName>;
26
+ route: RouteProp<ParamList, RouteName>;
27
+ };
28
+ export declare type NativeStackNavigationHelpers = NavigationHelpers<ParamListBase, NativeStackNavigationEventMap>;
29
+ export declare type NativeStackNavigationConfig = {};
30
+ export declare type NativeStackHeaderProps = {
31
+ /**
32
+ * Options for the back button.
33
+ */
34
+ back?: {
35
+ /**
36
+ * Title of the previous screen.
37
+ */
38
+ title: string;
39
+ };
40
+ /**
41
+ * Options for the current screen.
42
+ */
43
+ options: NativeStackNavigationOptions;
44
+ /**
45
+ * Route object for the current screen.
46
+ */
47
+ route: Route<string>;
48
+ /**
49
+ * Navigation prop for the header.
50
+ */
51
+ navigation: NativeStackNavigationProp<ParamListBase>;
52
+ };
53
+ export declare type HeaderBackButtonProps = {
54
+ /**
55
+ * Tint color for the header.
56
+ */
57
+ tintColor?: string;
58
+ /**
59
+ * Label text for the button. Usually the title of the previous screen.
60
+ * By default, this is only shown on iOS.
61
+ */
62
+ label?: string;
63
+ /**
64
+ * Whether it's possible to navigate back in stack.
65
+ */
66
+ canGoBack: boolean;
67
+ };
68
+ export declare type NativeStackNavigationOptions = {
69
+ /**
70
+ * String that can be displayed in the header as a fallback for `headerTitle`.
71
+ */
72
+ title?: string;
73
+ /**
74
+ * Function that given `HeaderProps` returns a React Element to display as a header.
75
+ */
76
+ header?: (props: NativeStackHeaderProps) => React.ReactNode;
77
+ /**
78
+ * Whether the back button is visible in the header.
79
+ * You can use it to show a back button alongside `headerLeft` if you have specified it.
80
+ *
81
+ * This will have no effect on the first screen in the stack.
82
+ *
83
+ * Only supported on iOS.
84
+ *
85
+ * @platform ios
86
+ */
87
+ headerBackVisible?: boolean;
88
+ /**
89
+ * Title string used by the back button on iOS.
90
+ * Defaults to the previous scene's title, or "Back" if there's not enough space.
91
+ * Use `headerBackTitleVisible: false` to hide it.
92
+ *
93
+ * Only supported on iOS.
94
+ *
95
+ * @platform ios
96
+ */
97
+ headerBackTitle?: string;
98
+ /**
99
+ * Whether the back button title should be visible or not.
100
+ *
101
+ * Only supported on iOS.
102
+ *
103
+ * @platform ios
104
+ */
105
+ headerBackTitleVisible?: boolean;
106
+ /**
107
+ * Style object for header back title. Supported properties:
108
+ * - fontFamily
109
+ * - fontSize
110
+ *
111
+ * Only supported on iOS.
112
+ *
113
+ * @platform ios
114
+ */
115
+ headerBackTitleStyle?: StyleProp<{
116
+ fontFamily?: string;
117
+ fontSize?: number;
118
+ }>;
119
+ /**
120
+ * Image to display in the header as the icon in the back button.
121
+ * Defaults to back icon image for the platform
122
+ * - A chevron on iOS
123
+ * - An arrow on Android
124
+ */
125
+ headerBackImageSource?: ImageSourcePropType;
126
+ /**
127
+ * Style of the header when a large title is shown.
128
+ * The large title is shown if `headerLargeTitle` is `true` and
129
+ * the edge of any scrollable content reaches the matching edge of the header.
130
+ *
131
+ * Supported properties:
132
+ * - backgroundColor
133
+ *
134
+ * Only supported on iOS.
135
+ *
136
+ * @platform ios
137
+ */
138
+ headerLargeStyle?: StyleProp<{
139
+ backgroundColor?: string;
140
+ }>;
141
+ /**
142
+ * Whether to enable header with large title which collapses to regular header on scroll.
143
+ *
144
+ * For large title to collapse on scroll, the content of the screen should be wrapped in a scrollable view such as `ScrollView` or `FlatList`.
145
+ * If the scrollable area doesn't fill the screen, the large title won't collapse on scroll.
146
+ *
147
+ * Only supported on iOS.
148
+ *
149
+ * @platform ios
150
+ */
151
+ headerLargeTitle?: boolean;
152
+ /**
153
+ * Whether drop shadow of header is visible when a large title is shown.
154
+ *
155
+ * Only supported on iOS.
156
+ *
157
+ * @platform ios
158
+ */
159
+ headerLargeTitleShadowVisible?: boolean;
160
+ /**
161
+ * Style object for large title in header. Supported properties:
162
+ * - fontFamily
163
+ * - fontSize
164
+ * - fontWeight
165
+ * - color
166
+ *
167
+ * Only supported on iOS.
168
+ *
169
+ * @platform ios
170
+ */
171
+ headerLargeTitleStyle?: StyleProp<{
172
+ fontFamily?: string;
173
+ fontSize?: number;
174
+ fontWeight?: string;
175
+ color?: string;
176
+ }>;
177
+ /**
178
+ * Whether to show the header. The header is shown by default.
179
+ * Setting this to `false` hides the header.
180
+ */
181
+ headerShown?: boolean;
182
+ /**
183
+ * Style object for header. Supported properties:
184
+ * - backgroundColor
185
+ */
186
+ headerStyle?: StyleProp<{
187
+ backgroundColor?: string;
188
+ }>;
189
+ /**
190
+ * Whether to hide the elevation shadow (Android) or the bottom border (iOS) on the header.
191
+ */
192
+ headerShadowVisible?: boolean;
193
+ /**
194
+ * Boolean indicating whether the navigation bar is translucent.
195
+ * Setting this to `true` makes the header absolutely positioned,
196
+ * and changes the background color to `transparent` unless specified in `headerStyle`.
197
+ */
198
+ headerTransparent?: boolean;
199
+ /**
200
+ * Blur effect for the translucent header.
201
+ * The `headerTransparent` option needs to be set to `true` for this to work.
202
+ *
203
+ * Only supported on iOS.
204
+ *
205
+ * @platform ios
206
+ */
207
+ headerBlurEffect?: ScreenStackHeaderConfigProps['blurEffect'];
208
+ /**
209
+ * Tint color for the header. Changes the color of back button and title.
210
+ */
211
+ headerTintColor?: string;
212
+ /**
213
+ * Function which returns a React Element to display on the left side of the header.
214
+ * This replaces the back button. See `headerBackVisible` to show the back button along side left element.
215
+ */
216
+ headerLeft?: (props: HeaderBackButtonProps) => React.ReactNode;
217
+ /**
218
+ * Function which returns a React Element to display on the right side of the header.
219
+ */
220
+ headerRight?: (props: {
221
+ tintColor?: string;
222
+ }) => React.ReactNode;
223
+ /**
224
+ * String or a function that returns a React Element to be used by the header.
225
+ * Defaults to screen `title` or route name.
226
+ *
227
+ * When a function is passed, it receives `tintColor` and`children` in the options object as an argument.
228
+ * The title string is passed in `children`.
229
+ *
230
+ * Note that if you render a custom element by passing a function, animations for the title won't work.
231
+ */
232
+ headerTitle?: string | ((props: {
233
+ /**
234
+ * The title text of the header.
235
+ */
236
+ children: string;
237
+ /**
238
+ * Tint color for the header.
239
+ */
240
+ tintColor?: string;
241
+ }) => React.ReactNode);
242
+ /**
243
+ * How to align the the header title.
244
+ * Defaults to `left` on platforms other than iOS.
245
+ *
246
+ * Not supported on iOS. It's always `center` on iOS and cannot be changed.
247
+ */
248
+ headerTitleAlign?: 'left' | 'center';
249
+ /**
250
+ * Style object for header title. Supported properties:
251
+ * - fontFamily
252
+ * - fontSize
253
+ * - fontWeight
254
+ * - color
255
+ */
256
+ headerTitleStyle?: StyleProp<Pick<TextStyle, 'fontFamily' | 'fontSize' | 'fontWeight'> & {
257
+ color?: string;
258
+ }>;
259
+ /**
260
+ * Options to render a native search bar on iOS.
261
+ *
262
+ * @platform ios
263
+ */
264
+ headerSearchBarOptions?: SearchBarProps;
265
+ /**
266
+ * Boolean indicating whether to show the menu on longPress of iOS >= 14 back button. Defaults to `true`.
267
+ * Requires `react-native-screens` version >=3.3.0.
268
+ *
269
+ * Only supported on iOS.
270
+ *
271
+ * @platform ios
272
+ */
273
+ headerBackButtonMenuEnabled?: boolean;
274
+ /**
275
+ * Sets the status bar animation (similar to the `StatusBar` component).
276
+ * Requires setting `View controller-based status bar appearance -> YES` (or removing the config) in your `Info.plist` file.
277
+ *
278
+ * Only supported on iOS.
279
+ *
280
+ * @platform ios
281
+ */
282
+ statusBarAnimation?: ScreenProps['statusBarAnimation'];
283
+ /**
284
+ * Whether the status bar should be hidden on this screen.
285
+ * Requires setting `View controller-based status bar appearance -> YES` in your Info.plist file.
286
+ *
287
+ * Only supported on iOS.
288
+ *
289
+ * @platform ios
290
+ */
291
+ statusBarHidden?: boolean;
292
+ /**
293
+ * Sets the status bar color (similar to the `StatusBar` component).
294
+ * Requires setting `View controller-based status bar appearance -> YES` (or removing the config) in your `Info.plist` file.
295
+ *
296
+ * Only supported on iOS.
297
+ *
298
+ * @platform ios
299
+ */
300
+ statusBarStyle?: ScreenProps['statusBarStyle'];
301
+ /**
302
+ * Style object for the scene content.
303
+ */
304
+ contentStyle?: StyleProp<ViewStyle>;
305
+ /**
306
+ * Whether you can use gestures to dismiss this screen. Defaults to `true`.
307
+ *
308
+ * Only supported on iOS.
309
+ *
310
+ * @platform ios
311
+ */
312
+ gestureEnabled?: boolean;
313
+ /**
314
+ * The type of animation to use when this screen replaces another screen. Defaults to `pop`.
315
+ *
316
+ * Supported values:
317
+ * - "push": the new screen will perform push animation.
318
+ * - "pop": the new screen will perform pop animation.
319
+ *
320
+ * Only supported on iOS and Android.
321
+ */
322
+ animationTypeForReplace?: ScreenProps['replaceAnimation'];
323
+ /**
324
+ * How the screen should animate when pushed or popped.
325
+ *
326
+ * Supported values:
327
+ * - "default": use the platform default animation
328
+ * - "fade": fade screen in or out
329
+ * - "flip": flip the screen, requires stackPresentation: "modal" (iOS only)
330
+ * - "slide_from_right": slide in the new screen from right (Android only, uses default animation on iOS)
331
+ * - "slide_from_left": slide in the new screen from left (Android only, uses default animation on iOS)
332
+ * - "none": don't animate the screen
333
+ *
334
+ * Only supported on iOS and Android.
335
+ */
336
+ animation?: ScreenProps['stackAnimation'];
337
+ /**
338
+ * How should the screen be presented.
339
+ *
340
+ * Supported values:
341
+ * - "card": the new screen will be pushed onto a stack, which means the default animation will be slide from the side on iOS, the animation on Android will vary depending on the OS version and theme.
342
+ * - "modal": the new screen will be presented modally. this also allows for a nested stack to be rendered inside the screen.
343
+ * - "transparentModal": the new screen will be presented modally, but in addition, the previous screen will stay so that the content below can still be seen if the screen has translucent background.
344
+ * - "containedModal": will use "UIModalPresentationCurrentContext" modal style on iOS and will fallback to "modal" on Android.
345
+ * - "containedTransparentModal": will use "UIModalPresentationOverCurrentContext" modal style on iOS and will fallback to "transparentModal" on Android.
346
+ * - "fullScreenModal": will use "UIModalPresentationFullScreen" modal style on iOS and will fallback to "modal" on Android.
347
+ * - "formSheet": will use "UIModalPresentationFormSheet" modal style on iOS and will fallback to "modal" on Android.
348
+ *
349
+ * Only supported on iOS and Android.
350
+ */
351
+ presentation?: Exclude<ScreenProps['stackPresentation'], 'push'> | 'card';
352
+ /**
353
+ * The display orientation to use for the screen.
354
+ *
355
+ * Supported values:
356
+ * - "default" - resolves to "all" without "portrait_down" on iOS. On Android, this lets the system decide the best orientation.
357
+ * - "all": all orientations are permitted.
358
+ * - "portrait": portrait orientations are permitted.
359
+ * - "portrait_up": right-side portrait orientation is permitted.
360
+ * - "portrait_down": upside-down portrait orientation is permitted.
361
+ * - "landscape": landscape orientations are permitted.
362
+ * - "landscape_left": landscape-left orientation is permitted.
363
+ * - "landscape_right": landscape-right orientation is permitted.
364
+ *
365
+ * Only supported on iOS and Android.
366
+ */
367
+ orientation?: ScreenProps['screenOrientation'];
368
+ };
369
+ export declare type NativeStackNavigatorProps = DefaultNavigatorOptions<ParamListBase, StackNavigationState<ParamListBase>, NativeStackNavigationOptions, NativeStackNavigationEventMap> & StackRouterOptions & NativeStackNavigationConfig;
370
+ export declare type NativeStackDescriptor = Descriptor<NativeStackNavigationOptions, NativeStackNavigationProp<ParamListBase>, RouteProp<ParamListBase>>;
371
+ export declare type NativeStackDescriptorMap = {
372
+ [key: string]: NativeStackDescriptor;
373
+ };
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ import { ViewProps } from 'react-native';
3
+ import type { StackPresentationTypes } from 'react-native-screens';
4
+ declare type ContainerProps = ViewProps & {
5
+ stackPresentation: StackPresentationTypes;
6
+ children: React.ReactNode;
7
+ };
8
+ export default function Container(props: ContainerProps): JSX.Element;
9
+ export {};
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ import { ViewProps } from 'react-native';
3
+ import type { StackPresentationTypes } from 'react-native-screens';
4
+ declare type ContainerProps = ViewProps & {
5
+ stackPresentation: StackPresentationTypes;
6
+ children: React.ReactNode;
7
+ };
8
+ declare let Container: React.ComponentType<ContainerProps>;
9
+ export default Container;
@@ -0,0 +1 @@
1
+ export declare function processFonts(_: (string | undefined)[]): (string | undefined)[];
@@ -0,0 +1 @@
1
+ export declare function processFonts(fontFamilies: (string | undefined)[]): (string | undefined)[];
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { Route } from '@react-navigation/native';
3
+ import type { NativeStackNavigationOptions } from '../types';
4
+ declare type Props = NativeStackNavigationOptions & {
5
+ route: Route<string>;
6
+ canGoBack: boolean;
7
+ };
8
+ export default function HeaderConfig({ headerBackImageSource, headerBackButtonMenuEnabled, headerBackTitle, headerBackTitleStyle, headerBackTitleVisible, headerBackVisible, headerShadowVisible, headerLargeStyle, headerLargeTitle, headerLargeTitleShadowVisible, headerLargeTitleStyle, headerLeft, headerRight, headerShown, headerStyle, headerBlurEffect, headerTintColor, headerTitle, headerTitleAlign, headerTitleStyle, headerTransparent, headerSearchBarOptions, route, title, canGoBack, }: Props): JSX.Element;
9
+ export {};
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import type { ParamListBase, StackNavigationState } from '@react-navigation/native';
3
+ import type { NativeStackDescriptorMap, NativeStackNavigationHelpers } from '../types';
4
+ declare type Props = {
5
+ state: StackNavigationState<ParamListBase>;
6
+ navigation: NativeStackNavigationHelpers;
7
+ descriptors: NativeStackDescriptorMap;
8
+ };
9
+ export default function NativeStackView({ state, descriptors }: Props): JSX.Element;
10
+ export {};
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { ParamListBase, StackNavigationState } from '@react-navigation/native';
3
+ import type { NativeStackDescriptorMap, NativeStackNavigationHelpers } from '../types';
4
+ declare type Props = {
5
+ state: StackNavigationState<ParamListBase>;
6
+ navigation: NativeStackNavigationHelpers;
7
+ descriptors: NativeStackDescriptorMap;
8
+ };
9
+ export default function NativeStackView(props: Props): JSX.Element;
10
+ export {};
package/package.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "@react-navigation/native-stack",
3
+ "description": "Native stack navigator using react-native-screens",
4
+ "version": "6.2.0",
5
+ "keywords": [
6
+ "react-native-component",
7
+ "react-component",
8
+ "react-native",
9
+ "react-navigation",
10
+ "ios",
11
+ "android",
12
+ "native",
13
+ "stack"
14
+ ],
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/react-navigation/react-navigation.git",
19
+ "directory": "packages/native-stack"
20
+ },
21
+ "bugs": {
22
+ "url": "https://github.com/software-mansion/react-native-screens/issues"
23
+ },
24
+ "homepage": "https://github.com/software-mansion/react-native-screens#readme",
25
+ "main": "lib/commonjs/index.js",
26
+ "react-native": "src/index.tsx",
27
+ "source": "src/index.tsx",
28
+ "module": "lib/module/index.js",
29
+ "types": "lib/typescript/src/index.d.ts",
30
+ "files": [
31
+ "src",
32
+ "lib",
33
+ "!**/__tests__"
34
+ ],
35
+ "sideEffects": false,
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "scripts": {
40
+ "prepare": "bob build",
41
+ "clean": "del lib"
42
+ },
43
+ "dependencies": {
44
+ "@react-navigation/elements": "^1.1.1",
45
+ "warn-once": "^0.1.0"
46
+ },
47
+ "devDependencies": {
48
+ "@react-navigation/native": "^6.0.3",
49
+ "@testing-library/react-native": "^7.2.0",
50
+ "@types/react": "^17.0.9",
51
+ "@types/react-native": "~0.64.9",
52
+ "react": "~16.13.1",
53
+ "react-native": "~0.63.4",
54
+ "react-native-builder-bob": "^0.18.1",
55
+ "react-native-screens": "^3.3.0",
56
+ "typescript": "^4.3.2"
57
+ },
58
+ "peerDependencies": {
59
+ "@react-navigation/native": "^6.0.0",
60
+ "react": "*",
61
+ "react-native": "*",
62
+ "react-native-safe-area-context": ">= 3.0.0",
63
+ "react-native-screens": ">= 3.0.0"
64
+ },
65
+ "react-native-builder-bob": {
66
+ "source": "src",
67
+ "output": "lib",
68
+ "targets": [
69
+ "commonjs",
70
+ "module",
71
+ [
72
+ "typescript",
73
+ {
74
+ "project": "tsconfig.build.json"
75
+ }
76
+ ]
77
+ ]
78
+ },
79
+ "gitHead": "38ac69f17ee314f96d3d4bcee02349fa4a02d422"
80
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Navigators
3
+ */
4
+ export { default as createNativeStackNavigator } from './navigators/createNativeStackNavigator';
5
+
6
+ /**
7
+ * Types
8
+ */
9
+ export type {
10
+ NativeStackHeaderProps,
11
+ NativeStackNavigationOptions,
12
+ NativeStackNavigationProp,
13
+ NativeStackScreenProps,
14
+ } from './types';
@@ -0,0 +1,81 @@
1
+ import {
2
+ createNavigatorFactory,
3
+ EventArg,
4
+ ParamListBase,
5
+ StackActionHelpers,
6
+ StackActions,
7
+ StackNavigationState,
8
+ StackRouter,
9
+ StackRouterOptions,
10
+ useNavigationBuilder,
11
+ } from '@react-navigation/native';
12
+ import * as React from 'react';
13
+
14
+ import type {
15
+ NativeStackNavigationEventMap,
16
+ NativeStackNavigationOptions,
17
+ NativeStackNavigatorProps,
18
+ } from '../types';
19
+ import NativeStackView from '../views/NativeStackView';
20
+
21
+ function NativeStackNavigator({
22
+ initialRouteName,
23
+ children,
24
+ screenListeners,
25
+ screenOptions,
26
+ ...rest
27
+ }: NativeStackNavigatorProps) {
28
+ const { state, descriptors, navigation } = useNavigationBuilder<
29
+ StackNavigationState<ParamListBase>,
30
+ StackRouterOptions,
31
+ StackActionHelpers<ParamListBase>,
32
+ NativeStackNavigationOptions,
33
+ NativeStackNavigationEventMap
34
+ >(StackRouter, {
35
+ initialRouteName,
36
+ children,
37
+ screenListeners,
38
+ screenOptions,
39
+ });
40
+
41
+ React.useEffect(
42
+ () =>
43
+ navigation?.addListener?.('tabPress', (e: any) => {
44
+ const isFocused = navigation.isFocused();
45
+
46
+ // Run the operation in the next frame so we're sure all listeners have been run
47
+ // This is necessary to know if preventDefault() has been called
48
+ requestAnimationFrame(() => {
49
+ if (
50
+ state.index > 0 &&
51
+ isFocused &&
52
+ !(e as EventArg<'tabPress', true>).defaultPrevented
53
+ ) {
54
+ // When user taps on already focused tab and we're inside the tab,
55
+ // reset the stack to replicate native behaviour
56
+ navigation.dispatch({
57
+ ...StackActions.popToTop(),
58
+ target: state.key,
59
+ });
60
+ }
61
+ });
62
+ }),
63
+ [navigation, state.index, state.key]
64
+ );
65
+
66
+ return (
67
+ <NativeStackView
68
+ {...rest}
69
+ state={state}
70
+ navigation={navigation}
71
+ descriptors={descriptors}
72
+ />
73
+ );
74
+ }
75
+
76
+ export default createNavigatorFactory<
77
+ StackNavigationState<ParamListBase>,
78
+ NativeStackNavigationOptions,
79
+ NativeStackNavigationEventMap,
80
+ typeof NativeStackNavigator
81
+ >(NativeStackNavigator);