UNPKG

9.23 kBTypeScriptView Raw
1import type { HeaderOptions } from '@react-navigation/elements';
2import type { Descriptor, NavigationHelpers, NavigationProp, ParamListBase, RouteProp, TabActionHelpers, TabNavigationState } from '@react-navigation/native';
3import type * as React from 'react';
4import type { Animated, GestureResponderEvent, StyleProp, TextStyle, TouchableWithoutFeedbackProps, 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 BottomTabNavigationEventMap = {
11 /**
12 * Event which fires on tapping on the tab in the tab bar.
13 */
14 tabPress: {
15 data: undefined;
16 canPreventDefault: true;
17 };
18 /**
19 * Event which fires on long press on the tab in the tab bar.
20 */
21 tabLongPress: {
22 data: undefined;
23 };
24};
25export type LabelPosition = 'beside-icon' | 'below-icon';
26export type BottomTabNavigationHelpers = NavigationHelpers<ParamListBase, BottomTabNavigationEventMap> & TabActionHelpers<ParamListBase>;
27export 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>;
28export type BottomTabScreenProps<ParamList extends ParamListBase, RouteName extends keyof ParamList = keyof ParamList, NavigatorID extends string | undefined = undefined> = {
29 navigation: BottomTabNavigationProp<ParamList, RouteName, NavigatorID>;
30 route: RouteProp<ParamList, RouteName>;
31};
32export type TimingKeyboardAnimationConfig = {
33 animation: 'timing';
34 config?: Omit<Partial<Animated.TimingAnimationConfig>, 'toValue' | 'useNativeDriver'>;
35};
36export type SpringKeyboardAnimationConfig = {
37 animation: 'spring';
38 config?: Omit<Partial<Animated.SpringAnimationConfig>, 'toValue' | 'useNativeDriver'>;
39};
40export type TabBarVisibilityAnimationConfig = TimingKeyboardAnimationConfig | SpringKeyboardAnimationConfig;
41export type BottomTabNavigationOptions = HeaderOptions & {
42 /**
43 * Title text for the screen.
44 */
45 title?: string;
46 /**
47 * Title string of a tab displayed in the tab bar
48 * 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.
49 *
50 * When undefined, scene title is used. Use `tabBarShowLabel` to hide the label.
51 */
52 tabBarLabel?: string | ((props: {
53 focused: boolean;
54 color: string;
55 position: LabelPosition;
56 children: string;
57 }) => React.ReactNode);
58 /**
59 * Whether the tab label should be visible. Defaults to `true`.
60 */
61 tabBarShowLabel?: boolean;
62 /**
63 * Whether the label is shown below the icon or beside the icon.
64 *
65 * - `below-icon`: the label is shown below the icon (typical for iPhones)
66 * - `beside-icon` the label is shown next to the icon (typical for iPad)
67 *
68 * By default, the position is chosen automatically based on device width.
69 */
70 tabBarLabelPosition?: LabelPosition;
71 /**
72 * Style object for the tab label.
73 */
74 tabBarLabelStyle?: StyleProp<TextStyle>;
75 /**
76 * Whether label font should scale to respect Text Size accessibility settings.
77 */
78 tabBarAllowFontScaling?: boolean;
79 /**
80 * A function that given { focused: boolean, color: string } returns a React.Node to display in the tab bar.
81 */
82 tabBarIcon?: (props: {
83 focused: boolean;
84 color: string;
85 size: number;
86 }) => React.ReactNode;
87 /**
88 * Style object for the tab icon.
89 */
90 tabBarIconStyle?: StyleProp<TextStyle>;
91 /**
92 * Text to show in a badge on the tab icon.
93 */
94 tabBarBadge?: number | string;
95 /**
96 * Custom style for the tab bar badge.
97 * You can specify a background color or text color here.
98 */
99 tabBarBadgeStyle?: StyleProp<TextStyle>;
100 /**
101 * Accessibility label for the tab button. This is read by the screen reader when the user taps the tab.
102 * It's recommended to set this if you don't have a label for the tab.
103 */
104 tabBarAccessibilityLabel?: string;
105 /**
106 * ID to locate this tab button in tests.
107 */
108 tabBarTestID?: string;
109 /**
110 * Function which returns a React element to render as the tab bar button.
111 * Renders `Pressable` by default.
112 */
113 tabBarButton?: (props: BottomTabBarButtonProps) => React.ReactNode;
114 /**
115 * Color for the icon and label in the active tab.
116 */
117 tabBarActiveTintColor?: string;
118 /**
119 * Color for the icon and label in the inactive tabs.
120 */
121 tabBarInactiveTintColor?: string;
122 /**
123 * Background color for the active tab.
124 */
125 tabBarActiveBackgroundColor?: string;
126 /**
127 * Background color for the inactive tabs.
128 */
129 tabBarInactiveBackgroundColor?: string;
130 /**
131 * Style object for the tab item container.
132 */
133 tabBarItemStyle?: StyleProp<ViewStyle>;
134 /**
135 * Whether the tab bar gets hidden when the keyboard is shown. Defaults to `false`.
136 */
137 tabBarHideOnKeyboard?: boolean;
138 /**
139 * Animation config for showing and hiding the tab bar when the keyboard is shown/hidden.
140 */
141 tabBarVisibilityAnimationConfig?: {
142 show?: TabBarVisibilityAnimationConfig;
143 hide?: TabBarVisibilityAnimationConfig;
144 };
145 /**
146 * Style object for the tab bar container.
147 */
148 tabBarStyle?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
149 /**
150 * Function which returns a React Element to use as background for the tab bar.
151 * You could render an image, a gradient, blur view etc.
152 *
153 * When using `BlurView`, make sure to set `position: 'absolute'` in `tabBarStyle` as well.
154 * You'd also need to use `useBottomTabBarHeight()` to add a bottom padding to your content.
155 */
156 tabBarBackground?: () => React.ReactNode;
157 /**
158 * Whether this screens should render the first time it's accessed. Defaults to `true`.
159 * Set it to `false` if you want to render the screen on initial render.
160 */
161 lazy?: boolean;
162 /**
163 * Function that given returns a React Element to display as a header.
164 */
165 header?: (props: BottomTabHeaderProps) => React.ReactNode;
166 /**
167 * Whether to show the header. Setting this to `false` hides the header.
168 * Defaults to `true`.
169 */
170 headerShown?: boolean;
171 /**
172 * Whether this screen should be unmounted when navigating away from it.
173 * Defaults to `false`.
174 */
175 unmountOnBlur?: boolean;
176 /**
177 * Whether inactive screens should be suspended from re-rendering. Defaults to `false`.
178 * Defaults to `true` when `enableFreeze()` is run at the top of the application.
179 * Requires `react-native-screens` version >=3.16.0.
180 *
181 * Only supported on iOS and Android.
182 */
183 freezeOnBlur?: boolean;
184};
185export type BottomTabDescriptor = Descriptor<BottomTabNavigationOptions, BottomTabNavigationProp<ParamListBase>, RouteProp<ParamListBase>>;
186export type BottomTabDescriptorMap = Record<string, BottomTabDescriptor>;
187export type BottomTabNavigationConfig = {
188 /**
189 * Function that returns a React element to display as the tab bar.
190 */
191 tabBar?: (props: BottomTabBarProps) => React.ReactNode;
192 /**
193 * 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.
194 * By default, the device's safe area insets are automatically detected. You can override the behavior with this option.
195 */
196 safeAreaInsets?: {
197 top?: number;
198 right?: number;
199 bottom?: number;
200 left?: number;
201 };
202 /**
203 * Whether inactive screens should be detached from the view hierarchy to save memory.
204 * Make sure to call `enableScreens` from `react-native-screens` to make it work.
205 * Defaults to `true` on Android.
206 */
207 detachInactiveScreens?: boolean;
208 /**
209 * Style object for the component wrapping the screen content.
210 */
211 sceneContainerStyle?: StyleProp<ViewStyle>;
212};
213export type BottomTabHeaderProps = {
214 /**
215 * Layout of the screen.
216 */
217 layout: Layout;
218 /**
219 * Options for the current screen.
220 */
221 options: BottomTabNavigationOptions;
222 /**
223 * Route object for the current screen.
224 */
225 route: RouteProp<ParamListBase>;
226 /**
227 * Navigation prop for the header.
228 */
229 navigation: BottomTabNavigationProp<ParamListBase>;
230};
231export type BottomTabBarProps = {
232 state: TabNavigationState<ParamListBase>;
233 descriptors: BottomTabDescriptorMap;
234 navigation: NavigationHelpers<ParamListBase, BottomTabNavigationEventMap>;
235 insets: EdgeInsets;
236};
237export type BottomTabBarButtonProps = Omit<TouchableWithoutFeedbackProps, 'onPress'> & {
238 to?: string;
239 children: React.ReactNode;
240 onPress?: (e: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent) => void;
241};
242//# sourceMappingURL=types.d.ts.map
\No newline at end of file