Skip to content

Commit 11f081d

Browse files
committed
Update documentation for icons
1 parent 8f07b82 commit 11f081d

File tree

8 files changed

+204
-56
lines changed

8 files changed

+204
-56
lines changed

versioned_docs/version-7.x/native-stack-navigator.md

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ If the content's height is less than the sheet's height, the remaining area may
16171617
16181618
## Header items
16191619
1620-
The [`unstable_headerLeftItems`](#unstable_headerleftitems) and [`unstable_headerRightItems`](#unstable_headerrightitems) options allow you to add header items to the left and right side of the header respectively. This items can show native buttons, menus or custom React elements.
1620+
The [`unstable_headerLeftItems`](#unstable_headerleftitems) and [`unstable_headerRightItems`](#unstable_headerrightitems) options allow you to add header items to the left and right side of the header respectively. These items can show native buttons, menus or custom React elements.
16211621
16221622
On iOS 26+, the header right items can also be collapsed into an overflow menu by the system when there is not enough space to show all items. Note that custom elements (with `type: 'custom'`) won't be collapsed into the overflow menu.
16231623
@@ -1642,7 +1642,7 @@ Common properties:
16421642
- `color` (of type `ColorValue`)
16431643
- `icon`: Optional icon to show instead of the label.
16441644
1645-
The icon can be of following types:
1645+
The icon can be one of the following types:
16461646
- Local image
16471647
16481648
```js
@@ -1657,7 +1657,7 @@ Common properties:
16571657
It also supports [xcasset](https://developer.apple.com/documentation/xcode/adding-images-to-your-xcode-project):
16581658
16591659
```js
1660-
tabBarIcon: {
1660+
icon: {
16611661
type: 'image',
16621662
source: { uri: 'icon_name' },
16631663
}
@@ -1666,7 +1666,7 @@ Common properties:
16661666
A `tinted` property can be used to control whether the icon should be tinted with the active/inactive color:
16671667
16681668
```js
1669-
tabBarIcon: {
1669+
icon: {
16701670
type: 'image',
16711671
source: require('./path/to/icon.png'),
16721672
tinted: false,
@@ -1742,14 +1742,7 @@ Supported properties when `type` is `menu`:
17421742
- `type`: Must be `action`.
17431743
- `label`: Label of the menu item.
17441744
- `description`: The secondary text displayed alongside the label of the menu item.
1745-
- `icon`: Optional icon to show alongside the label. The icon can be a [SF Symbols](https://developer.apple.com/sf-symbols/) name:
1746-
1747-
```js
1748-
{
1749-
type: 'sfSymbol',
1750-
name: 'trash',
1751-
}
1752-
```
1745+
- `icon`: Optional icon to show alongside the label. It accepts the same formats as `icon` above.
17531746
17541747
- `onPress`: Function to call when the menu item is pressed.
17551748
- `state`: Optional state of the menu item. Supported values:
@@ -1765,14 +1758,7 @@ Supported properties when `type` is `menu`:
17651758
- `submenu`: An object with the following properties:
17661759
- `type`: Must be `submenu`.
17671760
- `label`: Label of the submenu item.
1768-
- `icon`: Optional icon to show alongside the label. The icon can be a [SF Symbols](https://developer.apple.com/sf-symbols/) name:
1769-
1770-
```js
1771-
{
1772-
type: 'sfSymbol',
1773-
name: 'pencil',
1774-
}
1775-
```
1761+
- `icon`: Optional icon to show alongside the label. It accepts the same formats as `icon` above.
17761762
17771763
- `inline`: Whether the menu is displayed inline with the parent menu. By default, submenus are displayed after expanding the parent menu item. Inline menus are displayed as part of the parent menu as a section. Defaults to `false`.
17781764
- `layout`: How the submenu items are displayed. Supported values:

versioned_docs/version-8.x/bottom-tab-navigator.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,14 @@ tabBarIcon: ({ focused }) => {
625625

626626
This not supported on Android with `native` implementation, the icon specified for inactive state will be used for both active and inactive states.
627627

628+
With `custom` implementation, you can also return a React element:
629+
630+
```js
631+
tabBarIcon: ({ color, size }) => (
632+
<MyCustomIcon color={color} size={size} />
633+
),
634+
```
635+
628636
To provide different icons for different platforms, you can use [`Platform.select`](https://reactnative.dev/docs/platform-specific-code):
629637

630638
```js

versioned_docs/version-8.x/drawer-navigator.md

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,12 @@ export default function App() {
229229
}
230230
```
231231

232+
### `DrawerItem`
233+
232234
The `DrawerItem` component accepts the following props:
233235

234236
- `label` (required): The label text of the item. Can be string, or a function returning a react element. e.g. `({ focused, color }) => <Text style={{ color }}>{focused ? 'Focused text' : 'Unfocused text'}</Text>`.
235-
- `icon`: Icon to display for the item. Accepts a function returning a react element. e.g. `({ focused, color, size }) => <Icon color={color} size={size} name={focused ? 'heart' : 'heart-outline'} />`.
237+
- `icon`: Icon to display for the item. Accepts an icon object, or a function returning an icon object or a React element. See [Icons](icons.md) for supported icon formats.
236238
- `focused`: Boolean indicating whether to highlight the drawer item as active.
237239
- `onPress` (required): Function to execute on press.
238240
- `activeTintColor`: Color for the icon and label when the item is active.
@@ -300,7 +302,86 @@ String or a function that given `{ focused: boolean, color: string }` returns a
300302

301303
#### `drawerIcon`
302304

303-
Function, that given `{ focused: boolean, color: string, size: number }` returns a React.Node to display in drawer sidebar.
305+
Icon object to display or a function that given `{ focused: boolean, color: string, size: number }` returns an icon to display in drawer sidebar.
306+
307+
It supports the following types:
308+
309+
- `materialSymbol` (Android only)
310+
311+
```js
312+
drawerIcon: {
313+
type: 'materialSymbol',
314+
name: 'favorite',
315+
}
316+
```
317+
318+
It also supports the following optional properties:
319+
- `variant` - Supported values: `outlined`, `rounded`, `sharp`
320+
- `weight` - Supported values: `100`, `200`, `300`, `400`, `500`, `600`, `700`
321+
322+
See [Icons](icons.md#material-symbols) for more details.
323+
324+
- `sfSymbol` (iOS only)
325+
326+
```js
327+
drawerIcon: {
328+
type: 'sfSymbol',
329+
name: 'heart',
330+
}
331+
```
332+
333+
See [Icons](icons.md#sf-symbols) for more details.
334+
335+
- `image`
336+
337+
```js
338+
drawerIcon: {
339+
type: 'image',
340+
source: require('./path/to/icon.png'),
341+
}
342+
```
343+
344+
It also supports [drawable resource](https://developer.android.com/guide/topics/resources/drawable-resource) on Android, [xcasset](https://developer.apple.com/documentation/xcode/adding-images-to-your-xcode-project) on iOS:
345+
346+
```js
347+
drawerIcon: {
348+
type: 'image',
349+
source: { uri: 'icon_name' },
350+
}
351+
```
352+
353+
A `tinted` property can be used to control whether the icon should be tinted with the active/inactive color:
354+
355+
```js
356+
drawerIcon: {
357+
type: 'image',
358+
source: require('./path/to/icon.png'),
359+
tinted: false,
360+
}
361+
```
362+
363+
Set `tinted` to `false` if the image has its own colors that you want to preserve.
364+
365+
The image is tinted by default.
366+
367+
In addition to the icon object, you can also provide a function which returns an icon object or a React element. It receives `focused`, `color`, and `size` in its argument object:
368+
369+
```js
370+
drawerIcon: ({ focused }) => {
371+
return {
372+
type: 'sfSymbol',
373+
name: focused ? 'heart.fill' : 'heart',
374+
};
375+
},
376+
```
377+
378+
To render a custom React element, you can return it from the function:
379+
380+
```js
381+
drawerIcon: ({ color, size }) => (
382+
<MyCustomIcon color={color} size={size} />
383+
),
384+
```
304385

305386
#### `drawerActiveTintColor`
306387

versioned_docs/version-8.x/elements.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ A component used to show the back button header. It's the default for [`headerLe
668668
- `disabled` - Boolean which controls Whether the button is disabled.
669669
- `onPress` - Callback to call when the button is pressed.
670670
- `pressColor` - Color for material ripple (Android >= 5.0 only).
671-
- `backIcon` - Icon to display custom icon in header's back button. See [Custom back icon](#custom-back-icon) section for more details.
671+
- `icon` - Icon to display custom icon in header's back button. See [Custom back icon](#custom-back-icon) section for more details.
672672
- `tintColor` - Tint color for the header.
673673
- `label` - Label text for the button. Usually the title of the previous screen. By default, this is only shown on iOS.
674674
- `truncatedLabel` - Label text to show when there isn't enough space for the full label.
@@ -694,17 +694,17 @@ Usage:
694694

695695
#### Custom back icon
696696

697-
The `backIcon` prop accepts an icon object for SF Symbols on iOS, Material Symbols on Android and image source on all platforms:
697+
The `icon` prop accepts an icon object for SF Symbols on iOS, Material Symbols on Android and image source on all platforms:
698698

699699
```js
700700
<HeaderBackButton
701-
backIcon={Platform.select({
701+
icon={Platform.select({
702702
ios: {
703-
type: 'sf-symbol',
703+
type: 'sfSymbol',
704704
name: 'arrow.left',
705705
},
706706
android: {
707-
type: 'material-symbol',
707+
type: 'materialSymbol',
708708
name: 'arrow_back',
709709
},
710710
default: {
@@ -722,7 +722,7 @@ It can also be a function that returns a React Element to render any component:
722722

723723
```js
724724
<HeaderBackButton
725-
backIcon={({ tintColor }) => (
725+
icon={({ tintColor }) => (
726726
<MyCustomBackIconComponent tintColor={tintColor} />
727727
)}
728728
onPress={() => console.log('back pressed')}

versioned_docs/version-8.x/icons.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ Many components in React Navigation accept icons to customize their appearance.
99
Here are some common places where icons are used in React Navigation:
1010

1111
- [`tabBarIcon`](bottom-tab-navigator.md#tabbaricon) option in Bottom Tab Navigator
12+
- [`tabBarIcon`](material-top-tab-navigator.md#tabbaricon) option in Material Top Tabs Navigator
13+
- [`drawerIcon`](drawer-navigator.md#drawericon) option in Drawer Navigator
14+
- [`icon`](drawer-navigator.md#draweritem) prop in `DrawerItem` component
1215
- [`headerBackIcon`](native-stack-navigator.md#headerbackicon) option in Native Stack Navigator
1316
- [`headerBackIcon`](stack-navigator.md#headerbackicon) option in Stack Navigator
1417
- [`icon`](elements.md#headerbackbutton) prop in `HeaderBackButton` component
15-
- [`icon`](drawer-navigator.md#headerleft) option in `DrawerToggleButton` component
18+
- [`icon`](drawer-navigator.md#headerleft) prop in `DrawerToggleButton` component
19+
- [`icon`](native-stack-navigator.md#header-items) property in Native Stack header items (iOS only, `image` and `sfSymbol` only)
1620

1721
Typically, components accept an icon object with a `type` property:
1822

@@ -49,7 +53,7 @@ The `sfSymbol` and `materialSymbol` types use the respective system icon librari
4953

5054
SF Symbols is a library of over 6,900 symbols designed to integrate well with the San Francisco system font on Apple platforms. It comes included with iOS and other Apple platforms.
5155

52-
Options such as `tabBarIcon` and `headerBackIcon` accept an object with `type: 'sfSymbol'` and a `name` property to specify the SF Symbol to use:
56+
Where SF Symbols are supported, icon options and props accept an object with `type: 'sfSymbol'` and a `name` property to specify the SF Symbol to use:
5357

5458
```js
5559
tabBarIcon: {
@@ -205,7 +209,7 @@ You'll need to rebuild your app after changing the font configuration in `packag
205209

206210
:::
207211

208-
Options such as `tabBarIcon` and `headerBackIcon` accept an object with `type: 'materialSymbol'` and a `name` property to specify the Material Symbol to use:
212+
Where Material Symbols are supported, icon options and props accept an object with `type: 'materialSymbol'` and a `name` property to specify the Material Symbol to use:
209213

210214
```js
211215
tabBarIcon: {

versioned_docs/version-8.x/material-top-tab-navigator.md

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,86 @@ Whether the tab label should be visible. Defaults to `true`.
409409

410410
#### `tabBarIcon`
411411

412-
Function that given `{ focused: boolean, color: string }` returns a React.Node, to display in the tab bar.
412+
Icon object to display or a function that given `{ focused: boolean, color: string, size: number }` returns an icon to display in the tab bar.
413+
414+
It supports the following types:
415+
416+
- `materialSymbol` (Android only)
417+
418+
```js
419+
tabBarIcon: {
420+
type: 'materialSymbol',
421+
name: 'favorite',
422+
}
423+
```
424+
425+
It also supports the following optional properties:
426+
- `variant` - Supported values: `outlined`, `rounded`, `sharp`
427+
- `weight` - Supported values: `100`, `200`, `300`, `400`, `500`, `600`, `700`
428+
429+
See [Icons](icons.md#material-symbols) for more details.
430+
431+
- `sfSymbol` (iOS only)
432+
433+
```js
434+
tabBarIcon: {
435+
type: 'sfSymbol',
436+
name: 'heart',
437+
}
438+
```
439+
440+
See [Icons](icons.md#sf-symbols) for more details.
441+
442+
- `image`
443+
444+
```js
445+
tabBarIcon: {
446+
type: 'image',
447+
source: require('./path/to/icon.png'),
448+
}
449+
```
450+
451+
It also supports [drawable resource](https://developer.android.com/guide/topics/resources/drawable-resource) on Android, [xcasset](https://developer.apple.com/documentation/xcode/adding-images-to-your-xcode-project) on iOS:
452+
453+
```js
454+
tabBarIcon: {
455+
type: 'image',
456+
source: { uri: 'icon_name' },
457+
}
458+
```
459+
460+
A `tinted` property can be used to control whether the icon should be tinted with the active/inactive color:
461+
462+
```js
463+
tabBarIcon: {
464+
type: 'image',
465+
source: require('./path/to/icon.png'),
466+
tinted: false,
467+
}
468+
```
469+
470+
Set `tinted` to `false` if the image has its own colors that you want to preserve.
471+
472+
The image is tinted by default.
473+
474+
In addition to the icon object, you can also provide a function which returns an icon object or a React element. It receives `focused`, `color`, and `size` in its argument object:
475+
476+
```js
477+
tabBarIcon: ({ focused }) => {
478+
return {
479+
type: 'sfSymbol',
480+
name: focused ? 'heart.fill' : 'heart',
481+
};
482+
},
483+
```
484+
485+
To render a custom React element, you can return it from the function:
486+
487+
```js
488+
tabBarIcon: ({ color, size }) => (
489+
<MyCustomIcon color={color} size={size} />
490+
),
491+
```
413492

414493
#### `tabBarShowIcon`
415494

0 commit comments

Comments
 (0)