You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versioned_docs/version-8.x/bottom-tab-navigator.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -557,6 +557,15 @@ The icon object can be one of the following types:
557
557
558
558
It's necessary to provide icons for multiple screen densities (1x, 2x, 3x), e.g.: `icon.png`, `icon@2x.png`, `icon@3x.png` etc. as icons are not scaled automatically on iOS for the `native` implementation.
559
559
560
+
It also supports [drawable resource](https://developer.android.com/guide/topics/resources/drawable-resource) on Android, [xcasset](https://developer.apple.com/documentation/xcode/adding-images-to-your-xcode-project) on iOS:
561
+
562
+
```js
563
+
tabBarIcon: {
564
+
type:'image',
565
+
source: { uri:'icon_name' },
566
+
}
567
+
```
568
+
560
569
A `tinted` property can be used to control whether the icon should be tinted with the active/inactive color:
561
570
562
571
```js
@@ -597,15 +606,6 @@ The icon object can be one of the following types:
597
606
598
607
See [Icons](icons.md#material-symbols) for more details.
599
608
600
-
- Resource name - [Drawable resource](https://developer.android.com/guide/topics/resources/drawable-resource) on Android, [xcasset](https://developer.apple.com/documentation/xcode/adding-images-to-your-xcode-project) on iOS.
601
-
602
-
```js
603
-
tabBarIcon: {
604
-
type:'resource',
605
-
name:'sunny',
606
-
}
607
-
```
608
-
609
609
To render different icons for active and inactive states, you can use a function:
Copy file name to clipboardExpand all lines: versioned_docs/version-8.x/navigation-actions.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -106,7 +106,9 @@ In a stack navigator ([stack](stack-navigator.md) or [native stack](native-stack
106
106
107
107
- If you're already on a screenwith the same name, it will update its params and not push a newscreen.
108
108
- If you're on a different screen, it will push the new screen onto the stack.
109
-
- If the [`getId`](screen.md#id) prop is specified, and another screen in the stack has the same ID, it will bring that screen to focus and update its params instead.
109
+
- If the [`getId`](screen.md#id) prop is specified, it's treated similarly to the name,
110
+
- If you're already on a screen with the same id, it will update its params and not push a new screen.
111
+
- If you're on a different screen, it will push the newscreen onto the stack.
110
112
111
113
<details>
112
114
<summary>Advanced usage</summary>
@@ -116,10 +118,8 @@ The `navigate` action can also accepts an object as the argument with the follow
116
118
-`name`- _string_ -A destination name of the screenin the current or a parent navigator
117
119
-`params`- _object_ - Params to use for the destination route.
118
120
-`merge`- _boolean_ - Whether params should be merged with the existing route params, or replace them (when navigating to an existing screen). Defaults to `false`.
119
-
- `pop` - _boolean_ - Whether screens should be popped to navigate to a matching screen in the stack. Defaults to `false`.
120
-
- `path` - _string_ - The path (from deep link or universal link) to associate with the screen.
121
-
122
-
This is primarily used internally to associate a path with a screen when it's from a URL.
121
+
-`pop`- _boolean_ - Whether screens should be popped to navigate to a matching screen (by name or id if`getId` is specified) in the stack. Defaults to `false`.
122
+
-`path`- _string_ - The path (from deep link or universal link) to associate with the screen. This is primarily used internally to associate a path with a screen when it's from a URL.
Copy file name to clipboardExpand all lines: versioned_docs/version-8.x/navigation-object.md
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,13 +74,13 @@ The vast majority of your interactions with the `navigation` object will involve
74
74
75
75
The `navigate` method lets us navigate to another screen in your app. It takes the following arguments:
76
76
77
-
`navigation.navigate(name, params)`
77
+
`navigation.navigate(name, params, options)`
78
78
79
79
-`name` - _string_ - A destination name of the screen in the current or a parent navigator.
80
80
-`params` - _object_ - Params to use for the destination route.
81
81
-`options` - Options object containing the following properties:
82
82
-`merge` - _boolean_ - Whether params should be merged with the existing route params, or replace them (when navigating to an existing screen). Defaults to `false`.
83
-
-`pop` - _boolean_ - Whether screens should be popped to navigate to a matching screen in the stack. Defaults to `false`.
83
+
-`pop` - _boolean_ - Whether screens should be popped to navigate to a matching screen (by name or id if `getId` is specified) in the stack. Defaults to `false`.
84
84
85
85
<TabsgroupId="config"queryString="config">
86
86
<TabItemvalue="static"label="Static"default>
@@ -249,8 +249,9 @@ In a stack navigator ([stack](stack-navigator.md) or [native stack](native-stack
249
249
250
250
- If you're already on a screen with the same name, it will update its params and not push a new screen.
251
251
- If you're on a different screen, it will push the new screen onto the stack.
252
-
- If the [`getId`](screen.md#id) prop is specified, and another screen in the stack has the same ID, it will bring that screen to focus and update its params instead.
253
-
- If none of the above conditions match, it'll push a new screen to the stack.
252
+
- If the [`getId`](screen.md#id) prop is specified, it's treated similarly to the name,
253
+
- If you're already on a screen with the same id, it will update its params and not push a new screen.
254
+
- If you're on a different screen, it will push the new screen onto the stack.
254
255
255
256
In a tab or drawer navigator, calling `navigate` will switch to the relevant screen if it's not focused already and update the params of the screen.
A screen can have an ID to identify it uniquely. This is useful when you want to ensure that the screen with the same ID doesn't appear multiple times in the stack.
213
+
A screen can have an ID to identify it. The ID is used differently based on the navigator type.
214
+
215
+
- In a stack navigator, the ID is treated similarly to the name.
216
+
- In a tab or drawer navigator, the screen will remount if the ID changes.
214
217
215
218
This can be done by specifying the `getId` callback. It receives an object with the route params:
In the above example, `params.userId` is used as an ID for the `Profile` screen with `getId`. This changes how the navigation works to ensure that the screen with the same ID appears only once in the stack.
248
-
249
-
Let's say you have a stack with the history `Home > Profile (userId: bob) > Settings`, consider following scenarios:
250
-
251
-
- You call `navigate(Profile, { userId: 'bob' })`:
252
-
The resulting screens will be `Home > Settings > Profile (userId: bob)` since the existing `Profile` screen matches the ID.
253
-
- You call `navigate(Profile, { userId: 'alice' })`:
254
-
The resulting screens will be `Home > Profile (userId: bob) > Settings > Profile (userId: alice)` since it'll add a new `Profile` screen as no matching screen was found.
255
-
256
-
If `getId` is specified in a tab or drawer navigator, the screen will remount if the ID changes.
257
-
258
-
:::warning
259
-
260
-
If you're using [`@react-navigation/native-stack`](native-stack-navigator.md), it doesn't work correctly with the `getId` callback. So it's recommended to avoid using it in that case.
261
-
262
-
:::
250
+
In the above example, `params.userId` is used as an ID for the `Profile` screen with `getId`. So if you navigate to `Profile` with the same `userId`, it'll update the params of the existing screen instead of pushing a new one. If you navigate to `Profile` with a different `userId`, it'll push a new screen onto the stack.
Copy file name to clipboardExpand all lines: versioned_docs/version-8.x/stack-actions.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -287,6 +287,8 @@ The method accepts the following arguments:
287
287
- `options` - Options object containing the following properties:
288
288
- `merge` - _boolean_ - Whether params should be merged with the existing route params, or replace them (when navigating to an existing screen). Defaults to `false`.
289
289
290
+
If [`getId`](screen.md#id) is specified for the screen, `popTo` will match the screen by id instead of name.
Copy file name to clipboardExpand all lines: versioned_docs/version-8.x/upgrading-from-7.x.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -388,6 +388,14 @@ This way you have more control over how params are updated in tab and drawer nav
388
388
389
389
See [`setParams` action docs](navigation-actions.md#setparams) for more details.
390
390
391
+
#### `getId` no longer re-arranges screens in the stack to make the screen unique
392
+
393
+
Previously, the ID returned by `getId` was treated as a unique identifier. When using `navigate` or `push` to go to a route with an ID that already existed in the stack, the stack would rearrange to bring the existing route to the front. However, this resulted in broken behavior with Native Stack Navigator.
394
+
395
+
Since this was unusable, and resulted in hard to debug issues, we have changed the behavior of `getId` to treat it more like the route name - that is, it will match routes by ID without rearranging the stack. If you navigate to a route with an existing ID and `pop: true`, it will pop back to the matching route instead of moving it to the top.
396
+
397
+
If you were relying on the previous behavior and are not using Native Stack Navigator, you can use the [`router` prop](#navigators-now-accept-a-router-prop) on the navigator to customize how each action updates the state, and implement the previous behavior.
398
+
391
399
#### Navigators no longer use `InteractionManager`
392
400
393
401
Previously, various navigators used `InteractionManager` to mark when animations and gestures were in progress. This was primarily used to defer code that should run after transitions, such as loading data or rendering heavy components.
0 commit comments