Skip to content

Commit 431fb03

Browse files
committed
Various improvements to 7.x
1 parent 1e1f7f1 commit 431fb03

Some content is hidden

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

53 files changed

+301
-252
lines changed

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

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ This means:
8888

8989
This makes it impossible to navigate to the `Home` when the user is not signed in, and to `SignIn` when the user is signed in.
9090

91-
When the values returned by `useIsSignedin` and `useIsSignedOut` change, the screens matching the condition will change:
91+
When the values returned by `useIsSignedIn` and `useIsSignedOut` change, the screens matching the condition will change:
9292

93-
- Let's say, initially `useIsSignedOut` returns `true`. This means that `SignIn` screens is shown.
93+
- Let's say, initially `useIsSignedOut` returns `true`. This means that the `SignIn` screen is shown.
9494
- After the user signs in, the return value of `useIsSignedIn` will change to `true` and `useIsSignedOut` will change to `false`, which means:
95-
- React Navigation will see that the `SignIn` screen is no longer matches the condition, so it will remove the screen.
95+
- React Navigation will see that the `SignIn` screen no longer matches the condition, so it will remove the screen.
9696
- Then it'll show the `Home` screen automatically because that's the first screen available when `useIsSignedIn` returns `true`.
9797

9898
The order of the screens matters when there are multiple screens matching the condition. For example, if there are two screens matching `useIsSignedIn`, the first screen will be shown when the condition is `true`.
@@ -170,14 +170,14 @@ This means:
170170

171171
This makes it impossible to navigate to the `Home` when the user is not signed in, and to `SignIn` when the user is signed in.
172172

173-
When the value of `isSignedin` changes, the screens defined based on the condition will change:
173+
When the value of `isSignedIn` changes, the screens defined based on the condition will change:
174174

175-
- Let's say, initially `isSignedin` is `false`. This means that `SignIn` screens is shown.
176-
- After the user signs in, the value of `isSignedin` will change to `true`, which means:
175+
- Let's say, initially `isSignedIn` is `false`. This means that the `SignIn` screen is shown.
176+
- After the user signs in, the value of `isSignedIn` will change to `true`, which means:
177177
- React Navigation will see that the `SignIn` screen is no longer defined, so it will remove the screen.
178-
- Then it'll show the `Home` screen automatically because that's the first screen defined when `isSignedin` returns `true`.
178+
- Then it'll show the `Home` screen automatically because that's the first screen defined when `isSignedIn` returns `true`.
179179

180-
The order of the screens matters when there are multiple screens matching the condition. For example, if there are two screens defined based on `isSignedin`, the first screen will be shown when the condition is `true`.
180+
The order of the screens matters when there are multiple screens matching the condition. For example, if there are two screens defined based on `isSignedIn`, the first screen will be shown when the condition is `true`.
181181

