@react-navigation/elements 1.1.1

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 (177) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/lib/commonjs/Background.js +34 -0
  4. package/lib/commonjs/Background.js.map +1 -0
  5. package/lib/commonjs/Header/Header.js +250 -0
  6. package/lib/commonjs/Header/Header.js.map +1 -0
  7. package/lib/commonjs/Header/HeaderBackButton.js +222 -0
  8. package/lib/commonjs/Header/HeaderBackButton.js.map +1 -0
  9. package/lib/commonjs/Header/HeaderBackContext.js +15 -0
  10. package/lib/commonjs/Header/HeaderBackContext.js.map +1 -0
  11. package/lib/commonjs/Header/HeaderBackground.js +57 -0
  12. package/lib/commonjs/Header/HeaderBackground.js.map +1 -0
  13. package/lib/commonjs/Header/HeaderHeightContext.js +15 -0
  14. package/lib/commonjs/Header/HeaderHeightContext.js.map +1 -0
  15. package/lib/commonjs/Header/HeaderShownContext.js +15 -0
  16. package/lib/commonjs/Header/HeaderShownContext.js.map +1 -0
  17. package/lib/commonjs/Header/HeaderTitle.js +56 -0
  18. package/lib/commonjs/Header/HeaderTitle.js.map +1 -0
  19. package/lib/commonjs/Header/getDefaultHeaderHeight.js +40 -0
  20. package/lib/commonjs/Header/getDefaultHeaderHeight.js.map +1 -0
  21. package/lib/commonjs/Header/getHeaderTitle.js +11 -0
  22. package/lib/commonjs/Header/getHeaderTitle.js.map +1 -0
  23. package/lib/commonjs/Header/useHeaderHeight.js +27 -0
  24. package/lib/commonjs/Header/useHeaderHeight.js.map +1 -0
  25. package/lib/commonjs/MaskedView.android.js +16 -0
  26. package/lib/commonjs/MaskedView.android.js.map +1 -0
  27. package/lib/commonjs/MaskedView.ios.js +16 -0
  28. package/lib/commonjs/MaskedView.ios.js.map +1 -0
  29. package/lib/commonjs/MaskedView.js +16 -0
  30. package/lib/commonjs/MaskedView.js.map +1 -0
  31. package/lib/commonjs/MaskedViewNative.js +40 -0
  32. package/lib/commonjs/MaskedViewNative.js.map +1 -0
  33. package/lib/commonjs/MissingIcon.js +34 -0
  34. package/lib/commonjs/MissingIcon.js.map +1 -0
  35. package/lib/commonjs/PlatformPressable.js +77 -0
  36. package/lib/commonjs/PlatformPressable.js.map +1 -0
  37. package/lib/commonjs/ResourceSavingView.js +64 -0
  38. package/lib/commonjs/ResourceSavingView.js.map +1 -0
  39. package/lib/commonjs/SafeAreaProviderCompat.js +69 -0
  40. package/lib/commonjs/SafeAreaProviderCompat.js.map +1 -0
  41. package/lib/commonjs/Screen.js +89 -0
  42. package/lib/commonjs/Screen.js.map +1 -0
  43. package/lib/commonjs/assets/back-icon-mask.png +0 -0
  44. package/lib/commonjs/assets/back-icon.png +0 -0
  45. package/lib/commonjs/assets/back-icon@1.5x.android.png +0 -0
  46. package/lib/commonjs/assets/back-icon@1.5x.ios.png +0 -0
  47. package/lib/commonjs/assets/back-icon@1x.android.png +0 -0
  48. package/lib/commonjs/assets/back-icon@1x.ios.png +0 -0
  49. package/lib/commonjs/assets/back-icon@2x.android.png +0 -0
  50. package/lib/commonjs/assets/back-icon@2x.ios.png +0 -0
  51. package/lib/commonjs/assets/back-icon@3x.android.png +0 -0
  52. package/lib/commonjs/assets/back-icon@3x.ios.png +0 -0
  53. package/lib/commonjs/assets/back-icon@4x.android.png +0 -0
  54. package/lib/commonjs/assets/back-icon@4x.ios.png +0 -0
  55. package/lib/commonjs/getNamedContext.js +32 -0
  56. package/lib/commonjs/getNamedContext.js.map +1 -0
  57. package/lib/commonjs/index.js +175 -0
  58. package/lib/commonjs/index.js.map +1 -0
  59. package/lib/commonjs/types.js +6 -0
  60. package/lib/commonjs/types.js.map +1 -0
  61. package/lib/module/Background.js +20 -0
  62. package/lib/module/Background.js.map +1 -0
  63. package/lib/module/Header/Header.js +229 -0
  64. package/lib/module/Header/Header.js.map +1 -0
  65. package/lib/module/Header/HeaderBackButton.js +203 -0
  66. package/lib/module/Header/HeaderBackButton.js.map +1 -0
  67. package/lib/module/Header/HeaderBackContext.js +4 -0
  68. package/lib/module/Header/HeaderBackContext.js.map +1 -0
  69. package/lib/module/Header/HeaderBackground.js +42 -0
  70. package/lib/module/Header/HeaderBackground.js.map +1 -0
  71. package/lib/module/Header/HeaderHeightContext.js +4 -0
  72. package/lib/module/Header/HeaderHeightContext.js.map +1 -0
  73. package/lib/module/Header/HeaderShownContext.js +4 -0
  74. package/lib/module/Header/HeaderShownContext.js.map +1 -0
  75. package/lib/module/Header/HeaderTitle.js +41 -0
  76. package/lib/module/Header/HeaderTitle.js.map +1 -0
  77. package/lib/module/Header/getDefaultHeaderHeight.js +32 -0
  78. package/lib/module/Header/getDefaultHeaderHeight.js.map +1 -0
  79. package/lib/module/Header/getHeaderTitle.js +4 -0
  80. package/lib/module/Header/getHeaderTitle.js.map +1 -0
  81. package/lib/module/Header/useHeaderHeight.js +12 -0
  82. package/lib/module/Header/useHeaderHeight.js.map +1 -0
  83. package/lib/module/MaskedView.android.js +2 -0
  84. package/lib/module/MaskedView.android.js.map +1 -0
  85. package/lib/module/MaskedView.ios.js +2 -0
  86. package/lib/module/MaskedView.ios.js.map +1 -0
  87. package/lib/module/MaskedView.js +9 -0
  88. package/lib/module/MaskedView.js.map +1 -0
  89. package/lib/module/MaskedViewNative.js +26 -0
  90. package/lib/module/MaskedViewNative.js.map +1 -0
  91. package/lib/module/MissingIcon.js +20 -0
  92. package/lib/module/MissingIcon.js.map +1 -0
  93. package/lib/module/PlatformPressable.js +62 -0
  94. package/lib/module/PlatformPressable.js.map +1 -0
  95. package/lib/module/ResourceSavingView.js +50 -0
  96. package/lib/module/ResourceSavingView.js.map +1 -0
  97. package/lib/module/SafeAreaProviderCompat.js +51 -0
  98. package/lib/module/SafeAreaProviderCompat.js.map +1 -0
  99. package/lib/module/Screen.js +67 -0
  100. package/lib/module/Screen.js.map +1 -0
  101. package/lib/module/assets/back-icon-mask.png +0 -0
  102. package/lib/module/assets/back-icon.png +0 -0
  103. package/lib/module/assets/back-icon@1.5x.android.png +0 -0
  104. package/lib/module/assets/back-icon@1.5x.ios.png +0 -0
  105. package/lib/module/assets/back-icon@1x.android.png +0 -0
  106. package/lib/module/assets/back-icon@1x.ios.png +0 -0
  107. package/lib/module/assets/back-icon@2x.android.png +0 -0
  108. package/lib/module/assets/back-icon@2x.ios.png +0 -0
  109. package/lib/module/assets/back-icon@3x.android.png +0 -0
  110. package/lib/module/assets/back-icon@3x.ios.png +0 -0
  111. package/lib/module/assets/back-icon@4x.android.png +0 -0
  112. package/lib/module/assets/back-icon@4x.ios.png +0 -0
  113. package/lib/module/getNamedContext.js +19 -0
  114. package/lib/module/getNamedContext.js.map +1 -0
  115. package/lib/module/index.js +21 -0
  116. package/lib/module/index.js.map +1 -0
  117. package/lib/module/types.js +2 -0
  118. package/lib/module/types.js.map +1 -0
  119. package/lib/typescript/src/Background.d.ts +7 -0
  120. package/lib/typescript/src/Header/Header.d.ts +18 -0
  121. package/lib/typescript/src/Header/HeaderBackButton.d.ts +3 -0
  122. package/lib/typescript/src/Header/HeaderBackContext.d.ts +5 -0
  123. package/lib/typescript/src/Header/HeaderBackground.d.ts +8 -0
  124. package/lib/typescript/src/Header/HeaderHeightContext.d.ts +3 -0
  125. package/lib/typescript/src/Header/HeaderShownContext.d.ts +3 -0
  126. package/lib/typescript/src/Header/HeaderTitle.d.ts +9 -0
  127. package/lib/typescript/src/Header/getDefaultHeaderHeight.d.ts +2 -0
  128. package/lib/typescript/src/Header/getHeaderTitle.d.ts +5 -0
  129. package/lib/typescript/src/Header/useHeaderHeight.d.ts +1 -0
  130. package/lib/typescript/src/MaskedView.android.d.ts +1 -0
  131. package/lib/typescript/src/MaskedView.d.ts +10 -0
  132. package/lib/typescript/src/MaskedView.ios.d.ts +1 -0
  133. package/lib/typescript/src/MaskedViewNative.d.ts +10 -0
  134. package/lib/typescript/src/MissingIcon.d.ts +9 -0
  135. package/lib/typescript/src/PlatformPressable.d.ts +12 -0
  136. package/lib/typescript/src/ResourceSavingView.d.ts +9 -0
  137. package/lib/typescript/src/SafeAreaProviderCompat.d.ts +11 -0
  138. package/lib/typescript/src/Screen.d.ts +17 -0
  139. package/lib/typescript/src/getNamedContext.d.ts +5 -0
  140. package/lib/typescript/src/index.d.ts +18 -0
  141. package/lib/typescript/src/types.d.ts +202 -0
  142. package/package.json +72 -0
  143. package/src/Background.tsx +18 -0
  144. package/src/Header/Header.tsx +306 -0
  145. package/src/Header/HeaderBackButton.tsx +240 -0
  146. package/src/Header/HeaderBackContext.tsx +8 -0
  147. package/src/Header/HeaderBackground.tsx +56 -0
  148. package/src/Header/HeaderHeightContext.tsx +8 -0
  149. package/src/Header/HeaderShownContext.tsx +5 -0
  150. package/src/Header/HeaderTitle.tsx +52 -0
  151. package/src/Header/getDefaultHeaderHeight.tsx +39 -0
  152. package/src/Header/getHeaderTitle.tsx +12 -0
  153. package/src/Header/useHeaderHeight.tsx +15 -0
  154. package/src/MaskedView.android.tsx +1 -0
  155. package/src/MaskedView.ios.tsx +1 -0
  156. package/src/MaskedView.tsx +13 -0
  157. package/src/MaskedViewNative.tsx +33 -0
  158. package/src/MissingIcon.tsx +18 -0
  159. package/src/PlatformPressable.tsx +86 -0
  160. package/src/ResourceSavingView.tsx +70 -0
  161. package/src/SafeAreaProviderCompat.tsx +61 -0
  162. package/src/Screen.tsx +109 -0
  163. package/src/assets/back-icon-mask.png +0 -0
  164. package/src/assets/back-icon.png +0 -0
  165. package/src/assets/back-icon@1.5x.android.png +0 -0
  166. package/src/assets/back-icon@1.5x.ios.png +0 -0
  167. package/src/assets/back-icon@1x.android.png +0 -0
  168. package/src/assets/back-icon@1x.ios.png +0 -0
  169. package/src/assets/back-icon@2x.android.png +0 -0
  170. package/src/assets/back-icon@2x.ios.png +0 -0
  171. package/src/assets/back-icon@3x.android.png +0 -0
  172. package/src/assets/back-icon@3x.ios.png +0 -0
  173. package/src/assets/back-icon@4x.android.png +0 -0
  174. package/src/assets/back-icon@4x.ios.png +0 -0
  175. package/src/getNamedContext.tsx +28 -0
  176. package/src/index.tsx +25 -0
  177. package/src/types.tsx +208 -0
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { StyleProp, TextStyle } from 'react-native';
3
+ declare type Props = {
4
+ color?: string;
5
+ size?: number;
6
+ style?: StyleProp<TextStyle>;
7
+ };
8
+ export default function MissingIcon({ color, size, style }: Props): JSX.Element;
9
+ export {};
@@ -0,0 +1,12 @@
1
+ import * as React from 'react';
2
+ import { Animated, PressableProps, StyleProp, ViewStyle } from 'react-native';
3
+ export declare type Props = Omit<PressableProps, 'style'> & {
4
+ pressColor?: string;
5
+ pressOpacity?: number;
6
+ style?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
7
+ children: React.ReactNode;
8
+ };
9
+ /**
10
+ * PlatformPressable provides an abstraction on top of Pressable to handle platform differences.
11
+ */
12
+ export default function PlatformPressable({ onPressIn, onPressOut, android_ripple, pressColor, pressOpacity, style, ...rest }: Props): JSX.Element;
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ import { StyleProp, ViewStyle } from 'react-native';
3
+ declare type Props = {
4
+ visible: boolean;
5
+ children: React.ReactNode;
6
+ style?: StyleProp<ViewStyle>;
7
+ };
8
+ export default function ResourceSavingScene({ visible, children, style, ...rest }: Props): JSX.Element;
9
+ export {};
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ import { StyleProp, ViewStyle } from 'react-native';
3
+ declare type Props = {
4
+ children: React.ReactNode;
5
+ style?: StyleProp<ViewStyle>;
6
+ };
7
+ declare function SafeAreaProviderCompat({ children, style }: Props): JSX.Element;
8
+ declare namespace SafeAreaProviderCompat {
9
+ var initialMetrics: import("react-native-safe-area-context").Metrics;
10
+ }
11
+ export default SafeAreaProviderCompat;
@@ -0,0 +1,17 @@
1
+ import { NavigationProp, ParamListBase, RouteProp } from '@react-navigation/native';
2
+ import * as React from 'react';
3
+ import { StyleProp, ViewStyle } from 'react-native';
4
+ declare type Props = {
5
+ focused: boolean;
6
+ modal?: boolean;
7
+ navigation: NavigationProp<ParamListBase>;
8
+ route: RouteProp<ParamListBase>;
9
+ header: React.ReactNode;
10
+ headerShown?: boolean;
11
+ headerStatusBarHeight?: number;
12
+ headerTransparent?: boolean;
13
+ style?: StyleProp<ViewStyle>;
14
+ children: React.ReactNode;
15
+ };
16
+ export default function Screen(props: Props): JSX.Element;
17
+ export {};
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ declare global {
3
+ var __react_navigation__elements_contexts: Map<string, React.Context<any>>;
4
+ }
5
+ export default function getNamedContext<T>(name: string, initialValue: T): React.Context<T>;
@@ -0,0 +1,18 @@
1
+ export { default as Background } from './Background';
2
+ export { default as getDefaultHeaderHeight } from './Header/getDefaultHeaderHeight';
3
+ export { default as getHeaderTitle } from './Header/getHeaderTitle';
4
+ export { default as Header } from './Header/Header';
5
+ export { default as HeaderBackButton } from './Header/HeaderBackButton';
6
+ export { default as HeaderBackContext } from './Header/HeaderBackContext';
7
+ export { default as HeaderBackground } from './Header/HeaderBackground';
8
+ export { default as HeaderHeightContext } from './Header/HeaderHeightContext';
9
+ export { default as HeaderShownContext } from './Header/HeaderShownContext';
10
+ export { default as HeaderTitle } from './Header/HeaderTitle';
11
+ export { default as useHeaderHeight } from './Header/useHeaderHeight';
12
+ export { default as MissingIcon } from './MissingIcon';
13
+ export { default as PlatformPressable } from './PlatformPressable';
14
+ export { default as ResourceSavingView } from './ResourceSavingView';
15
+ export { default as SafeAreaProviderCompat } from './SafeAreaProviderCompat';
16
+ export { default as Screen } from './Screen';
17
+ export declare const Assets: any[];
18
+ export * from './types';
@@ -0,0 +1,202 @@
1
+ /// <reference types="react" />
2
+ import type { Animated, LayoutChangeEvent, StyleProp, TextStyle, ViewStyle } from 'react-native';
3
+ export declare type Layout = {
4
+ width: number;
5
+ height: number;
6
+ };
7
+ export declare type HeaderOptions = {
8
+ /**
9
+ * String or a function that returns a React Element to be used by the header.
10
+ * Defaults to screen `title` or route name.
11
+ *
12
+ * It receives `allowFontScaling`, `tintColor`, `style` and `children` in the options object as an argument.
13
+ * The title string is passed in `children`.
14
+ */
15
+ headerTitle?: string | ((props: HeaderTitleProps) => React.ReactNode);
16
+ /**
17
+ * How to align the the header title.
18
+ * Defaults to `center` on iOS and `left` on Android.
19
+ */
20
+ headerTitleAlign?: 'left' | 'center';
21
+ /**
22
+ * Style object for the title component.
23
+ */
24
+ headerTitleStyle?: Animated.WithAnimatedValue<StyleProp<TextStyle>>;
25
+ /**
26
+ * Style object for the container of the `headerTitle` element.
27
+ */
28
+ headerTitleContainerStyle?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
29
+ /**
30
+ * Whether header title font should scale to respect Text Size accessibility settings. Defaults to `false`.
31
+ */
32
+ headerTitleAllowFontScaling?: boolean;
33
+ /**
34
+ * Function which returns a React Element to display on the left side of the header.
35
+ */
36
+ headerLeft?: (props: {
37
+ tintColor?: string;
38
+ pressColor?: string;
39
+ pressOpacity?: number;
40
+ labelVisible?: boolean;
41
+ }) => React.ReactNode;
42
+ /**
43
+ * Whether a label is visible in the left button. Used to add extra padding.
44
+ */
45
+ headerLeftLabelVisible?: boolean;
46
+ /**
47
+ * Style object for the container of the `headerLeft` element`.
48
+ */
49
+ headerLeftContainerStyle?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
50
+ /**
51
+ * Function which returns a React Element to display on the right side of the header.
52
+ */
53
+ headerRight?: (props: {
54
+ tintColor?: string;
55
+ pressColor?: string;
56
+ pressOpacity?: number;
57
+ }) => React.ReactNode;
58
+ /**
59
+ * Style object for the container of the `headerRight` element.
60
+ */
61
+ headerRightContainerStyle?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
62
+ /**
63
+ * Color for material ripple (Android >= 5.0 only).
64
+ */
65
+ headerPressColor?: string;
66
+ /**
67
+ * Color for material ripple (Android >= 5.0 only).
68
+ */
69
+ headerPressOpacity?: number;
70
+ /**
71
+ * Tint color for the header.
72
+ */
73
+ headerTintColor?: string;
74
+ /**
75
+ * Function which returns a React Element to render as the background of the header.
76
+ * This is useful for using backgrounds such as an image or a gradient.
77
+ * You can use this with `headerTransparent` to render a blur view, for example, to create a translucent header.
78
+ */
79
+ headerBackground?: (props: {
80
+ style: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
81
+ }) => React.ReactNode;
82
+ /**
83
+ * Style object for the container of the `headerBackground` element.
84
+ */
85
+ headerBackgroundContainerStyle?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
86
+ /**
87
+ * Defaults to `false`. If `true`, the header will not have a background unless you explicitly provide it with `headerBackground`.
88
+ * The header will also float over the screen so that it overlaps the content underneath.
89
+ * This is useful if you want to render a semi-transparent header or a blurred background.
90
+ */
91
+ headerTransparent?: boolean;
92
+ /**
93
+ * Style object for the header. You can specify a custom background color here, for example.
94
+ */
95
+ headerStyle?: StyleProp<ViewStyle>;
96
+ /**
97
+ * Extra padding to add at the top of header to account for translucent status bar.
98
+ * By default, it uses the top value from the safe area insets of the device.
99
+ * Pass 0 or a custom value to disable the default behaviour, and customize the height.
100
+ */
101
+ headerStatusBarHeight?: number;
102
+ };
103
+ export declare type HeaderTitleProps = {
104
+ /**
105
+ * The title text of the header.
106
+ */
107
+ children: string;
108
+ /**
109
+ * Whether title font should scale to respect Text Size accessibility settings.
110
+ */
111
+ allowFontScaling?: boolean;
112
+ /**
113
+ * Tint color for the header.
114
+ */
115
+ tintColor?: string;
116
+ /**
117
+ * Callback to trigger when the size of the title element changes.
118
+ */
119
+ onLayout?: (e: LayoutChangeEvent) => void;
120
+ /**
121
+ * Style object for the title element.
122
+ */
123
+ style?: Animated.WithAnimatedValue<StyleProp<TextStyle>>;
124
+ };
125
+ export declare type HeaderBackButtonProps = {
126
+ /**
127
+ * Whether the button is disabled.
128
+ */
129
+ disabled?: boolean;
130
+ /**
131
+ * Callback to call when the button is pressed.
132
+ */
133
+ onPress?: () => void;
134
+ /**
135
+ * Color for material ripple (Android >= 5.0 only).
136
+ */
137
+ pressColor?: string;
138
+ /**
139
+ * Opacity when the button is pressed, used when ripple is not supported.
140
+ */
141
+ pressOpacity?: number;
142
+ /**
143
+ * Function which returns a React Element to display custom image in header's back button.
144
+ */
145
+ backImage?: (props: {
146
+ tintColor: string;
147
+ }) => React.ReactNode;
148
+ /**
149
+ * Tint color for the header.
150
+ */
151
+ tintColor?: string;
152
+ /**
153
+ * Label text for the button. Usually the title of the previous screen.
154
+ * By default, this is only shown on iOS.
155
+ */
156
+ label?: string;
157
+ /**
158
+ * Label text to show when there isn't enough space for the full label.
159
+ */
160
+ truncatedLabel?: string;
161
+ /**
162
+ * Whether the label text is visible.
163
+ * Defaults to `true` on iOS and `false` on Android.
164
+ */
165
+ labelVisible?: boolean;
166
+ /**
167
+ * Style object for the label.
168
+ */
169
+ labelStyle?: Animated.WithAnimatedValue<StyleProp<TextStyle>>;
170
+ /**
171
+ * Whether label font should scale to respect Text Size accessibility settings.
172
+ */
173
+ allowFontScaling?: boolean;
174
+ /**
175
+ * Callback to trigger when the size of the label changes.
176
+ */
177
+ onLabelLayout?: (e: LayoutChangeEvent) => void;
178
+ /**
179
+ * Layout of the screen.
180
+ */
181
+ screenLayout?: Layout;
182
+ /**
183
+ * Layout of the title element in the header.
184
+ */
185
+ titleLayout?: Layout;
186
+ /**
187
+ * Whether it's possible to navigate back in stack.
188
+ */
189
+ canGoBack?: boolean;
190
+ /**
191
+ * Accessibility label for the button for screen readers.
192
+ */
193
+ accessibilityLabel?: string;
194
+ /**
195
+ * ID to locate this button in tests.
196
+ */
197
+ testID?: string;
198
+ /**
199
+ * Style object for the button.
200
+ */
201
+ style?: StyleProp<ViewStyle>;
202
+ };
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@react-navigation/elements",
3
+ "description": "UI Components for React Navigation",
4
+ "version": "1.1.1",
5
+ "keywords": [
6
+ "react-native",
7
+ "react-navigation",
8
+ "ios",
9
+ "android"
10
+ ],
11
+ "license": "MIT",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/react-navigation/react-navigation.git",
15
+ "directory": "packages/elements"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/react-navigation/react-navigation/issues"
19
+ },
20
+ "homepage": "https://reactnavigation.org",
21
+ "main": "lib/commonjs/index.js",
22
+ "react-native": "src/index.tsx",
23
+ "source": "src/index.tsx",
24
+ "module": "lib/module/index.js",
25
+ "types": "lib/typescript/src/index.d.ts",
26
+ "files": [
27
+ "src",
28
+ "lib",
29
+ "!**/__tests__"
30
+ ],
31
+ "sideEffects": false,
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "scripts": {
36
+ "prepare": "bob build",
37
+ "clean": "del lib"
38
+ },
39
+ "devDependencies": {
40
+ "@react-native-masked-view/masked-view": "^0.2.4",
41
+ "@react-navigation/native": "^6.0.3",
42
+ "@testing-library/react-native": "^7.2.0",
43
+ "@types/react": "^17.0.9",
44
+ "@types/react-native": "~0.64.9",
45
+ "del-cli": "^3.0.1",
46
+ "react": "~16.13.1",
47
+ "react-native": "~0.63.4",
48
+ "react-native-builder-bob": "^0.18.1",
49
+ "typescript": "^4.3.2"
50
+ },
51
+ "peerDependencies": {
52
+ "@react-navigation/native": "^6.0.0",
53
+ "react": "*",
54
+ "react-native": "*",
55
+ "react-native-safe-area-context": ">= 3.0.0"
56
+ },
57
+ "react-native-builder-bob": {
58
+ "source": "src",
59
+ "output": "lib",
60
+ "targets": [
61
+ "commonjs",
62
+ "module",
63
+ [
64
+ "typescript",
65
+ {
66
+ "project": "tsconfig.build.json"
67
+ }
68
+ ]
69
+ ]
70
+ },
71
+ "gitHead": "38ac69f17ee314f96d3d4bcee02349fa4a02d422"
72
+ }
@@ -0,0 +1,18 @@
1
+ import { useTheme } from '@react-navigation/native';
2
+ import * as React from 'react';
3
+ import { View, ViewProps } from 'react-native';
4
+
5
+ type Props = ViewProps & {
6
+ children: React.ReactNode;
7
+ };
8
+
9
+ export default function Background({ style, ...rest }: Props) {
10
+ const { colors } = useTheme();
11
+
12
+ return (
13
+ <View
14
+ {...rest}
15
+ style={[{ flex: 1, backgroundColor: colors.background }, style]}
16
+ />
17
+ );
18
+ }
@@ -0,0 +1,306 @@
1
+ import * as React from 'react';
2
+ import { Animated, Platform, StyleSheet, View, ViewStyle } from 'react-native';
3
+ import {
4
+ useSafeAreaFrame,
5
+ useSafeAreaInsets,
6
+ } from 'react-native-safe-area-context';
7
+
8
+ import type { HeaderOptions, Layout } from '../types';
9
+ import getDefaultHeaderHeight from './getDefaultHeaderHeight';
10
+ import HeaderBackground from './HeaderBackground';
11
+ import HeaderShownContext from './HeaderShownContext';
12
+ import HeaderTitle from './HeaderTitle';
13
+
14
+ type Props = HeaderOptions & {
15
+ /**
16
+ * Whether the header is in a modal
17
+ */
18
+ modal?: boolean;
19
+ /**
20
+ * Layout of the screen.
21
+ */
22
+ layout?: Layout;
23
+ /**
24
+ * Title text for the header.
25
+ */
26
+ title: string;
27
+ };
28
+
29
+ const warnIfHeaderStylesDefined = (styles: Record<string, any>) => {
30
+ Object.keys(styles).forEach((styleProp) => {
31
+ const value = styles[styleProp];
32
+
33
+ if (styleProp === 'position' && value === 'absolute') {
34
+ console.warn(
35
+ "position: 'absolute' is not supported on headerStyle. If you would like to render content under the header, use the 'headerTransparent' option."
36
+ );
37
+ } else if (value !== undefined) {
38
+ console.warn(
39
+ `${styleProp} was given a value of ${value}, this has no effect on headerStyle.`
40
+ );
41
+ }
42
+ });
43
+ };
44
+
45
+ export default function Header(props: Props) {
46
+ const insets = useSafeAreaInsets();
47
+ const frame = useSafeAreaFrame();
48
+
49
+ const isParentHeaderShown = React.useContext(HeaderShownContext);
50
+
51
+ const {
52
+ layout = frame,
53
+ modal = false,
54
+ title,
55
+ headerTitle: customTitle,
56
+ headerTitleAlign = Platform.select({
57
+ ios: 'center',
58
+ default: 'left',
59
+ }),
60
+ headerLeft,
61
+ headerLeftLabelVisible,
62
+ headerTransparent,
63
+ headerTintColor,
64
+ headerBackground,
65
+ headerRight,
66
+ headerTitleAllowFontScaling: titleAllowFontScaling,
67
+ headerTitleStyle: titleStyle,
68
+ headerLeftContainerStyle: leftContainerStyle,
69
+ headerRightContainerStyle: rightContainerStyle,
70
+ headerTitleContainerStyle: titleContainerStyle,
71
+ headerBackgroundContainerStyle: backgroundContainerStyle,
72
+ headerStyle: customHeaderStyle,
73
+ headerPressColor,
74
+ headerPressOpacity,
75
+ headerStatusBarHeight = isParentHeaderShown ? 0 : insets.top,
76
+ } = props;
77
+
78
+ const defaultHeight = getDefaultHeaderHeight(
79
+ layout,
80
+ modal,
81
+ headerStatusBarHeight
82
+ );
83
+
84
+ const {
85
+ height = defaultHeight,
86
+ minHeight,
87
+ maxHeight,
88
+ backgroundColor,
89
+ borderBottomColor,
90
+ borderBottomEndRadius,
91
+ borderBottomLeftRadius,
92
+ borderBottomRightRadius,
93
+ borderBottomStartRadius,
94
+ borderBottomWidth,
95
+ borderColor,
96
+ borderEndColor,
97
+ borderEndWidth,
98
+ borderLeftColor,
99
+ borderLeftWidth,
100
+ borderRadius,
101
+ borderRightColor,
102
+ borderRightWidth,
103
+ borderStartColor,
104
+ borderStartWidth,
105
+ borderStyle,
106
+ borderTopColor,
107
+ borderTopEndRadius,
108
+ borderTopLeftRadius,
109
+ borderTopRightRadius,
110
+ borderTopStartRadius,
111
+ borderTopWidth,
112
+ borderWidth,
113
+ // @ts-expect-error: web support for shadow
114
+ boxShadow,
115
+ elevation,
116
+ shadowColor,
117
+ shadowOffset,
118
+ shadowOpacity,
119
+ shadowRadius,
120
+ opacity,
121
+ transform,
122
+ ...unsafeStyles
123
+ } = StyleSheet.flatten(customHeaderStyle || {}) as ViewStyle;
124
+
125
+ if (process.env.NODE_ENV !== 'production') {
126
+ warnIfHeaderStylesDefined(unsafeStyles);
127
+ }
128
+
129
+ const safeStyles: ViewStyle = {
130
+ backgroundColor,
131
+ borderBottomColor,
132
+ borderBottomEndRadius,
133
+ borderBottomLeftRadius,
134
+ borderBottomRightRadius,
135
+ borderBottomStartRadius,
136
+ borderBottomWidth,
137
+ borderColor,
138
+ borderEndColor,
139
+ borderEndWidth,
140
+ borderLeftColor,
141
+ borderLeftWidth,
142
+ borderRadius,
143
+ borderRightColor,
144
+ borderRightWidth,
145
+ borderStartColor,
146
+ borderStartWidth,
147
+ borderStyle,
148
+ borderTopColor,
149
+ borderTopEndRadius,
150
+ borderTopLeftRadius,
151
+ borderTopRightRadius,
152
+ borderTopStartRadius,
153
+ borderTopWidth,
154
+ borderWidth,
155
+ // @ts-expect-error: boxShadow is only for Web
156
+ boxShadow,
157
+ elevation,
158
+ shadowColor,
159
+ shadowOffset,
160
+ shadowOpacity,
161
+ shadowRadius,
162
+ opacity,
163
+ transform,
164
+ };
165
+
166
+ // Setting a property to undefined triggers default style
167
+ // So we need to filter them out
168
+ // Users can use `null` instead
169
+ for (const styleProp in safeStyles) {
170
+ // @ts-expect-error: typescript wrongly complains that styleProp cannot be used to index safeStyles
171
+ if (safeStyles[styleProp] === undefined) {
172
+ // @ts-expect-error
173
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
174
+ delete safeStyles[styleProp];
175
+ }
176
+ }
177
+
178
+ const leftButton = headerLeft
179
+ ? headerLeft({
180
+ tintColor: headerTintColor,
181
+ pressColor: headerPressColor,
182
+ pressOpacity: headerPressOpacity,
183
+ labelVisible: headerLeftLabelVisible,
184
+ })
185
+ : null;
186
+
187
+ const rightButton = headerRight
188
+ ? headerRight({
189
+ tintColor: headerTintColor,
190
+ pressColor: headerPressColor,
191
+ pressOpacity: headerPressOpacity,
192
+ })
193
+ : null;
194
+
195
+ const headerTitle =
196
+ typeof customTitle !== 'function'
197
+ ? (props: React.ComponentProps<typeof HeaderTitle>) => (
198
+ <HeaderTitle {...props} />
199
+ )
200
+ : customTitle;
201
+
202
+ return (
203
+ <React.Fragment>
204
+ <Animated.View
205
+ pointerEvents="box-none"
206
+ style={[
207
+ StyleSheet.absoluteFill,
208
+ { zIndex: 0 },
209
+ backgroundContainerStyle,
210
+ ]}
211
+ >
212
+ {headerBackground ? (
213
+ headerBackground({ style: safeStyles })
214
+ ) : headerTransparent ? null : (
215
+ <HeaderBackground style={safeStyles} />
216
+ )}
217
+ </Animated.View>
218
+ <Animated.View
219
+ pointerEvents="box-none"
220
+ style={[{ height, minHeight, maxHeight, opacity, transform }]}
221
+ >
222
+ <View pointerEvents="none" style={{ height: headerStatusBarHeight }} />
223
+ <View pointerEvents="box-none" style={styles.content}>
224
+ <Animated.View
225
+ pointerEvents="box-none"
226
+ style={[
227
+ styles.left,
228
+ headerTitleAlign === 'center' && styles.expand,
229
+ { marginStart: insets.left },
230
+ leftContainerStyle,
231
+ ]}
232
+ >
233
+ {leftButton}
234
+ </Animated.View>
235
+ <Animated.View
236
+ pointerEvents="box-none"
237
+ style={[
238
+ styles.title,
239
+ {
240
+ // Avoid the title from going offscreen or overlapping buttons
241
+ maxWidth:
242
+ headerTitleAlign === 'center'
243
+ ? layout.width -
244
+ ((leftButton
245
+ ? headerLeftLabelVisible !== false
246
+ ? 80
247
+ : 32
248
+ : 16) +
249
+ Math.max(insets.left, insets.right)) *
250
+ 2
251
+ : layout.width -
252
+ ((leftButton ? 72 : 16) +
253
+ (rightButton ? 72 : 16) +
254
+ insets.left -
255
+ insets.right),
256
+ },
257
+ titleContainerStyle,
258
+ ]}
259
+ >
260
+ {headerTitle({
261
+ children: title,
262
+ allowFontScaling: titleAllowFontScaling,
263
+ tintColor: headerTintColor,
264
+ style: titleStyle,
265
+ })}
266
+ </Animated.View>
267
+ <Animated.View
268
+ pointerEvents="box-none"
269
+ style={[
270
+ styles.right,
271
+ styles.expand,
272
+ { marginEnd: insets.right },
273
+ rightContainerStyle,
274
+ ]}
275
+ >
276
+ {rightButton}
277
+ </Animated.View>
278
+ </View>
279
+ </Animated.View>
280
+ </React.Fragment>
281
+ );
282
+ }
283
+
284
+ const styles = StyleSheet.create({
285
+ content: {
286
+ flex: 1,
287
+ flexDirection: 'row',
288
+ alignItems: 'stretch',
289
+ },
290
+ title: {
291
+ marginHorizontal: 16,
292
+ justifyContent: 'center',
293
+ },
294
+ left: {
295
+ justifyContent: 'center',
296
+ alignItems: 'flex-start',
297
+ },
298
+ right: {
299
+ justifyContent: 'center',
300
+ alignItems: 'flex-end',
301
+ },
302
+ expand: {
303
+ flexGrow: 1,
304
+ flexBasis: 0,
305
+ },
306
+ });