Skip to content

Commit 50b6d99

Browse files
committed
Document more updates
1 parent 001e32c commit 50b6d99

7 files changed

Lines changed: 224 additions & 13 deletions

File tree

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,13 @@ function CustomDrawerContent(props) {
206206
}
207207
```
208208

209+
The `DrawerContentScrollView` component applies safe are insets automatically:
210+
211+
- On iOS, it sets `contentInsetAdjustmentBehavior="automatic"`
212+
- On other platforms, it adjusts paddings of the scrollable content
213+
214+
You can override the default behavior by passing `contentInsetAdjustmentBehavior='never'` on iOS `contentContainerStyle` with custom paddings on other platforms.
215+
209216
To add additional items in the drawer, you can use the `DrawerItem` component:
210217

211218
```js name="Custom Drawer Content" snack static2dynamic
@@ -667,12 +674,13 @@ Style object for the component wrapping the screen content.
667674

668675
#### `configureGestureHandler`
669676

670-
Callback to configure the underlying [gesture from `react-native-gesture-handler`](https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/gesture). It receives the `gesture` object as an argument:
677+
Callback to configure the underlying [pan gesture from `react-native-gesture-handler`](https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/gesture). It receives the gesture configuration and should return the updated configuration:
671678

672679
```js
673-
configureGestureHandler: ({ gesture }) => {
674-
return gesture.enableTrackpadTwoFingerGesture(false);
675-
},
680+
configureGestureHandler: (config) => ({
681+
...config,
682+
enableTrackpadTwoFingerGesture: false,
683+
}),
676684
```
677685

678686
This is not supported on Web.

