Skip to content

Commit 4065a14

Browse files
committed
Document inactiveBehavior
1 parent 65583f8 commit 4065a14

File tree

5 files changed

+93
-31
lines changed

5 files changed

+93
-31
lines changed

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,6 @@ It supports the following values:
168168
- `fullHistory` - return to last visited screen in the navigator; doesn't drop duplicate entries unlike `history` - this behavior is useful to match how web pages work
169169
- `none` - do not handle back button
170170

171-
#### `detachInactiveScreens`
172-
173-
Boolean used to indicate whether inactive screens should be detached from the view hierarchy to save memory. This enables integration with [react-native-screens](https://github.com/software-mansion/react-native-screens). Defaults to `true`.
174-
175-
Only supported with `custom` implementation.
176-
177171
#### `tabBar`
178172

179173
Function that returns a React element to display as the tab bar.
@@ -316,6 +310,29 @@ function MyTabBar({ navigation }) {
316310

317311
The following [options](screen-options.md) can be used to configure the screens in the navigator. These can be specified under `screenOptions` prop of `Tab.Navigator` or `options` prop of `Tab.Screen`.
318312

313+
#### `inactiveBehavior`
314+
315+
This controls what should happen when screens become inactive.
316+
317+
It supports the following values:
318+
319+
- `pause`: Effects are cleaned up - e.g. timers are cleared, subscriptions are removed, etc. This avoids unnecessary renders when the screen is inactive.
320+
- `none`: Screen renders normally.
321+
322+
Defaults to `pause`.
323+
324+
If you set [`lazy: false`](#lazy) or [`preload`](navigation-actions.md#preload) a screen, it won't be paused until after the first time it becomes focused. This makes sure that effects are run to initialize the screen.
325+
326+
:::info
327+
328+
React Navigation determines whether a screen is inactive based on various factors such as gestures, animations, and other interactions after it becomes unfocused.
329+
330+
:::
331+
332+
#### `lazy`
333+
334+
Whether this screen should render only after the first time it's accessed. Defaults to `true`. Set it to `false` if you want to render the screen on the initial render of the navigator.
335+
319336
#### `title`
320337

321338
Generic title that can be used as a fallback for `headerTitle` and `tabBarLabel`.
@@ -1026,10 +1043,6 @@ Defaults to `automatic` for each edge.
10261043

10271044
Only supported with `native` implementation on iOS 26 and above.
10281045

1029-
#### `lazy`
1030-
1031-
Whether this screen should render only after the first time it's accessed. Defaults to `true`. Set it to `false` if you want to render the screen on the initial render of the navigator.
1032-
10331046
#### `popToTopOnBlur`
10341047

10351048
Boolean indicating whether any nested stack should be popped to the top of the stack when navigating away from this tab. Defaults to `false`.

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,6 @@ The default status of the drawer - whether the drawer should stay `open` or `clo
132132

133133
When this is set to `open`, the drawer will be open from the initial render. It can be closed normally using gestures or programmatically. However, when going back, the drawer will re-open if it was closed. This is essentially the opposite of the default behavior of the drawer where it starts `closed`, and the back button closes an open drawer.
134134

135-
#### `detachInactiveScreens`
136-
137-
Boolean used to indicate whether inactive screens should be detached from the view hierarchy to save memory. This enables integration with [react-native-screens](https://github.com/software-mansion/react-native-screens). Defaults to `true`.
138-
139135
#### `drawerContent`
140136

141137
Function that returns React element to render as the content of the drawer, for example, navigation items
@@ -267,14 +263,27 @@ To use the custom component, we need to pass it in the `drawerContent` prop:
267263

268264
The following [options](screen-options.md) can be used to configure the screens in the navigator. These can be specified under `screenOptions` prop of `Drawer.Navigator` or `options` prop of `Drawer.Screen`.
269265

270-
#### `title`
266+
#### `inactiveBehavior`
271267

272-
A generic title that can be used as a fallback for `headerTitle` and `drawerLabel`.
268+
This controls what should happen when screens become inactive.
269+
270+
It supports the following values:
271+
272+
- `pause`: Effects are cleaned up - e.g. timers are cleared, subscriptions are removed, etc. This avoids unnecessary renders when the screen is inactive.
273+
- `none`: Screen renders normally.
274+
275+
Defaults to `pause`.
276+
277+
If you set [`lazy: false`](#lazy) or [`preload`](navigation-actions.md#preload) a screen, it won't be paused until after the first time it becomes focused. This makes sure that effects are run to initialize the screen.
273278

274279
#### `lazy`
275280

276281
Whether this screen should render the first time it's accessed. Defaults to `true`. Set it to `false` if you want to render the screen on initial render.
277282

283+
#### `title`
284+
285+
A generic title that can be used as a fallback for `headerTitle` and `drawerLabel`.
286+
278287
#### `drawerLabel`
279288

280289
String or a function that given `{ focused: boolean, color: string }` returns a React.Node, to display in drawer sidebar. When undefined, scene `title` is used.

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,25 @@ export default function App() {
354354
}
355355
```
356356

357+
#### `inactiveBehavior`
358+
359+
This controls what should happen when screens become inactive.
360+
361+
It supports the following values:
362+
363+
- `pause`: Effects are cleaned up - e.g. timers are cleared, subscriptions are removed, etc. This avoids unnecessary renders when the screen is inactive.
364+
- `none`: Screen renders normally.
365+
366+
Defaults to `pause`.
367+
368+
If you set [`lazy: false`](#lazy) or [`preload`](navigation-actions.md#preload) a screen, it won't be paused until after the first time it becomes focused. This makes sure that effects are run to initialize the screen.
369+
370+
:::info
371+
372+
React Navigation determines whether a screen is inactive based on various factors such as gestures, animations, and other interactions after it becomes unfocused.
373+
374+
:::
375+
357376
#### `title`
358377

359378
Generic title that can be used as a fallback for `headerTitle` and `tabBarLabel`.

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,25 @@ The native stack navigator accepts the [common props](navigator.md#configuration
9595

9696
The following [options](screen-options.md) can be used to configure the screens in the navigator:
9797

98+
#### `inactiveBehavior`
99+
100+
This controls what should happen when screens become inactive.
101+
102+
It supports the following values:
103+
104+
- `pause`: Effects are cleaned up - e.g. timers are cleared, subscriptions are removed, etc. This avoids unnecessary renders when the screen is inactive.
105+
- `none`: Screen renders normally.
106+
107+
Defaults to `pause`.
108+
109+
If you [`preload`](navigation-actions.md#preload) a screen, it won't be paused until after the first time it becomes focused. This makes sure that effects are run to initialize the screen.
110+
111+
:::info
112+
113+
React Navigation determines whether a screen is inactive based on various factors such as gestures, animations, and other interactions after it becomes unfocused.
114+
115+
:::
116+
98117
#### `title`
99118

100119
String that can be used as a fallback for `headerTitle`.

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,28 @@ export default function App() {
110110

111111
## API Definition
112112

113-
### Props
113+
### Options
114114

115-
In addition to the [common props](navigator.md#configuration) shared by all navigators, the stack navigator accepts the following additional props:
115+
The following [options](screen-options.md) can be used to configure the screens in the navigator. These can be specified under `screenOptions` prop of `Stack.Navigator` or `options` prop of `Stack.Screen`.
116116

117-
#### `detachInactiveScreens`
117+
#### `inactiveBehavior`
118118

119-
Boolean used to indicate whether inactive screens should be detached from the view hierarchy to save memory. This enables integration with [react-native-screens](https://github.com/software-mansion/react-native-screens). Defaults to `true`.
119+
This controls what should happen when screens become inactive.
120120

121-
If you need to disable this optimization for specific screens (e.g. you want to screen to stay in view even when unfocused) [`detachPreviousScreen`](#detachpreviousscreen) option.
121+
It supports the following values:
122122

123-
### Options
123+
- `pause`: Effects are cleaned up - e.g. timers are cleared, subscriptions are removed, etc. This avoids unnecessary renders when the screen is inactive.
124+
- `none`: Screen renders normally.
124125

125-
The following [options](screen-options.md) can be used to configure the screens in the navigator. These can be specified under `screenOptions` prop of `Stack.Navigator` or `options` prop of `Stack.Screen`.
126+
Defaults to `pause`.
127+
128+
If you [`preload`](navigation-actions.md#preload) a screen, it won't be paused until after the first time it becomes focused. This makes sure that effects are run to initialize the screen.
129+
130+
:::info
131+
132+
React Navigation determines whether a screen is inactive based on various factors such as gestures, animations, and other interactions after it becomes unfocused.
133+
134+
:::
126135

127136
#### `title`
128137

@@ -144,7 +153,7 @@ Function which returns a React Element to display as the overlay for the card. M
144153

145154
Style object for the card in stack. You can provide a custom background color to use instead of the default background here.
146155

147-
You can also specify `{ backgroundColor: 'transparent' }` to make the previous screen visible underneath (for transparent modals). This is useful to implement things like modal dialogs. You should also specify `presentation: 'modal'` in the options when using a transparent background so previous screens aren't detached and stay visible underneath.
156+
You can also specify `{ backgroundColor: 'transparent' }` to make the previous screen visible underneath (for transparent modals). This is useful to implement things like modal dialogs. You should also specify `presentation: 'modal'` in the options when using a transparent background so previous screens stay visible underneath.
148157

149158
On Web, the height of the screen isn't limited to the height of the viewport. This is by design to allow the browser's address bar to hide when scrolling. If this isn't desirable behavior, you can set `cardStyle` to `{ flex: 1 }` to force the screen to fill the viewport.
150159

@@ -159,7 +168,6 @@ This is shortcut option which configures several options to configure the style
159168
- `transparentModal`: Similar to `modal`. This changes following things:
160169
- Sets `headerMode` to `screen` for the screen unless specified otherwise.
161170
- Sets background color of the screen to transparent, so previous screen is visible
162-
- Adjusts the `detachPreviousScreen` option so that the previous screen stays rendered.
163171
- Prevents the previous screen from animating from its last position.
164172
- Changes the screen animation to a vertical slide animation.
165173

@@ -223,12 +231,6 @@ Interpolated styles for various parts of the header. Refer the [Animations secti
223231

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

226-
#### `detachPreviousScreen`
227-
228-
Boolean used to indicate whether to detach the previous screen from the view hierarchy to save memory. Set it to `false` if you need the previous screen to be seen through the active screen. Only applicable if `detachInactiveScreens` isn't set to `false`.
229-
230-
This is automatically adjusted when using [`presentation`](#presentation) as `transparentModal` or `modal` to keep the required screens visible. Defaults to `true` in other cases.
231-
232234
#### `freezeOnBlur`
233235

234236
Boolean indicating whether to prevent inactive screens from re-rendering. Defaults to `false`.

0 commit comments

Comments
 (0)