Skip to content

Commit a961d8c

Browse files
committed
Cut 8.x docs
1 parent 1fa61a8 commit a961d8c

File tree

88 files changed

+35124
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+35124
-1
lines changed

versioned_docs/version-8.x/auth-flow.md

Lines changed: 1002 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 1198 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
---
2+
id: combine-static-with-dynamic
3+
title: Combining static and dynamic APIs
4+
sidebar_label: Static and dynamic APIs
5+
---
6+
7+
While the static API has many advantages, it doesn't fit use cases where the navigation configuration needs to be dynamic. So React Navigation supports interop between the static and dynamic APIs.
8+
9+
Keep in mind that the features provided by the static API such as automatic linking configuration and automatic TypeScript types need the whole configuration to be static. If part of the configuration is dynamic, you'll need to handle those parts manually.
10+
11+
There are 2 ways you may want to combine the static and dynamic APIs:
12+
13+
## Static root navigator, dynamic nested navigator
14+
15+
This is useful if you want to keep your configuration static, but need to use a dynamic configuration for a specific navigator.
16+
17+
Let's consider the following example:
18+
19+
- You have a root stack navigator that contains a tab navigator in a screen.
20+
- The tab navigator is defined using the dynamic API.
21+
22+
Our static configuration would look like this:
23+
24+
```js
25+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
26+
27+
const RootStack = createNativeStackNavigator({
28+
screens: {
29+
Home: {
30+
screen: HomeScreen,
31+
},
32+
Feed: {
33+
screen: FeedScreen,
34+
linking: {
35+
path: 'feed',
36+
},
37+
},
38+
},
39+
});
40+
```
41+
42+
Here, `FeedScreen` is a component that renders a tab navigator and is defined using the dynamic API:
43+
44+
```js
45+
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
46+
47+
const Tab = createBottomTabNavigator();
48+
49+
function FeedScreen() {
50+
return (
51+
<Tab.Navigator>
52+
<Tab.Screen name="Latest" component={LatestScreen} />
53+
<Tab.Screen name="Popular" component={PopularScreen} />
54+
</Tab.Navigator>
55+
);
56+
}
57+
```
58+
59+
This code will work, but we're missing 2 things:
60+
61+
- Linking configuration for the screens in the top tab navigator.
62+
- TypeScript types for the screens in the top tab navigator.
63+
64+
Since the nested navigator is defined using the dynamic API, we need to handle these manually. For the linking configuration, we can define the screens in the `linking` property of the `Feed` screen:
65+
66+
```js
67+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
68+
69+
const RootStack = createNativeStackNavigator({
70+
screens: {
71+
Home: {
72+
screen: HomeScreen,
73+
},
74+
Feed: {
75+
screen: FeedScreen,
76+
linking: {
77+
path: 'feed',
78+
// highlight-start
79+
screens: {
80+
Latest: 'latest',
81+
Popular: 'popular',
82+
},
83+
// highlight-end
84+
},
85+
},
86+
},
87+
});
88+
```
89+
90+
Here the `screens` property is the same as how you'd define it with `linking` config with the dynamic API. It can contain configuration for any nested navigators as well. See [configuring links](configuring-links.md) for more details on the API.
91+
92+
For the TypeScript types, we can define the type of the `FeedScreen` component:
93+
94+
```tsx
95+
import {
96+
StaticScreenProps,
97+
NavigatorScreenParams,
98+
} from '@react-navigation/native';
99+
100+
type FeedParamList = {
101+
Latest: undefined;
102+
Popular: undefined;
103+
};
104+
105+
// highlight-next-line
106+
type Props = StaticScreenProps<NavigatorScreenParams<FeedParamList>>;
107+
108+
// highlight-next-line
109+
function FeedScreen(_: Props) {
110+
// ...
111+
}
112+
```
113+
114+
In the above snippet:
115+
116+
1. We first define the param list type for screens in the navigator that defines params for each screen
117+
2. Then we use the `NavigatorScreenParams` type to get the type of route's `params` which will include types for the nested screens
118+
3. Finally, we use the type of `params` with `StaticScreenProps` to define the type of the screen component
119+
120+
This is based on how we'd define the type for a screen with a nested navigator with the dynamic API. See [Type checking screens and params in nested navigator](typescript.md#type-checking-screens-and-params-in-nested-navigator).
121+
122+
## Dynamic root navigator, static nested navigator
123+
124+
This is useful if you already have a dynamic configuration, but want to migrate to the static API. This way you can migrate one navigator at a time.
125+
126+
Let's consider the following example:
127+
128+
- You have a root stack navigator that contains a tab navigator in a screen.
129+
- The root stack navigator is defined using the dynamic API.
130+
131+
Our dynamic configuration would look like this:
132+
133+
```js
134+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
135+
136+
const RootStack = createNativeStackNavigator();
137+
138+
function RootStackScreen() {
139+
return (
140+
<RootStack.Navigator>
141+
<RootStack.Screen name="Home" component={HomeScreen} />
142+
<RootStack.Screen name="Feed" component={FeedScreen} />
143+
</RootStack.Navigator>
144+
);
145+
}
146+
```
147+
148+
Here, `FeedScreen` is a component that renders a tab navigator and is defined using the static API:
149+
150+
```js
151+
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
152+
153+
const FeedTabs = createBottomTabNavigator({
154+
screens: {
155+
Latest: {
156+
screen: LatestScreen,
157+
},
158+
Popular: {
159+
screen: PopularScreen,
160+
},
161+
},
162+
});
163+
```
164+
165+
To use the `FeedTabs` navigator for the `Feed` screen, we need to use the `createComponentForStaticNavigation` function:
166+
167+
```js
168+
import { createComponentForStaticNavigation } from '@react-navigation/native';
169+
170+
// highlight-next-line
171+
const FeedScreen = createComponentForStaticNavigation(FeedTabs, 'Feed');
172+
```
173+
174+
In addition, we can generate the TypeScript types for the `FeedTabs` navigator and use it in the types of `RootStack` without needing to write them manually:
175+
176+
```tsx
177+
import {
178+
StaticParamList,
179+
NavigatorScreenParams,
180+
} from '@react-navigation/native';
181+
182+
// highlight-next-line
183+
type FeedTabsParamList = StaticParamList<typeof FeedTabs>;
184+
185+
type RootStackParamList = {
186+
Home: undefined;
187+
// highlight-next-line
188+
Feed: NavigatorScreenParams<FeedTabsParamList>;
189+
};
190+
```
191+
192+
Similarly, we can generate the linking configuration for the `FeedTabs` navigator and use it in the linking configuration passed to `NavigationContainer`:
193+
194+
```js
195+
import { createPathConfigForStaticNavigation } from '@react-navigation/native';
196+
197+
// highlight-next-line
198+
const feedScreens = createPathConfigForStaticNavigation(FeedTabs);
199+
200+
const linking = {
201+
prefixes: ['https://example.com', 'example://'],
202+
config: {
203+
screens: {
204+
Home: '',
205+
Feed: {
206+
path: 'feed',
207+
// highlight-next-line
208+
screens: feedScreens,
209+
},
210+
},
211+
},
212+
};
213+
```
214+
215+
This will generate the linking configuration for the `Feed` screen based on the configuration of the `FeedTabs` navigator.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
id: community-libraries
3+
title: Community libraries
4+
sidebar_label: Community libraries
5+
---
6+
7+
This guide lists various community libraries that can be used alongside React Navigation to enhance its functionality.
8+
9+
:::note
10+
11+
Please refer to the library's documentation to see which version of React Navigation it supports.
12+
13+
:::
14+
15+
## react-native-screen-transitions
16+
17+
A library that provides customizable screen transition animations for React Navigation's [Native Stack Navigator](native-stack-navigator.md).
18+
19+
[Repository](https://github.com/eds2002/react-native-screen-transitions)
20+
21+
### react-navigation-header-buttons
22+
23+
Helps you to render buttons in the navigation bar and handle the styling so you don't have to. It tries to mimic the appearance of native navbar buttons and attempts to offer a simple interface for you to interact with.
24+
25+
[Repository](https://github.com/vonovak/react-navigation-header-buttons)
26+
27+
### react-navigation-props-mapper
28+
29+
Provides simple HOCs that map react-navigation props to your screen components directly - ie. instead of `const user = this.props.route.params.activeUser`, you'd write `const user = this.props.activeUser`.
30+
31+
[Repository](https://github.com/vonovak/react-navigation-props-mapper)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
id: community-navigators
3+
title: Community navigators
4+
sidebar_label: Community navigators
5+
---
6+
7+
This guide lists various community navigators for React Navigation. These navigators offer provide UI components for navigation with the familiar React Navigation API.
8+
9+
If you're looking to build your own navigator, check out the [custom navigators guide](custom-navigators.md).
10+
11+
:::note
12+
13+
Please refer to the library's documentation to see which version of React Navigation it supports.
14+
15+
:::
16+
17+
## React Native Bottom Tabs
18+
19+
This project aims to expose the native Bottom Tabs component to React Native. It exposes SwiftUI's TabView on iOS and the material design tab bar on Android. Using `react-native-bottom-tabs` can bring several benefits, including multi-platform support and a native-feeling tab bar.
20+
21+
[Documentation](https://oss.callstack.com/react-native-bottom-tabs/)
22+
23+
[Repository](https://github.com/callstackincubator/react-native-bottom-tabs)
24+
25+
## BottomNavigation - React Native Paper
26+
27+
The library provides React Navigation integration for its Material Bottom Tabs. Material Bottom Tabs is a material-design themed tab bar on the bottom of the screen that lets you switch between different routes with animation.
28+
29+
[Documentation](https://callstack.github.io/react-native-paper/docs/guides/bottom-navigation/)
30+
31+
[Repository](https://github.com/callstack/react-native-paper)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
id: community-solutions
3+
title: Community solutions
4+
sidebar_label: Community solutions
5+
---
6+
7+
This guide lists various community navigation solutions built on top of React Navigation that offer a different API or complement React Navigation in some way.
8+
9+
:::note
10+
11+
Please refer to the library's documentation to see which version of React Navigation it supports.
12+
13+
:::
14+
15+
## Expo Router
16+
17+
Expo Router is a file-based router for React Native and web applications built by the Expo team.
18+
19+
[Documentation](https://docs.expo.dev/router/introduction/)
20+
21+
[Repository](https://github.com/expo/expo/tree/main/packages/expo-router)
22+
23+
## Solito
24+
25+
A wrapper around React Navigation and Next.js that lets you share navigation code across platforms. Also, it provides a set of patterns and examples for building cross-platform apps with React Native + Next.js.
26+
27+
[Documentation](https://solito.dev/)
28+
29+
[Repository](https://github.com/nandorojo/solito)
30+
31+
## Navio
32+
33+
Navio provides a different API for React Navigation. It's main goal is to improve DX by building the app layout in one place and using the power of TypeScript to provide route names autocompletion.
34+
35+
[Repository](https://github.com/kanzitelli/rn-navio)

0 commit comments

Comments
 (0)