UNPKG

12.6 kBTypeScriptView Raw
1import type { HeaderOptions } from '@react-navigation/elements';
2import type { DefaultNavigatorOptions, Descriptor, NavigationHelpers, NavigationProp, ParamListBase, RouteProp, TabActionHelpers, TabNavigationState, TabRouterOptions, Theme } from '@react-navigation/native';
3import type * as React from 'react';
4import type { Animated, GestureResponderEvent, Pressable, StyleProp, TextStyle, ViewStyle } from 'react-native';
5import type { EdgeInsets } from 'react-native-safe-area-context';
6export type Layout = {
7 width: number;
8 height: number;
9};
10export type Variant = 'uikit' | 'material';
11export type BottomTabNavigationEventMap = {
12 /**
13 * Event which fires on tapping on the tab in the tab bar.
14 */
15 tabPress: {
16 data: undefined;
17 canPreventDefault: true;
18 };
19 /**
20 * Event which fires on long press on the tab in the tab bar.
21 */
22 tabLongPress: {
23 data: undefined;
24 };
25 /**
26 * Event which fires when a transition animation starts.
27 */
28 transitionStart: {
29 data: undefined;
30 };
31 /**
32 * Event which fires when a transition animation ends.
33 */
34 transitionEnd: {
35 data: undefined;
36 };
37};
38export type LabelPosition = 'beside-icon' | 'below-icon';
39export type BottomTabNavigationHelpers = NavigationHelpers<ParamListBase, BottomTabNavigationEventMap> & TabActionHelpers<ParamListBase>;
40export type BottomTabNavigationProp<ParamList extends ParamListBase, RouteName extends keyof ParamList = keyof ParamList, NavigatorID extends string | undefined = undefined> = NavigationProp<ParamList, RouteName, NavigatorID, TabNavigationState<ParamList>, BottomTabNavigationOptions, BottomTabNavigationEventMap> & TabActionHelpers<ParamList>;
41export type BottomTabScreenProps<ParamList extends ParamListBase, RouteName extends keyof ParamList = keyof ParamList, NavigatorID extends string | undefined = undefined> = {
42 navigation: BottomTabNavigationProp<ParamList, RouteName, NavigatorID>;
43 route: RouteProp<ParamList, RouteName>;
44};
45export type BottomTabOptionsArgs<ParamList extends ParamListBase, RouteName extends keyof ParamList = keyof ParamList, NavigatorID extends string | undefined = undefined> = BottomTabScreenProps<ParamList, RouteName, NavigatorID> & {
46 theme: Theme;
47};
48export type TimingKeyboardAnimationConfig = {
49 animation: 'timing';
50 config?: Omit<Partial<Animated.TimingAnimationConfig>, 'toValue' | 'useNativeDriver'>;
51};
52export type SpringKeyboardAnimationConfig = {
53 animation: 'spring';
54 config?: Omit<Partial<Animated.SpringAnimationConfig>, 'toValue' | 'useNativeDriver'>;
55};
56export type TabBarVisibilityAnimationConfig = TimingKeyboardAnimationConfig | SpringKeyboardAnimationConfig;
57export type TabAnimationName = 'none' | 'fade' | 'shift';
58export type BottomTabNavigationOptions = HeaderOptions & {
59 /**
60 * Title text for the screen.
61 */
62 title?: string;
63 /**
64 * Title string of a tab displayed in the tab bar
65 * or a function that given { focused: boolean, color: string, position: 'below-icon' | 'beside-icon', children: string } returns a React.Node to display in tab bar.
66 *
67 * When undefined, scene title is used. Use `tabBarShowLabel` to hide the label.
68 */
69 tabBarLabel?: string | ((props: {
70 focused: boolean;
71 color: string;
72 position: LabelPosition;
73 children: string;
74 }) => React.ReactNode);
75 /**
76 * Whether the tab label should be visible. Defaults to `true`.
77 */
78 tabBarShowLabel?: boolean;
79 /**
80 * Whether the label is shown below the icon or beside the icon.
81 *
82 * - `below-icon`: the label is shown below the icon (typical for iPhones)
83 * - `beside-icon` the label is shown next to the icon (typical for iPad)
84 *
85 * By default, the position is chosen automatically based on device width.
86 */
87 tabBarLabelPosition?: LabelPosition;
88 /**
89 * Style object for the tab label.
90 */
91 tabBarLabelStyle?: StyleProp<TextStyle>;
92 /**
93 * Whether label font should scale to respect Text Size accessibility settings.
94 */
95 tabBarAllowFontScaling?: boolean;
96 /**
97 * A function that given { focused: boolean, color: string } returns a React.Node to display in the tab bar.
98 */
99 tabBarIcon?: (props: {
100 focused: boolean;
101 color: string;
102 size: number;
103 }) => React.ReactNode;
104 /**
105 * Style object for the tab icon.
106 */
107 tabBarIconStyle?: StyleProp<TextStyle>;
108 /**
109 * Text to show in a badge on the tab icon.
110 */
111 tabBarBadge?: number | string;
112 /**
113 * Custom style for the tab bar badge.
114 * You can specify a background color or text color here.
115 */
116 tabBarBadgeStyle?: StyleProp<TextStyle>;
117 /**
118 * Accessibility label for the tab button. This is read by the screen reader when the user taps the tab.
119 * It's recommended to set this if you don't have a label for the tab.
120 */
121 tabBarAccessibilityLabel?: string;
122 /**
123 * ID to locate this tab button in tests.
124 */
125 tabBarButtonTestID?: string;
126 /**
127 * Function which returns a React element to render as the tab bar button.
128 * Renders `PlatformPressable` by default.
129 */
130 tabBarButton?: (props: BottomTabBarButtonProps) => React.ReactNode;
131 /**
132 * Color for the icon and label in the active tab.
133 */
134 tabBarActiveTintColor?: string;
135 /**
136 * Color for the icon and label in the inactive tabs.
137 */
138 tabBarInactiveTintColor?: string;
139 /**
140 * Background color for the active tab.
141 */
142 tabBarActiveBackgroundColor?: string;
143 /**
144 * Background color for the inactive tabs.
145 */
146 tabBarInactiveBackgroundColor?: string;
147 /**
148 * Style object for the tab item container.
149 */
150 tabBarItemStyle?: StyleProp<ViewStyle>;
151 /**
152 * Whether the tab bar gets hidden when the keyboard is shown. Defaults to `false`.
153 */
154 tabBarHideOnKeyboard?: boolean;
155 /**
156 * Animation config for showing and hiding the tab bar when the keyboard is shown/hidden.
157 */
158 tabBarVisibilityAnimationConfig?: {
159 show?: TabBarVisibilityAnimationConfig;
160 hide?: TabBarVisibilityAnimationConfig;
161 };
162 /**
163 * Variant of the tab bar. Defaults to `uikit`.
164 */
165 tabBarVariant?: Variant;
166 /**
167 * Style object for the tab bar container.
168 */
169 tabBarStyle?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
170 /**
171 * Function which returns a React Element to use as background for the tab bar.
172 * You could render an image, a gradient, blur view etc.
173 *
174 * When using `BlurView`, make sure to set `position: 'absolute'` in `tabBarStyle` as well.
175 * You'd also need to use `useBottomTabBarHeight()` to add a bottom padding to your content.
176 */
177 tabBarBackground?: () => React.ReactNode;
178 /**
179 * Position of the tab bar on the screen. Defaults to `bottom`.
180 */
181 tabBarPosition?: 'bottom' | 'left' | 'right' | 'top';
182 /**
183 * Whether this screens should render the first time it's accessed. Defaults to `true`.
184 * Set it to `false` if you want to render the screen on initial render.
185 */
186 lazy?: boolean;
187 /**
188 * Function that given returns a React Element to display as a header.
189 */
190 header?: (props: BottomTabHeaderProps) => React.ReactNode;
191 /**
192 * Whether to show the header. Setting this to `false` hides the header.
193 * Defaults to `true`.
194 */
195 headerShown?: boolean;
196 /**
197 * Whether any nested stack should be popped to top when navigating away from the tab.
198 * Defaults to `false`.
199 */
200 popToTopOnBlur?: boolean;
201 /**
202 * Whether inactive screens should be suspended from re-rendering. Defaults to `false`.
203 * Defaults to `true` when `enableFreeze()` is run at the top of the application.
204 * Requires `react-native-screens` version >=3.16.0.
205 *
206 * Only supported on iOS and Android.
207 */
208 freezeOnBlur?: boolean;
209 /**
210 * Style object for the component wrapping the screen content.
211 */
212 sceneStyle?: StyleProp<ViewStyle>;
213 /**
214 * How the screen should animate when switching tabs.
215 *
216 * Supported values:
217 * - 'none': don't animate the screen (default)
218 * - 'fade': cross-fade the screens.
219 * - 'shift': shift the screens slightly shift to left/right.
220 */
221 animation?: TabAnimationName;
222 /**
223 * Function which specifies interpolated styles for bottom-tab scenes.
224 */
225 sceneStyleInterpolator?: BottomTabSceneStyleInterpolator;
226 /**
227 * Object which specifies the animation type (timing or spring) and their options (such as duration for timing).
228 */
229 transitionSpec?: TransitionSpec;
230};
231export type BottomTabDescriptor = Descriptor<BottomTabNavigationOptions, BottomTabNavigationProp<ParamListBase>, RouteProp<ParamListBase>>;
232export type BottomTabDescriptorMap = Record<string, BottomTabDescriptor>;
233export type BottomTabSceneInterpolationProps = {
234 /**
235 * Values for the current screen.
236 */
237 current: {
238 /**
239 * Animated value for the current screen:
240 * - -1 if the index is lower than active tab,
241 * - 0 if they're active,
242 * - 1 if the index is higher than active tab
243 */
244 progress: Animated.Value;
245 };
246};
247export type BottomTabSceneInterpolatedStyle = {
248 /**
249 * Interpolated style for the view representing the scene containing screen content.
250 */
251 sceneStyle: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
252};
253export type BottomTabSceneStyleInterpolator = (props: BottomTabSceneInterpolationProps) => BottomTabSceneInterpolatedStyle;
254export type TransitionSpec = {
255 animation: 'timing';
256 config: Omit<Animated.TimingAnimationConfig, 'toValue' | keyof Animated.AnimationConfig>;
257} | {
258 animation: 'spring';
259 config: Omit<Animated.SpringAnimationConfig, 'toValue' | keyof Animated.AnimationConfig>;
260};
261export type BottomTabTransitionPreset = {
262 /**
263 * Whether transition animations should be enabled when switching tabs.
264 */
265 animationEnabled?: boolean;
266 /**
267 * Function which specifies interpolated styles for bottom-tab scenes.
268 */
269 sceneStyleInterpolator?: BottomTabSceneStyleInterpolator;
270 /**
271 * Object which specifies the animation type (timing or spring) and their options (such as duration for timing).
272 */
273 transitionSpec?: TransitionSpec;
274};
275export type BottomTabNavigationConfig = {
276 /**
277 * Function that returns a React element to display as the tab bar.
278 */
279 tabBar?: (props: BottomTabBarProps) => React.ReactNode;
280 /**
281 * Safe area insets for the tab bar. This is used to avoid elements like the navigation bar on Android and bottom safe area on iOS.
282 * By default, the device's safe area insets are automatically detected. You can override the behavior with this option.
283 */
284 safeAreaInsets?: {
285 top?: number;
286 right?: number;
287 bottom?: number;
288 left?: number;
289 };
290 /**
291 * Whether inactive screens should be detached from the view hierarchy to save memory.
292 * Make sure to call `enableScreens` from `react-native-screens` to make it work.
293 * Defaults to `true` on Android.
294 */
295 detachInactiveScreens?: boolean;
296};
297export type BottomTabHeaderProps = {
298 /**
299 * Layout of the screen.
300 */
301 layout: Layout;
302 /**
303 * Options for the current screen.
304 */
305 options: BottomTabNavigationOptions;
306 /**
307 * Route object for the current screen.
308 */
309 route: RouteProp<ParamListBase>;
310 /**
311 * Navigation prop for the header.
312 */
313 navigation: BottomTabNavigationProp<ParamListBase>;
314};
315export type BottomTabBarProps = {
316 state: TabNavigationState<ParamListBase>;
317 descriptors: BottomTabDescriptorMap;
318 navigation: NavigationHelpers<ParamListBase, BottomTabNavigationEventMap>;
319 insets: EdgeInsets;
320};
321export type BottomTabBarButtonProps = Omit<React.ComponentProps<typeof Pressable>, 'style'> & {
322 href?: string;
323 children: React.ReactNode;
324 style?: StyleProp<ViewStyle>;
325 onPress?: (e: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent) => void;
326};
327export type BottomTabNavigatorProps = DefaultNavigatorOptions<ParamListBase, string | undefined, TabNavigationState<ParamListBase>, BottomTabNavigationOptions, BottomTabNavigationEventMap, BottomTabNavigationProp<ParamListBase>> & TabRouterOptions & BottomTabNavigationConfig;
328//# sourceMappingURL=types.d.ts.map
\No newline at end of file