Skip to content

Commit 8cd7275

Browse files
committed
Improve docs for indepent containers
1 parent 990b009 commit 8cd7275

File tree

2 files changed

+65
-14
lines changed

2 files changed

+65
-14
lines changed

versioned_docs/version-6.x/navigation-container.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,14 @@ Custom theme to use for the navigation components such as the header, tab bar et
571571
572572
### `independent`
573573
574-
Whether this navigation container should be independent of parent containers. If this is not set to `true`, this container cannot be nested inside another container. Setting it to `true` disconnects any children navigators from parent container.
574+
:::warning
575+
576+
This is an advanced use case. Don't use this unless you are 100% sure that you need it.
577+
578+
:::
579+
580+
Whether this navigation container should be independent of parent containers. If this is not set to `true`, this container cannot be nested inside another container. Setting it to `true` disconnects any children navigators from the parent container and doesn't allow navigation between them.
575581
576582
You probably don't want to set this to `true` in a typical React Native app. This is only useful if you have navigation trees that work like their own mini-apps and don't need to navigate to the screens outside of them.
583+
584+
Avoid using this if you need to integrate with third-party components such as modals or bottom sheets. Consider using a [custom navigator](custom-navigators.md) instead.

versioned_docs/version-7.x/navigation-container.md

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: NavigationContainer
44
sidebar_label: NavigationContainer
55
---
66

7-
The `NavigationContainer` is responsible for managing your app state and linking your top-level navigator to the app environment.
7+
The `NavigationContainer` is responsible for managing your app's navigation state and linking your top-level navigator to the app environment.
88

99
The container takes care of platform specific integration and provides various useful functionality:
1010

@@ -38,16 +38,17 @@ Example:
3838
<samp id="using-refs" />
3939

4040
```js
41-
import { NavigationContainer, useNavigationContainerRef } from '@react-navigation/native';
41+
import {
42+
NavigationContainer,
43+
useNavigationContainerRef,
44+
} from '@react-navigation/native';
4245

4346
function App() {
4447
const navigationRef = useNavigationContainerRef(); // You can also use a regular ref with `React.useRef()`
4548

4649
return (
4750
<View style={{ flex: 1 }}>
48-
<Button onPress={() => navigationRef.navigate('Home')}>
49-
Go home
50-
</Button>
51+
<Button onPress={() => navigationRef.navigate('Home')}>Go home</Button>
5152
<NavigationContainer ref={navigationRef}>{/* ... */}</NavigationContainer>
5253
</View>
5354
);
@@ -155,9 +156,7 @@ Prop that accepts initial state for the navigator. This can be useful for cases
155156
Example:
156157

157158
```js
158-
<NavigationContainer
159-
initialState={initialState}
160-
>
159+
<NavigationContainer initialState={initialState}>
161160
{/* ... */}
162161
</NavigationContainer>
163162
```
@@ -417,7 +416,7 @@ import messaging from '@react-native-firebase/messaging';
417416
}}
418417
>
419418
{/* content */}
420-
</NavigationContainer>
419+
</NavigationContainer>;
421420
```
422421
423422
This option is not available on Web.
@@ -469,7 +468,7 @@ import messaging from '@react-native-firebase/messaging';
469468
}}
470469
>
471470
{/* content */}
472-
</NavigationContainer>
471+
</NavigationContainer>;
473472
```
474473
475474
This option is not available on Web.
@@ -569,8 +568,52 @@ function App() {
569568
570569
Custom theme to use for the navigation components such as the header, tab bar etc. See [theming guide](themes.md) for more details and usage guide.
571570
572-
### `independent`
571+
### `navigationInChildEnabled`
572+
573+
:::warning
574+
575+
This prop exists for backward compatibility reasons. It's not recommended to use it in new projects. It will be removed in a future release.
576+
577+
:::
578+
579+
In previous versions of React Navigation, it was possible to navigate to a screen in a nested navigator without specifying the name of the parent screen, i.e. `navigation.navigate(ScreenName)` instead of `navigation.navigate(ParentScreenName, { screen: ScreenName })`.
580+
581+
However, it has a few issues:
582+
583+
- It only works if the navigator is already mounted - making navigation coupled to other logic.
584+
- It doesn't work with the TypeScript types.
585+
586+
The `navigationInChildEnabled` prop allows you to opt-in to this behavior to make it easier to migrate legacy code. It's disabled by default.
587+
588+
For new code, see [navigating to a screen in a nested navigator](nesting-navigators.md#navigating-to-a-screen-in-a-nested-navigator) instead.
589+
590+
## Independent navigation containers
591+
592+
:::warning
593+
594+
This is an advanced use case. Don't use this unless you are 100% sure that you need it.
595+
596+
:::
597+
598+
In most apps, there will be only a single `NavigationContainer`. Nesting multiple `NavigationContainer`s will throw an error. However, in rare cases, it may be useful to have multiple independent navigation trees, e.g. including a mini-app inside a larger app.
599+
600+
You can wrap the nested `NavigationContainer` with the `NavigationIndependentTree` component to make it independent from the parent navigation tree:
601+
602+
```js
603+
import {
604+
NavigationContainer,
605+
NavigationIndependentTree,
606+
} from '@react-navigation/native';
607+
608+
function NestedApp() {
609+
return (
610+
<NavigationIndependentTree>
611+
<NavigationContainer>{/* content */}</NavigationContainer>
612+
</NavigationIndependentTree>
613+
);
614+
}
615+
```
573616
574-
Whether this navigation container should be independent of parent containers. If this is not set to `true`, this container cannot be nested inside another container. Setting it to `true` disconnects any children navigators from parent container.
617+
Doing this disconnects any children navigators from the parent container and doesn't allow navigation between them.
575618
576-
You probably don't want to set this to `true` in a typical React Native app. This is only useful if you have navigation trees that work like their own mini-apps and don't need to navigate to the screens outside of them.
619+
Avoid using this if you need to integrate with third-party components such as modals or bottom sheets. Consider using a [custom navigator](custom-navigators.md) instead.

0 commit comments

Comments
 (0)