Skip to content

Commit 60cee43

Browse files
committed
Document headerLeftItems & headerRightItems
1 parent 1391586 commit 60cee43

File tree

3 files changed

+254
-2
lines changed

3 files changed

+254
-2
lines changed
130 KB
Loading
42.6 KB
Loading

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

Lines changed: 254 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,12 @@ Tint color for the header. Changes the color of back button and title.
415415

416416
#### `headerLeft`
417417

418-
Function which returns a React Element to display on the left side of the header. This replaces the back button. See `headerBackVisible` to show the back button along side left element.
418+
Function which returns a React Element to display on the left side of the header. This replaces the back button. See `headerBackVisible` to show the back button along side left element. It receives the following properties in the arguments:
419+
420+
- `tintColor` - The tint color to apply. Defaults to the [theme](themes.md)'s primary color.
421+
- `canGoBack` - Boolean indicating whether there is a screen to go back to.
422+
- `label` - Label text for the button. Usually the title of the previous screen.
423+
- `href` - The `href` to use for the anchor tag on web
419424

420425
<img src="/assets/7.x/native-stack/headerLeft.png" width="500" alt="Header right"/>
421426

@@ -429,9 +434,43 @@ Example:
429434
headerBackTitle: 'Back',
430435
```
431436

437+
#### `unstable_headerLeftItems`
438+
439+
:::warning
440+
441+
This option is experimental and may change in a minor release.
442+
443+
:::
444+
445+
Function which returns an array of items to display as on the left side of the header. This will override `headerLeft` if both are specified. It receives the following properties in the arguments:
446+
447+
- `tintColor` - The tint color to apply. Defaults to the [theme](themes.md)'s primary color.
448+
- `canGoBack` - Boolean indicating whether there is a screen to go back to.
449+
450+
Example:
451+
452+
```js
453+
unstable_headerLeftItems: () => [
454+
{
455+
type: 'button',
456+
title: 'Edit',
457+
onPress: () => {
458+
// Do something
459+
},
460+
},
461+
],
462+
```
463+
464+
See [Header items](#header-items) for more information.
465+
466+
Only supported on iOS.
467+
432468
#### `headerRight`
433469

434-
Function which returns a React Element to display on the right side of the header.
470+
Function which returns a React Element to display on the right side of the header. It receives the following properties in the arguments:
471+
472+
- `tintColor` - The tint color to apply. Defaults to the [theme](themes.md)'s primary color.
473+
- `canGoBack` - Boolean indicating whether there is a screen to go back to.
435474

436475
<img src="/assets/7.x/native-stack/headerRight.png" width="500" alt="Header right"/>
437476

@@ -441,6 +480,37 @@ Example:
441480
headerRight: () => <MaterialCommunityIcons name="map" color="blue" size={36} />;
442481
```
443482

