You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versioned_docs/version-8.x/bottom-tab-navigator.md
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -576,7 +576,9 @@ The icon can be of following types with `native` implementation:
576
576
}
577
577
```
578
578
579
-
On iOS, you can additionally pass a `tinted` property to control whether the icon should be tinted with the active/inactive color:
579
+
It's necessary to provide icons for multiple screen densities (1x, 2x, 3x), e.g.: `icon.png`, `[email protected]`, `[email protected]` etc. as icons are not scaled automatically on iOS for the `native` implementation.
580
+
581
+
A `tinted` property can be used to control whether the icon should be tinted with the active/inactive color:
580
582
581
583
```js
582
584
tabBarIcon: {
@@ -586,7 +588,9 @@ The icon can be of following types with `native` implementation:
586
588
}
587
589
```
588
590
589
-
The image is tinted by default.
591
+
Set `tinted` to `false` if the image has its own colors that you want to preserve.
592
+
593
+
The image is tinted by default. Overriding is only supported on iOS for the `native` implementation, all platforms for the `custom` implementation.
590
594
591
595
-[SF Symbols](https://developer.apple.com/sf-symbols/) name - Supported on iOS
@@ -13,20 +13,17 @@ This guide covers customizing the tab bar in [`createBottomTabNavigator`](bottom
13
13
14
14
This is similar to how you would customize a stack navigator — there are some properties that are set when you initialize the tab navigator and others that can be customized per-screen in `options`.
15
15
16
-
<TabsgroupId="config"queryString="config">
17
-
<TabItemvalue="static"label="Static"default>
16
+
Icons can be specified using the [`tabBarIcon`](bottom-tab-navigator.md#tabbaricon) option. The format of the icon varies based on the platform:
18
17
19
-
```js name="Tab bar icons" snack dependencies=@expo/vector-icons,@expo/vector-icons/Ionicons
-[`tabBarIcon`](bottom-tab-navigator.md#tabbaricon) is a supported option in bottom tab navigator. So we know we can use it on our screen components in the `options` prop.
99
+
-`tabBarIcon` is an object specifying the icon to display.
100
+
- For iOS, you can use SF Symbols by setting `type: 'sfSymbol'` and providing the symbol `name`.
101
+
- For other platforms, use `type: 'image'` with a `source` pointing to your image file. Image files must be provided for multiple screen densities (1x, 2x, 3x), e.g.: `home-icon.png`, `[email protected]`, `[email protected]`.
102
+
-[`Platform.select`](https://reactnative.dev/docs/platform#select) can be used to provide different icons based on the platform.
103
+
- The `tabBarActiveTintColor` and `tabBarInactiveTintColor` options in `screenOptions` control the icon and label colors. These default to the iOS platform defaults, but you can change them as shown above.
104
+
- Read the [full API reference](bottom-tab-navigator.md) for further information on `createBottomTabNavigator` configuration options.
95
105
96
-
// codeblock-focus-end
106
+
### Different icons for active and inactive states
This not supported on Android with `native`[implementation](bottom-tab-navigator.md#implementation), the icon specified for inactive state will be used for both active and inactive states.
147
124
148
-
exportdefaultfunctionApp() {
149
-
return (
150
-
<NavigationContainer>
151
-
<RootTabs />
152
-
</NavigationContainer>
153
-
);
154
-
}
155
-
```
125
+
### Using [React Native Vector Icons](https://github.com/oblador/react-native-vector-icons)
156
126
157
-
</TabItem>
158
-
</Tabs>
127
+
The React Native Vector Icons library provides a large set of icons. To use vector icons in your tab bar, we'd need to [get an image source](https://github.com/oblador/react-native-vector-icons?tab=readme-ov-file#usage-as-png-imagesource-object) from the icon component.
159
128
160
-
Let's dissect this:
129
+
First, make sure to install the appropriate icon package (e.g. `@react-native-vector-icons/material-design-icons`) and `@react-native-vector-icons/get-image` and rebuild the app after installation. Then, you can use the `getImageSourceSync` method to get the image source for the desired icon:
161
130
162
-
-`tabBarIcon` is a supported option in bottom tab navigator. So we know we can use it on our screen components in the `options` prop, but in this case chose to put it in the `screenOptions` prop of `Tab.Navigator` in order to centralize the icon configuration for convenience.
163
-
-`tabBarIcon` is a function that is given the `focused` state, `color`, and `size` params. If you take a peek further down in the configuration you will see `tabBarActiveTintColor` and `tabBarInactiveTintColor`. These default to the iOS platform defaults, but you can change them here. The `color` that is passed through to the `tabBarIcon` is either the active or inactive one, depending on the `focused` state (focused is active). The `size` is the size of the icon expected by the tab bar.
164
-
- Read the [full API reference](bottom-tab-navigator.md) for further information on `createBottomTabNavigator` configuration options.
From UI perspective this component is ready to use, but you still need to find some way to pass down the badge count properly from somewhere else, like using [React Context](https://react.dev/reference/react/use):
From UI perspective this component is ready to use, but you still need to find some way to pass down the badge count properly from somewhere else, like using [React Context](https://react.dev/reference/react/useContext), [Redux](https://redux.js.org/), [MobX](https://mobx.js.org/) or [event emitters](https://github.com/facebook/react-native/blob/master/Libraries/vendor/emitter/EventEmitter.js).
277
-
278
205
You can also update the badge from within the screen component by using the `setOptions` method:
Similar to `options`, you can also pass a function to `screenOptions`. The function will receive the [`navigation` object](navigation-object.md) and the [`route` object](route-object.md) for each screen. This can be useful if you want to configure options for all the screens in one place based on the route:
313
313
314
-
```js name="Screen options for tab navigator" snack dependencies=@expo/vector-icons static2dynamic
314
+
```js name="Screen options for tab navigator" snack static2dynamic
0 commit comments