Skip to content

Commit 9d13c4d

Browse files
authored
Rework fundamentals to accomodate static API (#1293)
1 parent 4806039 commit 9d13c4d

Some content is hidden

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

43 files changed

+964
-471
lines changed

sidebars.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

static/examples/7.x/go-back.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import * as React from 'react';
22
import { Button, View, Text } from 'react-native';
3-
import { NavigationContainer } from '@react-navigation/native';
3+
import { NavigationContainer, useNavigation } from '@react-navigation/native';
44
import { createNativeStackNavigator } from '@react-navigation/native-stack';
55

6-
function HomeScreen({ navigation }) {
6+
function HomeScreen() {
7+
const navigation = useNavigation();
8+
79
return (
810
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
911
<Text>Home Screen</Text>
@@ -15,7 +17,9 @@ function HomeScreen({ navigation }) {
1517
);
1618
}
1719

18-
function DetailsScreen({ navigation }) {
20+
function DetailsScreen() {
21+
const navigation = useNavigation();
22+
1923
return (
2024
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
2125
<Text>Details Screen</Text>

static/examples/7.x/multiple-navigate.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import * as React from 'react';
22
import { Button, View, Text } from 'react-native';
3-
import { NavigationContainer } from '@react-navigation/native';
3+
import { NavigationContainer, useNavigation } from '@react-navigation/native';
44
import { createNativeStackNavigator } from '@react-navigation/native-stack';
55

6-
function HomeScreen({ navigation }) {
6+
function HomeScreen() {
7+
const navigation = useNavigation();
8+
79
return (
810
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
911
<Text>Home Screen</Text>
@@ -15,7 +17,9 @@ function HomeScreen({ navigation }) {
1517
);
1618
}
1719

18-
function DetailsScreen({ navigation }) {
20+
function DetailsScreen() {
21+
const navigation = useNavigation();
22+
1923
return (
2024
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
2125
<Text>Details Screen</Text>

static/examples/7.x/multiple-push.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import * as React from 'react';
22
import { Button, View, Text } from 'react-native';
3-
import { NavigationContainer } from '@react-navigation/native';
3+
import { NavigationContainer, useNavigation } from '@react-navigation/native';
44
import { createNativeStackNavigator } from '@react-navigation/native-stack';
55

6-
function HomeScreen({ navigation }) {
6+
function HomeScreen() {
7+
const navigation = useNavigation();
8+
79
return (
810
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
911
<Text>Home Screen</Text>
@@ -15,7 +17,9 @@ function HomeScreen({ navigation }) {
1517
);
1618
}
1719

18-
function DetailsScreen({ navigation }) {
20+
function DetailsScreen() {
21+
const navigation = useNavigation();
22+
1923
return (
2024
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
2125
<Text>Details Screen</Text>

static/examples/7.x/new-screen.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import * as React from 'react';
22
import { Button, View, Text } from 'react-native';
3-
import { NavigationContainer } from '@react-navigation/native';
3+
import { NavigationContainer, useNavigation } from '@react-navigation/native';
44
import { createNativeStackNavigator } from '@react-navigation/native-stack';
55

6-
function HomeScreen({ navigation }) {
6+
function HomeScreen() {
7+
const navigation = useNavigation();
8+
79
return (
810
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
911
<Text>Home Screen</Text>

static/examples/7.x/params-nested-navigators.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import * as React from 'react';
22
import { Button, View, Text } from 'react-native';
3-
import { NavigationContainer } from '@react-navigation/native';
3+
import { NavigationContainer, useNavigation } from '@react-navigation/native';
44
import { createNativeStackNavigator } from '@react-navigation/native-stack';
55
import { createDrawerNavigator } from '@react-navigation/drawer';
66

7-
function SettingsScreen({ route, navigation }) {
7+
function SettingsScreen({ route }) {
8+
const navigation = useNavigation();
9+
810
const { user } = route.params;
911
return (
1012
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
@@ -18,15 +20,19 @@ function SettingsScreen({ route, navigation }) {
1820
);
1921
}
2022

21-
function ProfileScreen({ navigation }) {
23+
function ProfileScreen() {
24+
const navigation = useNavigation();
25+
2226
return (
2327
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
2428
<Text>Profile Screen</Text>
2529
</View>
2630
);
2731
}
2832

29-
function HomeScreen({ navigation }) {
33+
function HomeScreen() {
34+
const navigation = useNavigation();
35+
3036
return (
3137
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
3238
<Text>Home Screen</Text>

static/examples/7.x/passing-params-back.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import * as React from 'react';
22
import { Text, TextInput, View, Button } from 'react-native';
3-
import { NavigationContainer } from '@react-navigation/native';
3+
import { NavigationContainer, useNavigation } from '@react-navigation/native';
44
import { createNativeStackNavigator } from '@react-navigation/native-stack';
55

6-
function HomeScreen({ navigation, route }) {
6+
function HomeScreen({ route }) {
7+
const navigation = useNavigation();
8+
79
React.useEffect(() => {
810
if (route.params?.post) {
911
// Post updated, do something with `route.params.post`
@@ -22,7 +24,8 @@ function HomeScreen({ navigation, route }) {
2224
);
2325
}
2426

25-
function CreatePostScreen({ navigation, route }) {
27+
function CreatePostScreen({ route }) {
28+
const navigation = useNavigation();
2629
const [postText, setPostText] = React.useState('');
2730

2831
return (

static/examples/7.x/passing-params.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import * as React from 'react';
22
import { Text, View, Button } from 'react-native';
3-
import { NavigationContainer } from '@react-navigation/native';
3+
import { NavigationContainer, useNavigation } from '@react-navigation/native';
44
import { createNativeStackNavigator } from '@react-navigation/native-stack';
55

6-
function HomeScreen({ navigation }) {
6+
function HomeScreen() {
7+
const navigation = useNavigation();
8+
79
return (
810
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
911
<Text>Home Screen</Text>
@@ -21,7 +23,9 @@ function HomeScreen({ navigation }) {
2123
);
2224
}
2325

24-
function DetailsScreen({ route, navigation }) {
26+
function DetailsScreen({ route }) {
27+
const navigation = useNavigation();
28+
2529
/* 2. Get the param */
2630
const { itemId } = route.params;
2731
const { otherParam } = route.params;

static/examples/7.x/pop-to-top.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import * as React from 'react';
22
import { Button, View, Text } from 'react-native';
3-
import { NavigationContainer } from '@react-navigation/native';
3+
import { NavigationContainer, useNavigation } from '@react-navigation/native';
44
import { createNativeStackNavigator } from '@react-navigation/native-stack';
55

6-
function HomeScreen({ navigation }) {
6+
function HomeScreen() {
7+
const navigation = useNavigation();
8+
79
return (
810
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
911
<Text>Home Screen</Text>
@@ -15,7 +17,9 @@ function HomeScreen({ navigation }) {
1517
);
1618
}
1719

18-
function DetailsScreen({ navigation }) {
20+
function DetailsScreen() {
21+
const navigation = useNavigation();
22+
1923
return (
2024
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
2125
<Text>Details Screen</Text>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ The `Tab.Navigator` component accepts following props:
5353

5454
#### `id`
5555

56-
Optional unique ID for the navigator. This can be used with [`navigation.getParent`](navigation-prop.md#getparent) to refer to this navigator in a child navigator.
56+
Optional unique ID for the navigator. This can be used with [`navigation.getParent`](navigation-object.md#getparent) to refer to this navigator in a child navigator.
5757

5858
#### `initialRouteName`
5959

@@ -442,7 +442,7 @@ React.useEffect(() => {
442442

443443
### Helpers
444444

445-
The tab navigator adds the following methods to the navigation prop:
445+
The tab navigator adds the following methods to the navigation object:
446446

447447
#### `jumpTo`
448448

versioned_docs/version-7.x/connecting-navigation-prop.md

Lines changed: 0 additions & 48 deletions
This file was deleted.

versioned_docs/version-7.x/custom-navigators.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The hook returns an object with following properties:
4040
- `navigation` - The navigation object containing various helper methods for the navigator to manipulate the [navigation state](navigation-state.md). This isn't the same as the navigation object for the screen and includes some helpers such as `emit` to emit events to the screens.
4141
- `descriptors` - This is an object containing descriptors for each route with the route keys as its properties. The descriptor for a route can be accessed by `descriptors[route.key]`. Each descriptor contains the following properties:
4242

43-
- `navigation` - The navigation prop for the screen. You don't need to pass this to the screen manually. But it's useful if we're rendering components outside the screen that need to receive `navigation` prop as well, such as a header component.
43+
- `navigation` - The navigation object for the screen. You don't need to pass this to the screen manually. But it's useful if we're rendering components outside the screen that need to receive `navigation` prop as well, such as a header component.
4444
- `options` - A getter which returns the options such as `title` for the screen if they are specified.
4545
- `render` - A function which can be used to render the actual screen. Calling `descriptors[route.key].render()` will return a React element containing the screen content. It's important to use this method to render a screen, otherwise any child navigators won't be connected to the navigation tree properly.
4646

versioned_docs/version-7.x/custom-routers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ const MyTabRouter = options => {
182182
};
183183
```
184184

185-
Instead of writing a custom router to handle custom actions, you can [pass a function to `dispatch`](navigation-prop.md#dispatch) instead. It's cleaner and recommended instead of overriding routers.
185+
Instead of writing a custom router to handle custom actions, you can [pass a function to `dispatch`](navigation-object.md#dispatch) instead. It's cleaner and recommended instead of overriding routers.
186186

187187
### Blocking Navigation Actions
188188

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ The `Drawer.Navigator` component accepts following props:
9191

9292
#### `id`
9393

94-
Optional unique ID for the navigator. This can be used with [`navigation.getParent`](navigation-prop.md#getparent) to refer to this navigator in a child navigator.
94+
Optional unique ID for the navigator. This can be used with [`navigation.getParent`](navigation-object.md#getparent) to refer to this navigator in a child navigator.
9595

9696
#### `initialRouteName`
9797

@@ -529,7 +529,7 @@ If you have custom drawer content, make sure to emit this event.
529529

530530
### Helpers
531531

532-
The drawer navigator adds the following methods to the navigation prop:
532+
The drawer navigator adds the following methods to the navigation object:
533533

534534
#### `openDrawer`
535535

versioned_docs/version-7.x/getting-started.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ title: Getting started
44
sidebar_label: Getting started
55
---
66

7+
import Tabs from '@theme/Tabs';
8+
import TabItem from '@theme/TabItem';
9+
710
What follows within the _Fundamentals_ section of this documentation is a tour of the most important aspects of React Navigation. It should cover enough for you to know how to build your typical small mobile application, and give you the background that you need to dive deeper into the more advanced parts of React Navigation.
811

912
## Pre-requisites
@@ -114,9 +117,25 @@ When you use a navigator (such as stack navigator), you'll need to follow the in
114117

115118
:::
116119

117-
## Wrapping your app in `NavigationContainer`
120+
## Setting up React Navigation
121+
122+
Once you've installed and configured the dependencies, you can move on to setting up your project to use React Navigation.
123+
124+
When using React Navigation, you configure [**navigators**](glossary-of-terms.md#navigator) in your app. Navigators handle the transition between screens in your app and provide UI such as header, tab bar etc.
125+
126+
There are 2 primary ways to configure the navigators:
127+
128+
### Static configuration
118129

119-
Now, we need to wrap the whole app in `NavigationContainer`. Usually you'd do this in your entry file, such as `index.js` or `App.js`:
130+
The static configuration API has reduced boilerplate and simplifies things such as TypeScript types and deep linking. If you're starting a new project or are new to React Navigation, this is the **recommended way** to set up your app. If you need more flexibility in the future, you can always mix and match with the dynamic configuration.
131+
132+
Continue to ["Hello React Navigation"](hello-react-navigation.md?config=static) to start writing some code with the static API.
133+
134+
### Dynamic configuration
135+
136+
The dynamic configuration allows for more flexibility but requires more boilerplate and configuration (e.g. for deep links, typescript etc.).
137+
138+
To get started with dynamic configuration, first, we need to wrap your app in `NavigationContainer`. Usually, you'd do this in your entry file, such as `index.js` or `App.js`:
120139

121140
```js
122141
import * as React from 'react';
@@ -135,6 +154,4 @@ In a typical React Native app, the `NavigationContainer` should be only used onc
135154

136155
:::
137156

138-
Now you are ready to build and run your app on the device/simulator.
139-
140-
Continue to ["Hello React Navigation"](hello-react-navigation.md) to start writing some code.
157+
Continue to ["Hello React Navigation"](hello-react-navigation.md?config=dynamic) to start writing some code with the dynamic API.

0 commit comments

Comments
 (0)