483+
#### `unstable_headerRightItems`
484+
485+
:::warning
486+
487+
This option is experimental and may change in a minor release.
488+
489+
:::
490+
491+
Function which returns an array of items to display as on the right side of the header. This will override `headerRight` if both are specified. It receives the following properties in the arguments:
492+
493+
- `tintColor` - The tint color to apply. Defaults to the [theme](themes.md)'s primary color.
494+
- `canGoBack` - Boolean indicating whether there is a screen to go back to.
495+
496+
Example:
497+
498+
```js
499+
unstable_headerRightItems: () => [
500+
{
501+
type: 'button',
502+
title: 'Edit',
503+
onPress: () => {
504+
// Do something
505+
},
506+
},
507+
],
508+
```
509+
510+
See [Header items](#header-items) for more information.
511+
512+
Only supported on iOS.
513+
444514
#### `headerTitle`
445515

446516
String or a function that returns a React Element to be used by the header. Defaults to `title` or name of the screen.
@@ -1430,3 +1500,185 @@ const MyView = () => {
14301500
);
14311501
};
14321502
```
1503+
1504+
## Header items
1505+
1506+
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.
1507+
1508+
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.
1509+
1510+
<img src="/assets/header-items/header-items.png" width="300" alt="Header items" />
1511+
1512+
<img src="/assets/header-items/header-items-menu.png" width="300" alt="Header item with menu" />
1513+
1514+
There are 3 categories of items that can be displayed in the header:
1515+
1516+
### Action
1517+
1518+
A regular button that performs an action when pressed, or shows a menu.
1519+
1520+
Common properties:
1521+
1522+
- `type`: Must be `button` or `menu`.
1523+
- `label`: Label of the item. The label is not shown if `icon` is specified. However, it is used by screen readers, or if the header items get collapsed due to lack of space.
1524+
- `labelStyle`: Style object for the label. Supported properties:
1525+
- `fontFamily`
1526+
- `fontSize`
1527+
- `fontWeight`
1528+
- `color`
1529+
- `icon`: Optional icon to show instead of the label.
1530+
- `variant`: Visual variant of the button. Supported values:
1531+
- `plain` (default)
1532+
- `done`
1533+
- `prominent`
1534+
- `tintColor`: Tint color to apply to the item.
1535+
- `disabled`: Whether the item is disabled.
1536+
- `width`: Width of the item.
1537+
- `hidesSharedBackground` (iOS 26+): Whether the background this item may share with other items should be hidden. Setting this to `true` hides the liquid glass background.
1538+
- `sharesBackground` (iOS 26+): Whether this item can share a background with other items.
1539+
- `identifier` (iOS 26+) - An identifier used to match items across transitions.
1540+
- `badge`: An optional badge to display alongside the item. Supported properties:
1541+
- `value`: The value to display in the badge. It can be a string or a number.
1542+
- `style`: Style object for the badge. Supported properties:
1543+
- `fontFamily`
1544+
- `fontSize`
1545+
- `fontWeight`
1546+
- `color`
1547+
- `accessibilityLabel`: Accessibility label for the item.
1548+
- `accessibilityHint`: Accessibility hint for the item.
1549+
1550+
Supported properties when `type` is `button`:
1551+
1552+
- `onPress`: Function to call when the button is pressed.
1553+
- `selected`: Whether the button is in a selected state.
1554+
1555+
Example:
1556+
1557+
```js
1558+
unstable_headerLeftItems: () => [
1559+
{
1560+
type: 'button',
1561+
label: 'Edit',
1562+
onPress: () => {
1563+
// Do something
1564+
},
1565+
},
1566+
],
1567+
```
1568+
1569+
Supported properties when `type` is `menu`:
1570+
1571+
- `menu`: An object containing the menu items. It contains the following properties:
1572+
- `title`: Optional title to show on top of the menu.
1573+
- `items`: An array of menu items. A menu item can be either an `action` or a `submenu`.
1574+
- `action`: An object with the following properties:
1575+
- `type`: Must be `action`.
1576+
- `label`: Label of the menu item.
1577+
- `icon`: Optional icon to show alongside the label.
1578+
- `onPress`: Function to call when the menu item is pressed.
1579+
- `state`: Optional state of the menu item. Supported values:
1580+
- `on`
1581+
- `off`
1582+
- `mixed`
1583+
- `disabled`: Whether the menu item is disabled.
1584+
- `destructive`: Whether the menu item is styled as destructive.
1585+
- `hidden`: Whether the menu item is hidden.
1586+
- `keepsMenuPresented`: Whether to keep the menu open after selecting this item. Defaults to `false`.
1587+
- `discoverabilityLabel`: An elaborated title that explains the purpose of the action.
1588+
- `submenu`: An object with the following properties:
1589+
- `type`: Must be `submenu`.
1590+
- `label`: Label of the submenu item.
1591+
- `icon`: Optional icon to show alongside the label.
1592+
- `items`: An array of menu items (can be either `action` or `submenu`).
1593+
1594+
Example:
1595+
1596+
```js
1597+
unstable_headerLeftItems: () => [
1598+
{
1599+
type: 'menu',
1600+
label: 'Options',
1601+
menu: {
1602+
title: 'Options',
1603+
items: [
1604+
{
1605+
type: 'action',
1606+
label: 'Edit',
1607+
onPress: () => {
1608+
// Do something
1609+
},
1610+
},
1611+
{
1612+
type: 'submenu',
1613+
label: 'More',
1614+
items: [
1615+
{
1616+
type: 'action',
1617+
label: 'Delete',
1618+
destructive: true,
1619+
onPress: () => {
1620+
// Do something
1621+
},
1622+
},
1623+
],
1624+
},
1625+
],
1626+
},
1627+
},
1628+
],
1629+
```
1630+
1631+
### Spacing
1632+
1633+
An item to add spacing between other items in the header.
1634+
1635+
Supported properties:
1636+
1637+
- `type`: Must be `spacing`.
1638+
- `spacing`: Amount of spacing to add.
1639+
1640+
```js
1641+
unstable_headerLeftItems: () => [
1642+
{
1643+
type: 'button',
1644+
label: 'Edit',
1645+
onPress: () => {
1646+
// Do something
1647+
},
1648+
},
1649+
{
1650+
type: 'spacing',
1651+
spacing: 10,
1652+
},
1653+
{
1654+
type: 'button',
1655+
label: 'Delete',
1656+
onPress: () => {
1657+
// Do something
1658+
},
1659+
},
1660+
],
1661+
```
1662+
1663+
### Custom
1664+
1665+
A custom item to display any React Element in the header.
1666+
1667+
Supported properties:
1668+
1669+
- `type`: Must be `custom`.
1670+
- `element`: A React Element to display as the item.
1671+
- `hidesSharedBackground`: Whether the background this item may share with other items in the bar should be hidden. Setting this to `true` hides the liquid glass background on iOS 26+.
1672+
1673+
Example:
1674+
1675+
```js
1676+
unstable_headerLeftItems: () => [
1677+
{
1678+
type: 'custom',
1679+
element: <MaterialCommunityIcons name="map" color="gray" size={36} />,
1680+
},
1681+
],
1682+
```
1683+
1684+
The advantage of using this over [`headerLeft`](#headerleft) or [`headerRight`](#headerright) options is it supports features like shared background on iOS 26+.

0 commit comments

Comments
 (0)