Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions versioned_docs/version-8.x/stack-navigator.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ Interpolated styles for various parts of the header. Refer the [Animations secti

If `false`, the keyboard will NOT automatically dismiss when navigating to a new screen from this screen. Defaults to `true`.

When enabled, the text input that was focused before navigating away from this screen is focused again when the screen comes back into focus. To skip this for a specific navigation, use the [`usePreventFocusRestore`](#usepreventfocusrestore) hook.

### Header related options

You can find the list of header related options [here](elements.md#header). These [options](screen-options.md) can be specified under `screenOptions` prop of `Stack.Navigator` or `options` prop of `Stack.Screen`. You don't have to be using `@react-navigation/elements` directly to use these options, they are just documented in that page.
Expand Down Expand Up @@ -660,6 +662,34 @@ See [Transparent modals](#transparent-modals) for an example of how to use this

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 [Pan gesture APIs from `react-native-gesture-handler`](https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/use-pan-gesture/).

#### `usePreventFocusRestore`

When you go back to a screen, the stack focuses the text input that was focused before you left it. This hook returns a function that skips this once, for the next time the screen comes back into focus.

It's useful when the screen decides what to focus after another screen returns a result. For example, after picking a country on another screen, you may want to focus the next field or keep the keyboard hidden:

```js
import { usePreventFocusRestore } from '@react-navigation/stack';

function AddressScreen({ route }) {
const preventFocusRestore = usePreventFocusRestore();
const cityInputRef = React.useRef(null);

React.useEffect(() => {
if (route.params?.country) {
preventFocusRestore();
cityInputRef.current?.focus();
}
}, [route.params?.country, preventFocusRestore]);

// ...
}
```

Call it before the screen is focused again, e.g. in an effect when receiving the params, or in a callback called from the other screen. Outside of a Stack screen, the returned function does nothing.

To disable the keyboard handling entirely for a screen, use the [`keyboardHandlingEnabled`](#keyboardhandlingenabled) option.

## Animations

You can specify the `animation` option to customize the transition animation for screens being pushed or popped.
Expand Down
Loading