|
| 1 | +--- |
| 2 | +id: version-3.x-tab-navigator |
| 3 | +title: createTabNavigator |
| 4 | +sidebar_label: createTabNavigator |
| 5 | +original_id: tab-navigator |
| 6 | +--- |
| 7 | + |
| 8 | +> Note: `createTabNavigator` is deprecated. Please use `createBottomTabNavigator` and/or `createMaterialTopTabNavigator` instead. |
| 9 | +
|
| 10 | +```js |
| 11 | +createTabNavigator(RouteConfigs, TabNavigatorConfig); |
| 12 | +``` |
| 13 | + |
| 14 | +## RouteConfigs |
| 15 | + |
| 16 | +The route configs object is a mapping from route name to a route config, which tells the navigator what to present for that route, see [example](stack-navigator.html#routeconfigs) from stack navigator. |
| 17 | + |
| 18 | +## TabNavigatorConfig |
| 19 | + |
| 20 | +* `tabBarComponent` - Component to use as the tab bar, e.g. `TabBarBottom` (this is the default on iOS), `TabBarTop` (this is the default on Android). |
| 21 | +* `tabBarPosition` - Position of the tab bar, can be `'top'` or `'bottom'`. |
| 22 | +* `swipeEnabled` - Whether to allow swiping between tabs. |
| 23 | +* `animationEnabled` - Whether to animate when changing tabs. |
| 24 | +* `lazy` - Defaults to `true`. If `false`, all tabs are rendered immediately. When `true`, tabs are rendered only when they are made active for the first time. Note: tabs are **not** re-rendered upon subsequent visits. |
| 25 | +* `removeClippedSubviews` - Defaults to `true`. An optimization to reduce memory usage by freeing resources used by inactive tabs. |
| 26 | +* `initialLayout` - Optional object containing the initial `height` and `width`, can be passed to prevent the one frame delay in [react-native-tab-view](https://github.com/react-native-community/react-native-tab-view#avoid-one-frame-delay) rendering. |
| 27 | +* `tabBarOptions` - Configure the tab bar, see below. |
| 28 | + |
| 29 | +Several options get passed to the underlying router to modify navigation logic: |
| 30 | + |
| 31 | +* `initialRouteName` - The routeName for the initial tab route when first loading. |
| 32 | +* `order` - Array of routeNames which defines the order of the tabs. |
| 33 | +* `paths` - Provide a mapping of routeName to path config, which overrides the paths set in the routeConfigs. |
| 34 | +* `backBehavior` - Should the back button cause a tab switch to the initial tab? If yes, set to `initialRoute`, otherwise `none`. Defaults to `initialRoute` behavior. |
| 35 | + |
| 36 | +### `tabBarOptions` for `TabBarBottom` (default tab bar on iOS) |
| 37 | + |
| 38 | +* `activeTintColor` - Label and icon color of the active tab. |
| 39 | +* `activeBackgroundColor` - Background color of the active tab. |
| 40 | +* `inactiveTintColor` - Label and icon color of the inactive tab. |
| 41 | +* `inactiveBackgroundColor` - Background color of the inactive tab. |
| 42 | +* `showLabel` - Whether to show label for tab, default is true. |
| 43 | +* `style` - Style object for the tab bar. |
| 44 | +* `labelStyle` - Style object for the tab label. |
| 45 | +* `tabStyle` - Style object for the tab. |
| 46 | +* `allowFontScaling` - Whether label font should scale to respect Text Size accessibility settings, default is true. |
| 47 | +* `safeAreaInset` - Override the `forceInset` prop for `<SafeAreaView>`. Defaults to `{ bottom: 'always', top: 'never' }`. Available keys are `top | bottom | left | right` provided with the values `'always' | 'never'`. |
| 48 | + |
| 49 | +Example: |
| 50 | + |
| 51 | +```js |
| 52 | +tabBarOptions: { |
| 53 | + activeTintColor: '#e91e63', |
| 54 | + labelStyle: { |
| 55 | + fontSize: 12, |
| 56 | + }, |
| 57 | + style: { |
| 58 | + backgroundColor: 'blue', |
| 59 | + }, |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +### `tabBarOptions` for `TabBarTop` (default tab bar on Android) |
| 64 | + |
| 65 | +* `activeTintColor` - Label and icon color of the active tab. |
| 66 | +* `inactiveTintColor` - Label and icon color of the inactive tab. |
| 67 | +* `showIcon` - Whether to show icon for tab, default is false. |
| 68 | +* `showLabel` - Whether to show label for tab, default is true. |
| 69 | +* `upperCaseLabel` - Whether to make label uppercase, default is true. |
| 70 | +* `pressColor` - Color for material ripple (Android >= 5.0 only). |
| 71 | +* `pressOpacity` - Opacity for pressed tab (iOS and Android < 5.0 only). |
| 72 | +* `scrollEnabled` - Whether to enable scrollable tabs. |
| 73 | +* `tabStyle` - Style object for the tab. |
| 74 | +* `indicatorStyle` - Style object for the tab indicator (line at the bottom of the tab). |
| 75 | +* `labelStyle` - Style object for the tab label. |
| 76 | +* `iconStyle` - Style object for the tab icon. |
| 77 | +* `style` - Style object for the tab bar. |
| 78 | +* `allowFontScaling` - Whether label font should scale to respect Text Size accessibility settings, default is true. |
| 79 | + |
| 80 | +Example: |
| 81 | + |
| 82 | +```js |
| 83 | +tabBarOptions: { |
| 84 | + labelStyle: { |
| 85 | + fontSize: 12, |
| 86 | + }, |
| 87 | + tabStyle: { |
| 88 | + width: 100, |
| 89 | + }, |
| 90 | + style: { |
| 91 | + backgroundColor: 'blue', |
| 92 | + }, |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +## `navigationOptions` for screens inside of the navigator |
| 97 | + |
| 98 | +#### `title` |
| 99 | + |
| 100 | +Generic title that can be used as a fallback for `headerTitle` and `tabBarLabel`. |
| 101 | + |
| 102 | +#### `tabBarVisible` |
| 103 | + |
| 104 | +True or false to show or hide the tab bar, if not set then defaults to true. |
| 105 | + |
| 106 | +#### `swipeEnabled` |
| 107 | + |
| 108 | +True or false to enable or disable swiping between tabs, if not set then defaults to TabNavigatorConfig option swipeEnabled. |
| 109 | + |
| 110 | +#### `tabBarIcon` |
| 111 | + |
| 112 | +React Element or a function that given `{ focused: boolean, horizontal: boolean, tintColor: string }` returns a React.Node, to display in the tab bar. `horizontal` is `true` when the device is in landscape and `false` when portrait. The icon is re-rendered whenever the device orientation changes. |
| 113 | + |
| 114 | +#### `tabBarLabel` |
| 115 | + |
| 116 | +Title string of a tab displayed in the tab bar or React Element or a function that given `{ focused: boolean, tintColor: string }` returns a React.Node, to display in tab bar. When undefined, scene `title` is used. To hide, see `tabBarOptions.showLabel` in the previous section. |
| 117 | + |
| 118 | +#### `tabBarOnPress` |
| 119 | + |
| 120 | +Callback to handle tap events; the argument is an object containing: |
| 121 | + |
| 122 | +* the `previousScene: { route, index }` which is the scene we are leaving |
| 123 | +* the `scene: { route, index }` that was tapped |
| 124 | +* the `jumpToIndex` method that can perform the navigation for you |
| 125 | + |
| 126 | +Useful for adding a custom logic before the transition to the next scene (the tapped one) starts. |
0 commit comments