versioned_docs/version-8.x/elements.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,43 @@ A component which provides an abstraction on top of [`Pressable`](https://reactn
711711
- `pressColor` - Color of material ripple on Android when it's pressed
712712
- `pressOpacity` - Opacity when it's pressed if material ripple isn't supported by the platform
713713

714+
### `PlatformIcon`
715+
716+
A component that renders an [icon object](icons.md) with a consistent API across platforms. It accepts the following props:
717+
718+
- `icon` - Icon object to render. It can contain an image, an SF Symbol, or a Material Symbol.
719+
- `size` - Size of the icon.
720+
- `color` - Color to apply to the icon.
721+
- `style` - Style object for the icon.
722+
723+
Example:
724+
725+
```js
726+
import { PlatformIcon } from '@react-navigation/elements';
727+
import { Platform } from 'react-native';
728+
729+
// ...
730+
731+
<PlatformIcon
732+
icon={Platform.select({
733+
ios: {
734+
type: 'sfSymbol',
735+
name: 'person',
736+
},
737+
android: {
738+
type: 'materialSymbol',
739+
name: 'person',
740+
},
741+
default: {
742+
type: 'image',
743+
source: require('./person.png'),
744+
},
745+
})}
746+
color="tomato"
747+
size={24}
748+
/>;
749+
```
750+
714751
### `Button`
715752

716753
A component that renders a button. In addition to [`PlatformPressable`](#platformpressable)'s props, it accepts following additional props:
@@ -721,6 +758,7 @@ A component that renders a button. In addition to [`PlatformPressable`](#platfor
721758
- `filled`
722759
- `color` - Color of the button. Defaults to the [theme](themes.md)'s primary color.
723760
- `icon` - Icon to display before the label. It can be an icon object or a function that returns an icon object or a React element. See [Icons](icons.md) for more details.
761+
- `loading` - Boolean which controls whether to show a loading indicator instead of the icon. The button is disabled while loading.
724762
- `disabled` - Boolean which controls whether the button is disabled.
725763
- `children` - Content to render inside the button. It must be a string or React element that can be nested inside a `Text` component.
726764

@@ -734,7 +772,9 @@ It can be used to navigate between screens by specifying a screen name and param
734772
</Button>
735773
```
736774

737-
Or as a regular button:
775+
When navigating to a screen this way, it automatically shows the loading indicator while the navigation transition is pending. You can pass `loading={false}` to disable the automatic loading indicator.
776+
777+
It can also be used as a regular button:
738778

739779
```js
740780
<Button onPress={() => console.log('button pressed')}>Press me</Button>

versioned_docs/version-8.x/link.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { Link } from '@react-navigation/native';
1717

1818
function Home() {
1919
return (
20-
<Link screen="Profile" params={{ id: 'jane' }}>
20+
<Link in="Home" screen="Profile" params={{ id: 'jane' }}>
2121
Go to Jane's profile
2222
</Link>
2323
);
@@ -26,4 +26,4 @@ function Home() {
2626
2727
If you want to use your own custom link component, you can use [`useLinkProps`](use-link-props.md) instead.
2828
29-
The `Link` component accepts the [same props as `useLinkProps`](use-link-props.md#options)
29+
The `Link` component accepts the [same props as `useLinkProps`](use-link-props.md#options).

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,10 @@ This hook returns values related to the screen's animation. It contains the foll
640640

641641
See [Transparent modals](#transparent-modals) for an example of how to use this hook.
642642

643+
#### `useGestureHandler`
644+
645+
This hook returns the pan gesture for the current Stack screen, or `null` if gestures are not supported on the platform. It can be used to coordinate a custom gesture with the Stack's gesture using the APIs from [`react-native-gesture-handler`](https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/gesture).
646+
643647
## Animations
644648

645649
You can specify the `animation` option to customize the transition animation for screens being pushed or popped.
@@ -847,6 +851,7 @@ Stack Navigator exposes various options to configure the transition animation wh
847851
- `containerStyle` - Style for the container view wrapping the card.
848852
- `cardStyle` - Style for the view representing the card.
849853
- `overlayStyle` - Style for the view representing the semi-transparent overlay below
854+
- `dimStyle` - Style for the dimming view on top of the card content.
850855
- `shadowStyle` - Style for the view representing the card shadow.
851856

852857
The function receives the following properties in its argument:
@@ -1173,7 +1178,7 @@ import { TransitionSpecs } from '@react-navigation/stack';
11731178

11741179
- `forHorizontalIOS` - Standard iOS-style slide in from the right.
11751180
- `forVerticalIOS` - Standard iOS-style slide in from the bottom (used for modals).
1176-
- `forModalPresentationIOS` - Standard iOS-style modal animation in iOS 13.
1181+
- `forModalPresentationIOS` - Standard iOS-style modal animation.
11771182
- `forFadeFromBottomAndroid` - Standard Android-style fade in from the bottom for Android Oreo.
11781183
- `forRevealFromBottomAndroid` - Standard Android-style reveal from the bottom for Android Pie.
11791184

versioned_docs/version-8.x/typescript.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,30 @@ function Header() {
335335
}
336336
```
337337

338+
## Using typed links
339+
340+
The [`Link`](link.md), [`Button`](elements.md#button), and [`useLinkProps`](use-link-props.md) APIs are automatically type-checked based on the root navigator type.
341+
342+
By default, the `screen` and `params` props refer to a screen in the root navigator. To link to a screen in the current or a parent navigator, pass the name of the current or parent screen with the `in` prop, similar to the screen name accepted by `useNavigation`.
343+
344+
For example, suppose the `ArticleList` screen is in a stack nested under the `Feed` tab. The `Feed` tab is nested under the `Home` screen in the root navigator, alongside the `Settings` screen:
345+
346+
```tsx
347+
function ArticleListScreen() {
348+
return (
349+
<>
350+
{/* The root navigator is used by default */}
351+
<Link screen="Settings">Go to Settings</Link>
352+
353+
{/* The navigator containing the Feed screen is used */}
354+
<Link in="Feed" screen="Profile" params={{ userId: 'jane' }}>
355+
Go to Jane's profile
356+
</Link>
357+
</>
358+
);
359+
}
360+
```
361+
338362
## Nesting a dynamic navigator
339363

340364
If you render a dynamic navigator inside a static navigator, see [Mixing Static & Dynamic APIs](combine-static-with-dynamic.md#static-root-navigator-dynamic-nested-navigator) for the additional typing and linking configuration needed for the nested navigator.
@@ -558,6 +582,30 @@ function Header() {
558582
}
559583
```
560584

585+
<h2 id="using-typed-links-dynamic">Using typed links</h2>
586+
587+
The [`Link`](link.md), [`Button`](elements.md#button), and [`useLinkProps`](use-link-props.md) APIs are automatically type-checked based on the root navigator type.
588+
589+
By default, the `screen` and `params` props refer to a screen in the root navigator. To link to a screen in the current or a parent navigator, pass the name of the current or parent screen with the `in` prop, similar to the screen name accepted by `useNavigation`.
590+
591+
For example, suppose the `ArticleList` screen is in a stack nested under the `Feed` tab. The `Feed` tab is nested under the `Home` screen in the root navigator, alongside the `Settings` screen:
592+
593+
```tsx
594+
function ArticleListScreen() {
595+
return (
596+
<>
597+
{/* The root navigator is used by default */}
598+
<Link screen="Settings">Go to Settings</Link>
599+
600+
{/* The navigator containing the Feed screen is used */}
601+
<Link in="Feed" screen="Profile" params={{ userId: 'jane' }}>
602+
Go to Jane's profile
603+
</Link>
604+
</>
605+
);
606+
}
607+
```
608+
561609
## Annotating `options` and `screenOptions`
562610

563611
When you pass the `options` to a `Screen` or `screenOptions` prop to a `Navigator` component, they are already type-checked and you don't need to do anything special. However, sometimes you might want to extract the options to a separate object, and you might want to annotate it.

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

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,42 @@ Previously, the `gestureResponseDistance` option in Stack Navigator accepted an
726726
+ gestureResponseDistance: 50
727727
```
728728

729+
#### Stack and Drawer now use Gesture Handler 3
730+
731+
Stack and Drawer navigators now require `react-native-gesture-handler` 3. In addition to the [dependency change](#dependency-changes), APIs for customizing and accessing gestures have changed to match the new Gesture Handler API.
732+
733+
The [`configureGestureHandler`](drawer-navigator.md#configuregesturehandler) option in Drawer Navigator now receives and returns a gesture configuration object instead of a gesture builder:
734+
735+
```diff lang=js
736+
- configureGestureHandler: (gesture) =>
737+
- gesture.enableTrackpadTwoFingerGesture(false),
738+
+ configureGestureHandler: (config) => ({
739+
+ ...config,
740+
+ enableTrackpadTwoFingerGesture: false,
741+
+ }),
742+
```
743+
744+
The utilities exported by Stack Navigator have also changed:
745+
746+
```diff lang=js
747+
- import {
748+
- GestureHandlerRefContext,
749+
- useGestureHandlerRef,
750+
- } from '@react-navigation/stack';
751+
+ import {
752+
+ GestureHandlerContext,
753+
+ useGestureHandler,
754+
+ } from '@react-navigation/stack';
755+
```
756+
757+
The [`useGestureHandler`](stack-navigator.md#usegesturehandler) hook returns the pan gesture for the current Stack screen instead of a ref to the gesture handler.
758+
759+
#### Stack modal presentation has changed on iOS 26
760+
761+
The modal presentation in Stack Navigator has been updated to match the latest iOS design on iOS 26 and later. Modal screens now use rounded corners, and the screens underneath are scaled and dimmed.
762+
763+
This applies to screens using [`presentation: 'modal'`](stack-navigator.md#presentation) and the [`forModalPresentationIOS`](stack-navigator.md#cardstyleinterpolators) card style interpolator. If you use a custom card style interpolator for a similar presentation, it can now return a `dimStyle` to render a dimming view on top of the card content.
764+
729765
#### Material Top Tabs and `react-native-tab-view` have been updated to Material Design 3
730766

731767
##### The tab bar now uses the `primary` variant by default
@@ -1191,6 +1227,20 @@ It's still possible to use these hooks without passing the screen name, same as
11911227

11921228
See [`useNavigation`](use-navigation.md), [`useRoute`](use-route.md), and [`useNavigationState`](use-navigation-state.md) for more details.
11931229

1230+
### Links can target screens in the current or a parent navigator
1231+
1232+
The [`useLinkProps`](use-link-props.md), [`Link`](link.md), and [`Button`](elements.md#button) APIs now accept an [`in`](use-link-props.md#in) prop. It specifies the name of the current or parent screen whose navigator contains the target screen.
1233+
1234+
For example, a screen nested in the `Home` tab can link to the `Settings` tab in the parent tab navigator:
1235+
1236+
```js
1237+
<Link in="Home" screen="Settings">
1238+
Go to Settings
1239+
</Link>
1240+
```
1241+
1242+
This is similar to how [typed hooks accept the name of the screen](#common-hooks-now-accept-name-of-the-screen). But unlike typed hooks, navigation from `Link` using the `screen` and `params` props doesn't bubble up to parent navigators.
1243+
11941244
### New entry can be added to history stack with `pushParams` action
11951245

11961246
The `pushParams` action updates the params and pushes a new entry to the history stack:
@@ -1572,6 +1622,20 @@ tabBarIcon: Platform.select({
15721622

15731623
In addition, new `SFSymbol` and `MaterialSymbol` components are exported from `@react-navigation/native` to render these icons directly.
15741624

1625+
The new [`PlatformIcon`](elements.md#platformicon) component from `@react-navigation/elements` can render an icon object directly. It renders an image, SF Symbol, or Material Symbol based on the icon object:
1626+
1627+
```js
1628+
<PlatformIcon
1629+
icon={Platform.select({
1630+
ios: { type: 'sfSymbol', name: 'person' },
1631+
android: { type: 'materialSymbol', name: 'person' },
1632+
default: { type: 'image', source: require('./person.png') },
1633+
})}
1634+
color="tomato"
1635+
size={24}
1636+
/>
1637+
```
1638+
15751639
See [Icons](icons.md) for more details.
15761640

15771641
### `react-native-tab-view` now supports a `renderAdapter` prop for custom adapters
@@ -1607,9 +1671,25 @@ export default function TabViewExample() {
16071671

16081672
You can also create your own custom adapter by implementing the required interface. See the [`react-native-tab-view` docs](tab-view.md) for more information.
16091673

1610-
### `Button` from `@react-navigation/elements` now supports disabled state, icons and React elements
1674+
### `Button` from `@react-navigation/elements` now supports more options
1675+
1676+
The [`Button`](elements.md#button) component now supports loading and disabled states. The `loading` prop shows a loading indicator in place of the icon and disables interaction:
16111677

1612-
The [`Button`](elements.md#button) component now supports a disabled state.
1678+
```js
1679+
<Button loading={isLoading} onPress={submit}>
1680+
Submit
1681+
</Button>
1682+
```
1683+
1684+
When the button navigates to a screen, it automatically shows the loading indicator while the navigation transition is pending. You can pass `loading={false}` to disable the automatic loading indicator.
1685+
1686+
The `disabled` prop disables interaction and applies a disabled style to the button:
1687+
1688+
```js
1689+
<Button disabled={isDisabled} onPress={submit}>
1690+
Submit
1691+
</Button>
1692+
```
16131693

16141694
It also accepts an `icon` prop to show an icon alongside the button label:
16151695

versioned_docs/version-8.x/use-link-props.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,22 @@ import { useLinkProps } from '@react-navigation/native';
1515

1616
// ...
1717

18-
const LinkButton = ({ screen, params, action, href, children, ...rest }) => {
19-
const props = useLinkProps({ screen, params, action, href });
18+
const LinkButton = ({
19+
in: parent,
20+
screen,
21+
params,
22+
action,
23+
href,
24+
children,
25+
...rest
26+
}) => {
27+
const props = useLinkProps({
28+
in: parent,
29+
screen,
30+
params,
31+
action,
32+
href,
33+
});
2034

2135
const [isHovered, setIsHovered] = React.useState(false);
2236

@@ -64,6 +78,20 @@ If you want to navigate to a nested screen, you can pass the name of the `screen
6478
</LinkButton>
6579
```
6680

81+
### `in`
82+
83+
By default, the link targets a screen in the root navigator. You can pass the name of the current or parent screen whose navigator contains the target screen with the `in` prop.
84+
85+
For example, if the current screen is nested in the `Home` tab, you can link to the `Settings` tab in the parent tab navigator:
86+
87+
```js
88+
<LinkButton in="Home" screen="Settings">
89+
Go to Settings
90+
</LinkButton>
91+
```
92+
93+
This is similar to how [useNavigation](use-navigation.md) accepts the current screen or any of its parent screens. But unlike navigating with `useNavigation`, navigation from `Link` using the `screen` and `params` props doesn't bubble up to parent navigators.
94+
6795
### `action`
6896

6997
Sometimes we want a different behavior for in-page navigation, such as `replace` instead of `navigate`. We can use the `action` prop to customize it:
@@ -88,7 +116,9 @@ function Home() {
88116
}
89117
```
90118
91-
The `screen` and `params` props can be omitted if the `action` prop is specified. In that case, we recommend specifying the `href` prop as well to ensure that the link is accessible.
119+
The action gets dispatched to the current navigator and can bubble upto a parent navigator similar to dispatching the action with [navigation.dispatch](navigation-object.md#dispatch).
120+
121+
The `screen` and `params` props can be omitted if the `action` prop is specified. In that case, we recommend specifying the `href` prop as well to ensure that the link is accessible. The `in` prop is not supported when only the `action` prop is specified.
92122
93123
### `href`
94124

0 commit comments

Comments
 (0)