@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,173 @@
1
+ import {
2
+ getHeaderTitle,
3
+ Header,
4
+ HeaderBackButton,
5
+ SafeAreaProviderCompat,
6
+ Screen,
7
+ } from '@react-navigation/elements';
8
+ import type {
9
+ ParamListBase,
10
+ StackNavigationState,
11
+ } from '@react-navigation/native';
12
+ import * as React from 'react';
13
+ import { Image, StyleSheet, View } from 'react-native';
14
+
15
+ import type {
16
+ NativeStackDescriptorMap,
17
+ NativeStackNavigationHelpers,
18
+ } from '../types';
19
+
20
+ type Props = {
21
+ state: StackNavigationState<ParamListBase>;
22
+ // This is used for the native implementation of the stack.
23
+ // eslint-disable-next-line react/no-unused-prop-types
24
+ navigation: NativeStackNavigationHelpers;
25
+ descriptors: NativeStackDescriptorMap;
26
+ };
27
+
28
+ export default function NativeStackView({ state, descriptors }: Props) {
29
+ return (
30
+ <SafeAreaProviderCompat>
31
+ <View style={styles.container}>
32
+ {state.routes.map((route, i) => {
33
+ const isFocused = state.index === i;
34
+ const canGoBack = i !== 0;
35
+ const previousKey = state.routes[i - 1]?.key;
36
+ const previousDescriptor = previousKey
37
+ ? descriptors[previousKey]
38
+ : undefined;
39
+ const { options, navigation, render } = descriptors[route.key];
40
+
41
+ const {
42
+ header,
43
+ headerShown,
44
+ headerTintColor,
45
+ headerBackImageSource,
46
+ headerLeft,
47
+ headerRight,
48
+ headerTitle,
49
+ headerTitleAlign,
50
+ headerTitleStyle,
51
+ headerStyle,
52
+ headerShadowVisible,
53
+ headerTransparent,
54
+ contentStyle,
55
+ headerBackTitle,
56
+ } = options;
57
+
58
+ return (
59
+ <Screen
60
+ key={route.key}
61
+ focused={isFocused}
62
+ route={route}
63
+ navigation={navigation}
64
+ headerShown={headerShown}
65
+ headerTransparent={headerTransparent}
66
+ header={
67
+ header !== undefined ? (
68
+ header({
69
+ back: previousDescriptor
70
+ ? {
71
+ title: getHeaderTitle(
72
+ previousDescriptor.options,
73
+ previousDescriptor.route.name
74
+ ),
75
+ }
76
+ : undefined,
77
+ options,
78
+ route,
79
+ navigation,
80
+ })
81
+ ) : (
82
+ <Header
83
+ title={getHeaderTitle(options, route.name)}
84
+ headerTintColor={headerTintColor}
85
+ headerLeft={
86
+ typeof headerLeft === 'function'
87
+ ? ({ tintColor }) =>
88
+ headerLeft({
89
+ tintColor,
90
+ canGoBack,
91
+ label: headerBackTitle,
92
+ })
93
+ : headerLeft === undefined && canGoBack
94
+ ? ({ tintColor }) => (
95
+ <HeaderBackButton
96
+ tintColor={tintColor}
97
+ backImage={
98
+ headerBackImageSource !== undefined
99
+ ? () => (
100
+ <Image
101
+ source={headerBackImageSource}
102
+ style={[
103
+ styles.backImage,
104
+ { tintColor },
105
+ ]}
106
+ />
107
+ )
108
+ : undefined
109
+ }
110
+ onPress={navigation.goBack}
111
+ canGoBack={canGoBack}
112
+ />
113
+ )
114
+ : headerLeft
115
+ }
116
+ headerRight={
117
+ typeof headerRight === 'function'
118
+ ? ({ tintColor }) => headerRight({ tintColor })
119
+ : headerRight
120
+ }
121
+ headerTitle={
122
+ typeof headerTitle === 'function'
123
+ ? ({ children, tintColor }) =>
124
+ headerTitle({ children, tintColor })
125
+ : headerTitle
126
+ }
127
+ headerTitleAlign={headerTitleAlign}
128
+ headerTitleStyle={headerTitleStyle}
129
+ headerStyle={[
130
+ headerTransparent
131
+ ? {
132
+ position: 'absolute',
133
+ backgroundColor: 'transparent',
134
+ }
135
+ : null,
136
+ headerStyle,
137
+ headerShadowVisible === false
138
+ ? { shadowOpacity: 0, borderBottomWidth: 0 }
139
+ : null,
140
+ ]}
141
+ />
142
+ )
143
+ }
144
+ style={[
145
+ StyleSheet.absoluteFill,
146
+ { display: isFocused ? 'flex' : 'none' },
147
+ ]}
148
+ >
149
+ <View style={[styles.contentContainer, contentStyle]}>
150
+ {render()}
151
+ </View>
152
+ </Screen>
153
+ );
154
+ })}
155
+ </View>
156
+ </SafeAreaProviderCompat>
157
+ );
158
+ }
159
+
160
+ const styles = StyleSheet.create({
161
+ container: {
162
+ flex: 1,
163
+ },
164
+ contentContainer: {
165
+ flex: 1,
166
+ },
167
+ backImage: {
168
+ height: 24,
169
+ width: 24,
170
+ margin: 3,
171
+ resizeMode: 'contain',
172
+ },
173
+ });