Skip to content

Commit b90b1f2

Browse files
committed
Update docs for icons
1 parent 3b5d606 commit b90b1f2

File tree

3 files changed

+106
-7
lines changed

3 files changed

+106
-7
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,37 @@ Note that this style is not applied to the header by default since you control t
596596

597597
Whether to show or hide the header for the screen. The header is shown by default. Setting this to `false` hides the header.
598598

599+
#### `headerLeft`
600+
601+
Custom element to display on the left side of the header. By default, renders a menu icon with the `DrawerToggleButton` component:
602+
603+
```js
604+
import { DrawerToggleButton } from '@react-navigation/drawer';
605+
606+
// ...
607+
608+
headerLeft: (props) => <DrawerToggleButton {...props} />;
609+
```
610+
611+
To customize the icon, you can use the `icon` prop of `DrawerToggleButton` component. It can be a function that returns a React Element or an icon object:
612+
613+
```js
614+
import { DrawerToggleButton } from '@react-navigation/drawer';
615+
616+
// ...
617+
618+
headerLeft: (props) => (
619+
<DrawerToggleButton
620+
{...props}
621+
icon={({ color, size }) => (
622+
<MyCustomIcon name="menu" color={color} size={size} />
623+
)}
624+
/>
625+
);
626+
```
627+
628+
See [Icons](icons.md) documentation on how to use [SF Symbols](icons.md#sf-symbols) and [Material Symbols](icons.md#material-symbols).
629+
599630
### Events
600631

601632
The navigator can [emit events](navigation-events.md) on certain actions. Supported events are:

versioned_docs/version-8.x/icons.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,39 @@ Here are some common places where icons are used in React Navigation:
1111
- [`tabBarIcon`](bottom-tab-navigator.md#tabbaricon) option in Bottom Tab Navigator
1212
- [`headerBackIcon`](native-stack-navigator.md#headerbackicon) option in Native Stack Navigator
1313
- [`headerBackIcon`](stack-navigator.md#headerbackicon) option in Stack Navigator
14-
- [`backIcon`](elements.md#headerbackbutton) prop in `HeaderBackButton` component
14+
- [`icon`](elements.md#headerbackbutton) prop in `HeaderBackButton` component
15+
- [`icon`](drawer-navigator.md#headerleft) option in `DrawerToggleButton` component
1516

16-
There are 2 types of icons supported natively:
17+
Typically, components accept an icon object with a `type` property:
18+
19+
- [`sfSymbol`](#sf-symbols) (iOS only)
20+
21+
```js
22+
headerBackIcon: {
23+
type: 'sfSymbol',
24+
name: 'arrow.left',
25+
}
26+
```
27+
28+
- [`materialSymbol`](#material-symbols) (Android only)
29+
30+
```js
31+
headerBackIcon: {
32+
type: 'materialSymbol',
33+
name: 'arrow_back',
34+
}
35+
```
36+
37+
- `image`
38+
39+
```js
40+
headerBackIcon: {
41+
type: 'image',
42+
source: require('./path/to/icon.png'),
43+
}
44+
```
45+
46+
The `sfSymbol` and `materialSymbol` types use the respective system icon libraries on each platform. The `image` type allows you to use a custom image as an icon on any platform.
1747

1848
## SF Symbols
1949

@@ -180,7 +210,7 @@ tabBarIcon: {
180210
}
181211
```
182212

183-
The behavior differs depending on the weights and variants included in the bundle. If there is a single variant and weight included, it will be used by default. You don't need to specify the variant or weight in the icon object.
213+
The behavior differs depending on the weights and variants included in the bundle. If there is a single variant and weight included, it will be used by default. You don't need to specify the variant or weight in the icon object. The built-in icons such as icons in the header will also use the included variant and weight automatically.
184214

185215
If there are multiple variants or weights included, you can specify the `variant` and `weight` properties in the icon object to choose which one to use:
186216

versioned_docs/version-8.x/upgrading-from-7.x.md

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,26 @@ If you don't want to enable deep linking, you can set `linking.enabled` to `fals
633633
>
634634
```
635635

636+
#### `HeaderBackButton` and `DrawerToggleButton` components now accept an `icon` prop
637+
638+
Previously, the `HeaderBackButton` and `DrawerToggleButton` components accepted `backImage` and `imageSource` props respectively. In order to support the new icons such as [Material Symbols](https://fonts.google.com/icons) and [SF Symbols](https://developer.apple.com/sf-symbols/), these props have been replaced with a new `icon` prop.
639+
640+
If you're using a custom back image with `imageSource`, you can update your code as follows:
641+
642+
```diff lang=js
643+
- <HeaderBackButton backImage={require('./path/to/my-back-icon.png')} />
644+
+ <HeaderBackButton icon={{ type: 'image', source: require('./path/to/my-back-icon.png') }} />
645+
```
646+
647+
And for `DrawerToggleButton`:
648+
649+
```diff lang=js
650+
- <DrawerToggleButton imageSource={require('./path/to/my-drawer-icon.png')} />
651+
+ <DrawerToggleButton icon={{ type: 'image', source: require('./path/to/my-drawer-icon.png') }} />
652+
```
653+
654+
See [HeaderBackButton](elements.md#headerbackbutton) and [DrawerToggleButton](elements.md#drawertogglebutton) for more details.
655+
636656
#### Some exports are removed from `@react-navigation/elements`
637657

638658
The `@react-navigation/elements` package has exported some components that were primarily intended for internal usage. These components have been removed from the public API:
@@ -663,7 +683,20 @@ The `@react-navigation/elements` package has exported some components that were
663683

664684
You can copy the implementation from the [source code](https://github.com/react-navigation/react-navigation/blob/main/packages/elements/src/MissingIcon.tsx) if you need a placeholder icon.
665685

666-
Some of these components are still available and exported at `@react-navigation/elements/internal`, so you can continue using them if you really need. However, since they are not part of the public API, they don't follow semver and may change without warning in future releases.
686+
- `Assets`
687+
688+
This was an array of assets to preload with `expo-asset`. However since the built-in icons now render [Material Symbols](https://fonts.google.com/icons) on Android and [SF Symbols](https://developer.apple.com/sf-symbols/) on iOS instead of images, this is no longer needed.
689+
690+
If you were using this, you can remove it from your code:
691+
692+
```diff lang=js
693+
- import { Assets } from '@react-navigation/elements';
694+
- import { Asset } from 'expo-asset';
695+
-
696+
- Asset.loadAsync(Assets);
697+
```
698+
699+
Some of these exports are still available and exported at `@react-navigation/elements/internal`, so you can continue using them if you really need. However, since they are not part of the public API, they don't follow semver and may change without warning in future releases.
667700

668701
#### The `getDefaultHeaderHeight` utility now accepts an object instead of positional arguments
669702

@@ -909,8 +942,11 @@ Various navigators and components now support using [Material Symbols](https://f
909942

910943
For example,
911944

912-
- The `headerBackIcon` option in Stack and Native Stack Navigators
913-
- The `tabBarIcon` option in Bottom Tab Navigator
945+
- [`tabBarIcon`](bottom-tab-navigator.md#tabbaricon) option in Bottom Tab Navigator
946+
- [`headerBackIcon`](native-stack-navigator.md#headerbackicon) option in Native Stack Navigator
947+
- [`headerBackIcon`](stack-navigator.md#headerbackicon) option in Stack Navigator
948+
- [`icon`](elements.md#headerbackbutton) prop in `HeaderBackButton` component
949+
- [`icon`](drawer-navigator.md#headerleft) option in `DrawerToggleButton` component
914950

915951
Usage:
916952

@@ -927,7 +963,9 @@ tabBarIcon: Platform.select({
927963
}),
928964
```
929965

930-
In addition, new `SFSymbol` and `MaterialSymbol` components are exported from `@react-navigation/native` to render these icons directly. See [Icons](icons.md) for more details.
966+
In addition, new `SFSymbol` and `MaterialSymbol` components are exported from `@react-navigation/native` to render these icons directly.
967+
968+
See [Icons](icons.md) for more details.
931969

932970
### `react-native-tab-view` now supports a `renderAdapter` prop for custom adapters
933971

0 commit comments

Comments
 (0)