182182
</TabItem>
183183
</Tabs>
@@ -228,16 +228,15 @@ export default function App() {
228228
<NavigationContainer>
229229
<Stack.Navigator>
230230
{isSignedIn ? (
231+
<Stack.Screen name="Home" component={HomeScreen} />
232+
) : (
231233
<Stack.Screen
232234
name="SignIn"
233-
component={SimpleSignInScreen}
235+
component={SignInScreen}
234236
options={{
235237
title: 'Sign in',
236238
}}
237-
initialParams={{ setUserToken }}
238239
/>
239-
) : (
240-
<Stack.Screen name="Home" component={HomeScreen} />
241240
)}
242241
</Stack.Navigator>
243242
</NavigationContainer>
@@ -285,16 +284,15 @@ return (
285284
<NavigationContainer>
286285
<Stack.Navigator>
287286
{isSignedIn ? (
287+
<Stack.Screen name="Home" component={HomeScreen} />
288+
) : (
288289
<Stack.Screen
289290
name="SignIn"
290-
component={SimpleSignInScreen}
291+
component={SignInScreen}
291292
options={{
292293
title: 'Sign in',
293294
}}
294-
initialParams={{ setUserToken }}
295295
/>
296-
) : (
297-
<Stack.Screen name="Home" component={HomeScreen} />
298296
)}
299297
</Stack.Navigator>
300298
</NavigationContainer>
@@ -348,14 +346,14 @@ We can use [`React.Fragment`](https://react.dev/reference/react/Fragment) or [`G
348346
```js
349347
isSignedIn ? (
350348
<>
351-
<Stack.Screen name="SignIn" component={SignInScreen} />
352-
<Stack.Screen name="SignUp" component={SignUpScreen} />
353-
<Stack.Screen name="ResetPassword" component={ResetPassword} />
349+
<Stack.Screen name="Home" component={HomeScreen} />
350+
<Stack.Screen name="Profile" component={ProfileScreen} />
354351
</>
355352
) : (
356353
<>
357-
<Stack.Screen name="Home" component={HomeScreen} />
358-
<Stack.Screen name="Profile" component={ProfileScreen} />
354+
<Stack.Screen name="SignIn" component={SignInScreen} />
355+
<Stack.Screen name="SignUp" component={SignUpScreen} />
356+
<Stack.Screen name="ResetPassword" component={ResetPasswordScreen} />
359357
</>
360358
);
361359
```

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,8 @@ const Tabs = createBottomTabNavigator({
457457
```js
458458
<Tab.Navigator
459459
screenOptions={{
460-
tabBarPosition: dimensions.width < 600 ? 'bottom' : 'left',
460+
tabBarPosition: isLargeScreen ? 'left' : 'bottom',
461+
tabBarVariant: isLargeScreen ? 'material' : 'uikit',
461462
tabBarLabelPosition: 'below-icon',
462463
}}
463464
>
@@ -731,7 +732,7 @@ function MyComponent() {
731732
const tabBarHeight = useBottomTabBarHeight();
732733

733734
return (
734-
<ScrollView contentStyle={{ paddingBottom: tabBarHeight }}>
735+
<ScrollView contentContainerStyle={{ paddingBottom: tabBarHeight }}>
735736
{/* Content */}
736737
</ScrollView>
737738
);
@@ -961,7 +962,6 @@ Bottom Tab Navigator exposes various options to configure the transition animati
961962
</Tabs>
962963
963964
Putting these together, you can customize the transition animation for a screen:
964-
965965
Putting these together, you can customize the transition animation for a screen:
966966
967967
```js name="Bottom Tabs custom animation" snack static2dynamic
@@ -1043,7 +1043,7 @@ import { TransitionSpecs } from '@react-navigation/bottom-tabs';
10431043
screen: Profile,
10441044
options: {
10451045
// highlight-start
1046-
transitionSpec: TransitionSpecs.CrossFadeSpec,
1046+
transitionSpec: TransitionSpecs.FadeSpec,
10471047
// highlight-end
10481048
},
10491049
},

versioned_docs/version-7.x/combine-static-with-dynamic.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const RootStack = createNativeStackNavigator({
3939
});
4040
```
4141

42-
Here, `FeedScreen` is a component that renders a tab navigator and is defined using the dynamic API:
42+
Here, `FeedScreen` is a component that renders a bottom tab navigator and is defined using the dynamic API:
4343

4444
```js
4545
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
@@ -58,8 +58,8 @@ function FeedScreen() {
5858

5959
This code will work, but we're missing 2 things:
6060

61-
- Linking configuration for the screens in the top tab navigator.
62-
- TypeScript types for the screens in the top tab navigator.
61+
- Linking configuration for the screens in the bottom tab navigator.
62+
- TypeScript types for the screens in the bottom tab navigator.
6363

6464
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:
6565

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Community navigators
44
sidebar_label: Community navigators
55
---
66

7-
This guide lists various community navigators for React Navigation. These navigators offer provide UI components for navigation with the familiar React Navigation API.
7+
This guide lists various community navigators for React Navigation. These navigators provide UI components for navigation with the familiar React Navigation API.
88

99
If you're looking to build your own navigator, check out the [custom navigators guide](custom-navigators.md).
1010

versioned_docs/version-7.x/configuring-links.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ const state = {
426426
sort: 'latest',
427427
},
428428
},
429-
];
430-
}
429+
],
430+
};
431431
```
432432

433433
See [Navigation State reference](navigation-state.md) for more details on how the state object is structured.
@@ -611,7 +611,7 @@ const HomeTabs = createBottomTabNavigator({
611611
screen: FeedScreen,
612612
},
613613
Profile: {
614-
screen: HomeScreen,
614+
screen: ProfileScreen,
615615
linking: {
616616
path: 'users/:id',
617617
},
@@ -710,7 +710,7 @@ const HomeTabs = createBottomTabNavigator({
710710
screen: FeedScreen,
711711
},
712712
Profile: {
713-
screen: HomeScreen,
713+
screen: ProfileScreen,
714714
linking: {
715715
path: 'users/:id',
716716
},
@@ -823,7 +823,7 @@ const HomeTabs = createBottomTabNavigator({
823823
screen: FeedScreen,
824824
},
825825
Profile: {
826-
screen: HomeScreen,
826+
screen: ProfileScreen,
827827
linking: {
828828
path: 'users/:id',
829829
},
@@ -927,7 +927,7 @@ By default, paths defined for each screen are matched against the URL relative t
927927
const ProfileTabs = createBottomTabNavigator({
928928
screens: {
929929
Profile: {
930-
screen: HomeScreen,
930+
screen: ProfileScreen,
931931
linking: {
932932
path: 'users/:id',
933933
},
@@ -979,7 +979,7 @@ In this case, it makes more sense to navigate to the `Profile` screen using a UR
979979
const ProfileTabs = createBottomTabNavigator({
980980
screens: {
981981
Profile: {
982-
screen: HomeScreen,
982+
screen: ProfileScreen,
983983
linking: {
984984
path: 'users/:id',
985985
// highlight-next-line
@@ -1037,13 +1037,13 @@ Sometimes, you may not want to have the route name of a screen in the path. For
10371037
const RootStack = createStackNavigator({
10381038
screens: {
10391039
Home: {
1040-
screen: ProfileScreen,
1040+
screen: HomeScreen,
10411041
linking: {
10421042
path: 'home',
10431043
},
10441044
},
10451045
Profile: {
1046-
screen: HomeScreen,
1046+
screen: ProfileScreen,
10471047
linking: {
10481048
path: 'users/:id',
10491049
},
@@ -1080,13 +1080,13 @@ You can specify an empty string as path or not specify a path at all, and React
10801080
const RootStack = createStackNavigator({
10811081
screens: {
10821082
Home: {
1083-
screen: ProfileScreen,
1083+
screen: HomeScreen,
10841084
linking: {
10851085
path: '',
10861086
},
10871087
},
10881088
Profile: {
1089-
screen: HomeScreen,
1089+
screen: ProfileScreen,
10901090
linking: {
10911091
path: 'users/:id',
10921092
},
@@ -1194,7 +1194,7 @@ const config = {
11941194
</TabItem>
11951195
</Tabs>
11961196
1197-
You can also provide a your own function to serialize the params. For example, let's say that you want to use a DD-MM-YYYY format in the path instead of a timestamp:
1197+
You can also provide your own function to serialize the params. For example, let's say that you want to use a DD-MM-YYYY format in the path instead of a timestamp:
11981198
11991199
<Tabs groupId="config" queryString="config">
12001200
<TabItem value="static" label="Static" default>
@@ -1213,7 +1213,9 @@ const RootStack = createStackNavigator({
12131213
date: (date) => {
12141214
const d = new Date(date);
12151215

1216-
return d.getFullYear() + '-' + d.getMonth() + '-' + d.getDate();
1216+
return (
1217+
d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate()
1218+
);
12171219
},
12181220
},
12191221
},
@@ -1237,7 +1239,7 @@ const config = {
12371239
date: (date) => {
12381240
const d = new Date(date);
12391241

1240-
return d.getFullYear() + '-' + d.getMonth() + '-' + d.getDate();
1242+
return d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate();
12411243
},
12421244
},
12431245
},
@@ -1254,7 +1256,7 @@ Depending on your requirements, you can use this functionality to parse and stri
12541256
12551257
If you need more complex matching logic, you can use regular expressions to match the path. For example, if you want to use the pattern `@username` to match a user's profile, you can use a regular expression to match the path. This allows you to have the same path pattern for multiple screens, but fine-tune the matching logic to be more specific for a particular screen.
12561258
1257-
Regular expressions can be specified between parentheses `(` and `)` in the after a param name. For example:
1259+
Regular expressions can be specified between parentheses `(` and `)` after a param name. For example:
12581260
12591261
<Tabs groupId="config" queryString="config">
12601262
<TabItem value="static" label="Static" default>

versioned_docs/version-7.x/contributing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ Much like the issue template, the [pull request template](https://github.com/rea
9898
- Run these commands in the terminal to download locally and install it:
9999

100100
```bash
101-
git clone https://github.com/<USERNAME>/navigation-ex.git
102-
cd navigation-ex
101+
git clone https://github.com/<USERNAME>/react-navigation.git
102+
cd react-navigation
103103
git remote add upstream https://github.com/react-navigation/react-navigation.git
104104
yarn
105105
```
@@ -134,7 +134,7 @@ yarn typescript --watch
134134

135135
### Run the Example App
136136

137-
The [example app](https://github.com/react-navigation/react-navigation/tree/main/packages/example) includes a variety of patterns and is used as a simple way for contributors to manually integration test changes.
137+
The [example app](https://github.com/react-navigation/react-navigation/tree/main/example) includes a variety of patterns and is used as a simple way for contributors to manually integration test changes.
138138

139139
While developing, you can run the [example app](https://github.com/react-navigation/react-navigation/tree/main/example) with [Expo](https://expo.io/) to test your changes:
140140

versioned_docs/version-7.x/custom-android-back-button-handling.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function ScreenWithCustomBackBehavior() {
6060
return (
6161
<View style={styles.container}>
6262
{listData.map((item) => (
63-
<>
63+
<React.Fragment key={item.key}>
6464
{isSelectionModeEnabled ? (
6565
<PlatformPressable
6666
onPress={() => {
@@ -85,7 +85,7 @@ function ScreenWithCustomBackBehavior() {
8585
{item.key}
8686
</Text>
8787
)}
88-
</>
88+
</React.Fragment>
8989
))}
9090
<Button
9191
onPress={() => setIsSelectionModeEnabled(!isSelectionModeEnabled)}
@@ -175,7 +175,7 @@ function ScreenWithCustomBackBehavior() {
175175
return (
176176
<View style={styles.container}>
177177
{listData.map((item) => (
178-
<>
178+
<React.Fragment key={item.key}>
179179
{isSelectionModeEnabled ? (
180180
<PlatformPressable
181181
onPress={() => {
@@ -200,7 +200,7 @@ function ScreenWithCustomBackBehavior() {
200200
{item.key}
201201
</Text>
202202
)}
203-
</>
203+
</React.Fragment>
204204
))}
205205
<Button
206206
onPress={() => setIsSelectionModeEnabled(!isSelectionModeEnabled)}

0 commit comments

Comments
 (0)