Skip to content

Commit 2df1134

Browse files
committed
Rework behavior for preload
1 parent df1fae3 commit 2df1134

3 files changed

Lines changed: 17 additions & 19 deletions

File tree

versioned_docs/version-8.x/navigation-actions.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,6 @@ The `preload` action allows preloading a screen in the background before navigat
450450

451451
- `name` - _string_ - A destination name of the screen in the current or a parent navigator.
452452
- `params` - _object_ - Params to use for the destination route.
453-
- `options` - Options object containing the following properties:
454-
- `reuse` - _boolean_ - Whether to reuse a matching preloaded or existing route instead of adding a new preloaded route. Defaults to `false`.
455453

456454
```js name="Common actions preload" snack static2dynamic
457455
import * as React from 'react';
@@ -553,7 +551,7 @@ Preloading a screen means that the screen will be rendered in the background. Al
553551
554552
Depending on the navigator, `preload` may work differently:
555553
556-
- In a stack navigator ([stack](stack-navigator.md), [native stack](native-stack-navigator.md)), the screen will be rendered off-screen and animated in when you navigate to it. If [`getId`](screen.md#id) is specified, it'll be used for the navigation to identify the preloaded screen. When `reuse` is `true`, a matching preloaded or existing route will be reused and its params will be updated.
554+
- In a stack navigator ([stack](stack-navigator.md), [native stack](native-stack-navigator.md)), the screen will be rendered off-screen and animated in when you navigate to it. Calling `preload` for a matching preloaded screen will update its params instead of adding a new preloaded screen. If [`getId`](screen.md#id) is specified, it'll be used for matching the preloaded screen. Otherwise, the screen name is used. If you need multiple preloaded instances of the same screen, use `getId` or [`reset`](#reset).
557555
- In a tab or drawer navigator ([bottom tabs](bottom-tab-navigator.md), [material top tabs](material-top-tab-navigator.md), [drawer](drawer-navigator.md), etc.), the existing screen will be rendered as if `lazy` was set to `false`. Calling `preload` on a screen that is already rendered will not have any effect.
558556

559557
### setParams

versioned_docs/version-8.x/navigation-object.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -717,11 +717,9 @@ The `preload` method allows preloading a screen in the background before navigat
717717

718718
- `name` - _string_ - A destination name of the screen in the current or a parent navigator.
719719
- `params` - _object_ - Params to use for the destination route.
720-
- `options` - Options object containing the following properties:
721-
- `reuse` - _boolean_ - Whether to reuse a matching preloaded or existing route instead of adding a new preloaded route. Defaults to `false`.
722720

723721
```js
724-
navigation.preload('Profile', { user: 'jane' }, { reuse: true });
722+
navigation.preload('Profile', { user: 'jane' });
725723
```
726724

727725
<Tabs groupId="config" queryString="config">
@@ -917,7 +915,7 @@ Preloading a screen means that the screen will be rendered in the background. Al
917915

918916
Depending on the navigator, `preload` may work slightly differently:
919917

920-
- In a stack navigator ([stack](stack-navigator.md), [native stack](native-stack-navigator.md)), the screen will be rendered off-screen and animated in when you navigate to it. If [`getId`](screen.md#id) is specified, it'll be used for the navigation to identify the preloaded screen. When `reuse` is `true`, a matching preloaded or existing route will be reused and its params will be updated.
918+
- In a stack navigator ([stack](stack-navigator.md), [native stack](native-stack-navigator.md)), the screen will be rendered off-screen and animated in when you navigate to it. Calling `preload` for a matching preloaded screen will update its params instead of adding a new preloaded screen. If [`getId`](screen.md#id) is specified, it'll be used for matching the preloaded screen. Otherwise, the screen name is used. If you need multiple preloaded instances of the same screen, use `getId` or [`reset`](#reset).
921919
- In a tab or drawer navigator ([bottom tabs](bottom-tab-navigator.md), [material top tabs](material-top-tab-navigator.md), [drawer](drawer-navigator.md), etc.), the existing screen will be rendered as if `lazy` was set to `false`. Calling `preload` on a screen that is already rendered will not have any effect.
922920

923921
### `setParams`

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,20 @@ If you use a custom navigator with `StackRouter` and do not want to change the s
339339

340340
See [Navigation state](navigation-state.md) for more details.
341341

342+
##### `preload` reuses matching preloaded routes instead of adding new ones
343+
344+
Previously, calling `preload` for the same screen multiple times in a Stack or Native Stack Navigator would always preload a new instance of screen, leading to multiple preloaded instances. We found that this behavior was not intuitive and most people expected to have a single instance.
345+
346+
In React Navigation 8, calling `preload` for a matching preloaded screen updates its params instead of adding another preloaded screen:
347+
348+
```js
349+
navigation.preload('Profile', { user: 'jane' });
350+
```
351+
352+
By default, preloaded screens are matched based on the screen name. The [`getId`](screen.md#id) prop can be used to match based on an ID derived from the params instead.
353+
354+
See [`preload`](navigation-actions.md#preload) for more details.
355+
342356
##### Preloaded screens behave closer to regular screens
343357

344358
Previously, when a screen was preloaded in Stack and Native Stack Navigators, there were a few restrictions:
@@ -852,18 +866,6 @@ This can be useful in various scenario:
852866

853867
See [`pushParams` docs](navigation-actions.md#pushparams) for more details.
854868

855-
### `preload` now supports a `reuse` option in Stack navigators
856-
857-
Previously, calling `preload` for the same screen multiple times in a Stack or Native Stack Navigator would add another preloaded route.
858-
859-
In React Navigation 8, you can pass `reuse: true` to update params for an existing preloaded or matching route instead:
860-
861-
```js
862-
navigation.preload('Profile', { user: 'jane' }, { reuse: true });
863-
```
864-
865-
See [`preload`](navigation-actions.md#preload) for more details.
866-
867869
### Themes now support `ColorValue` and CSS custom properties
868870

869871
Previously, theme colors only supported string values. In React Navigation 8, theme colors now support `PlatformColor`, `DynamicColorIOS` on native, and CSS custom properties on Web for more flexibility.

0 commit comments

Comments
 (0)