Skip to content

Commit e36c05d

Browse files
committed
Mention images and vector icons in icons docs
1 parent 52d0738 commit e36c05d

2 files changed

Lines changed: 53 additions & 17 deletions

File tree

versioned_docs/version-8.x/customizing-bottom-tabs.md

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ Let's dissect this:
112112
- 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.
113113
- Read the [full API reference](bottom-tab-navigator.md) for further information on `createBottomTabNavigator` configuration options.
114114

115+
See [Icons](icons.md) for more details on different icon types and how to use them with React Navigation.
116+
115117
### Different icons for active and inactive states
116118

117119
You can also provide different icons for active and inactive states by using a function for the `tabBarIcon` option:
@@ -131,23 +133,6 @@ The `focused` parameter indicates whether the tab is active or inactive.
131133

132134
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.
133135

134-
### Using [React Native Vector Icons](https://github.com/oblador/react-native-vector-icons)
135-
136-
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.
137-
138-
First, make sure to install the appropriate icon package (e.g. `@react-native-vector-icons/lucide`) 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:
139-
140-
```js
141-
import { Lucide } from '@react-native-vector-icons/lucide';
142-
143-
// ...
144-
145-
tabBarIcon: {
146-
type: 'image',
147-
source: Lucide.getImageSourceSync('heart', 22),
148-
},
149-
```
150-
151136
## Add badges to tab items
152137

153138
Sometimes we want to add badges to some tabs. You can use the [`tabBarBadge` option](bottom-tab-navigator.md#tabbarbadge) to do it:

versioned_docs/version-8.x/icons.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,54 @@ The component accepts the following props:
440440
- `"bold"` (`700`)
441441

442442
The available weights depend on which weights are included in the bundle. If the specified weight is not included, it will throw an error.
443+
444+
## Other sources
445+
446+
### Images
447+
448+
React Navigation also supports using images as icons. It supports the same formats as React Native's [`Image`](https://reactnative.dev/docs/image) component.
449+
450+
You can use the `type: 'image'` option with a `source` property pointing to your image file:
451+
452+
```js
453+
tabBarIcon: {
454+
type: 'image',
455+
source: require('./path/to/icon.png'),
456+
}
457+
```
458+
459+
:::note
460+
461+
It's necessary to provide icons for multiple screen densities (1x, 2x, 3x), e.g.: `icon.png`, `icon@2x.png`, `icon@3x.png`, as icons are not scaled automatically on iOS.
462+
463+
:::
464+
465+
Images also include [drawable resources](https://developer.android.com/guide/topics/resources/drawable-resource) on Android and [asset catalogs](https://developer.apple.com/documentation/xcode/adding-images-to-your-xcode-project) on iOS, which can be specified using `uri`:
466+
467+
```js
468+
tabBarIcon: {
469+
type: 'image',
470+
source: { uri: 'icon_name' },
471+
}
472+
```
473+
474+
Here `icon_name` is the resource name without the file extension. On Android, this can refer to a bitmap drawable such as `res/drawable/icon_name.png` or a vector drawable such as `res/drawable/icon_name.xml`. On iOS, this can refer to an image in an asset catalog, such as an image set named `icon_name`.
475+
476+
### [React Native Vector Icons](https://github.com/oblador/react-native-vector-icons)
477+
478+
The React Native Vector Icons library provides a large set of icons. However, these icons are rendered using custom fonts, which are not supported in most native navigation components such as tab bars or headers.
479+
480+
As an alternative, you can [rasterize the icon into an image source](https://github.com/oblador/react-native-vector-icons?tab=readme-ov-file#usage-as-png-imagesource-object). This image can then be used as an icon in such components using the `type: 'image'` option.
481+
482+
First, install the appropriate icon package, such as `@react-native-vector-icons/lucide`, along with `@react-native-vector-icons/get-image`. Then rebuild the app and use `getImageSourceSync` to create the image source:
483+
484+
```js
485+
import { Lucide } from '@react-native-vector-icons/lucide';
486+
487+
// ...
488+
489+
tabBarIcon: {
490+
type: 'image',
491+
source: Lucide.getImageSourceSync('heart', 22),
492+
},
493+
```

0 commit comments

Comments
 (0)