Skip to content

Commit 5bddf22

Browse files
committed
Update docs with 7.x changes
1 parent de3124f commit 5bddf22

18 files changed

+262
-60
lines changed

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

+15
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,21 @@ const linking = {
6969
};
7070
```
7171

72+
### Filtering certain paths
73+
74+
Sometimes we may not want to handle all incoming links. For example, we may want to filter out links meant for authentication (e.g. `expo-auth-session`) or other purposes instead of navigating to a specific screen.
75+
76+
To achieve this, you can use the `filter` option:
77+
78+
```js
79+
const linking = {
80+
prefixes: ['mychat://', 'https://mychat.com'],
81+
filter: (url) => !url.includes('+expo-auth-session'),
82+
};
83+
```
84+
85+
This is not supported on Web as we always need to handle the URL of the page.
86+
7287
## Mapping path to route names
7388

7489
To handle a link, you need to translate it to a valid [navigation state](navigation-state.md) and vice versa. For example, the path `/rooms/chat?user=jane` may be translated to a state object like this:

versioned_docs/version-6.x/themes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ import { DefaultTheme, DarkTheme } from '@react-navigation/native';
7979

8080
## Using the operating system preferences
8181

82-
On iOS 13+ and Android 10+, you can get user's preferred color scheme (`'dark'` or `'light'`) with the ([Appearance API](https://reactnative.dev/docs/appearance)).
82+
On iOS 13+ and Android 10+, you can get user's preferred color scheme (`'dark'` or `'light'`) with the ([`useColorScheme` hook](https://reactnative.dev/docs/usecolorscheme)).
8383

8484
<samp id="system-themes" />
8585

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ function MyTabBar({ state, descriptors, navigation }) {
230230
accessibilityRole="button"
231231
accessibilityState={isFocused ? { selected: true } : {}}
232232
accessibilityLabel={options.tabBarAccessibilityLabel}
233-
testID={options.tabBarTestID}
233+
testID={options.tabBarButtonTestID}
234234
onPress={onPress}
235235
onLongPress={onLongPress}
236236
style={{ flex: 1 }}
@@ -319,10 +319,6 @@ Style for the badge on the tab icon. You can specify a background color or text
319319

320320
Accessibility label for the tab button. This is read by the screen reader when the user taps the tab. It's recommended to set this if you don't have a label for the tab.
321321

322-
#### `tabBarTestID`
323-
324-
ID to locate this tab button in tests.
325-
326322
#### `tabBarButton`
327323

328324
Function which returns a React element to render as the tab bar button. It wraps the icon and label. Renders `Pressable` by default.
@@ -333,6 +329,10 @@ You can specify a custom implementation here:
333329
tabBarButton: (props) => <TouchableOpacity {...props} />;
334330
```
335331

332+
#### `tabBarButtonTestID`
333+
334+
ID to locate this tab button in tests.
335+
336336
#### `tabBarActiveTintColor`
337337

338338
Color for the icon and label in the active tab.

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

+34
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,40 @@ const linking = {
6969
};
7070
```
7171

72+
### Filtering certain paths
73+
74+
Sometimes we may not want to handle all incoming links. For example, we may want to filter out links meant for authentication (e.g. `expo-auth-session`) or other purposes instead of navigating to a specific screen.
75+
76+
To achieve this, you can use the `filter` option:
77+
78+
```js
79+
const linking = {
80+
prefixes: ['mychat://', 'https://mychat.com'],
81+
// highlight-next-line
82+
filter: (url) => !url.includes('+expo-auth-session'),
83+
};
84+
```
85+
86+
This is not supported on Web as we always need to handle the URL of the page.
87+
88+
### Apps under subpaths
89+
90+
If your app is hosted under a subpath, you can specify the subpath at the top-level of the `config`. For example, if your app is hosted at `https://mychat.com/app`, you can specify the `path` as `app`:
91+
92+
```js
93+
const linking = {
94+
prefixes: ['mychat://', 'https://mychat.com'],
95+
config: {
96+
// highlight-next-line
97+
path: 'app',
98+
99+
// ...
100+
},
101+
};
102+
```
103+
104+
It's not possible to specify params here since this doesn't belong to a screen, e.g. `app/:id` won't work.
105+
72106
## Mapping path to route names
73107

74108
To handle a link, you need to translate it to a valid [navigation state](navigation-state.md) and vice versa. For example, the path `/rooms/chat?user=jane` may be translated to a state object like this:

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

+40-15
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ import {
145145

146146
// ...
147147

148-
export const createMyNavigator = createNavigatorFactory(TabNavigator);
148+
export function createMyNavigator(config) {
149+
return createNavigatorFactory(TabNavigator)(config);
150+
}
149151
```
150152
151153
Then it can be used like this:
@@ -181,19 +183,22 @@ import {
181183
View,
182184
Text,
183185
Pressable,
184-
StyleProp,
185-
ViewStyle,
186+
type StyleProp,
187+
type ViewStyle,
186188
StyleSheet,
187189
} from 'react-native';
188190
import {
189191
createNavigatorFactory,
190-
DefaultNavigatorOptions,
191-
ParamListBase,
192192
CommonActions,
193-
TabActionHelpers,
194-
TabNavigationState,
193+
type DefaultNavigatorOptions,
194+
type NavigatorTypeBagBase,
195+
type ParamListBase,
196+
type StaticConfig,
197+
type TabActionHelpers,
198+
type TabNavigationState,
195199
TabRouter,
196-
TabRouterOptions,
200+
type TabRouterOptions,
201+
type TypedNavigator,
197202
useNavigationBuilder,
198203
} from '@react-navigation/native';
199204

@@ -298,12 +303,30 @@ function TabNavigator({
298303
);
299304
}
300305

301-
export default createNavigatorFactory<
302-
TabNavigationState<ParamListBase>,
303-
TabNavigationOptions,
304-
TabNavigationEventMap,
305-
typeof TabNavigator
306-
>(TabNavigator);
306+
export function createMyNavigator<
307+
ParamList extends ParamListBase,
308+
NavigatorID extends string | undefined = undefined,
309+
TypeBag extends NavigatorTypeBagBase = {
310+
ParamList: ParamList;
311+
NavigatorID: NavigatorID;
312+
State: TabNavigationState<ParamList>;
313+
ScreenOptions: TabNavigationOptions;
314+
EventMap: TabNavigationEventMap;
315+
NavigationList: {
316+
[RouteName in keyof ParamList]: TabNavigationProp<
317+
ParamList,
318+
RouteName,
319+
NavigatorID
320+
>;
321+
};
322+
Navigator: typeof TabNavigator;
323+
},
324+
Config extends StaticConfig<TypeBag> | undefined =
325+
| StaticConfig<TypeBag>
326+
| undefined,
327+
>(config?: Config): TypedNavigator<TypeBag, Config> {
328+
return createNavigatorFactory(TabNavigator)(config);
329+
}
307330
```
308331
309332
## Extending Navigators
@@ -346,7 +369,9 @@ function BottomTabNavigator({
346369
);
347370
}
348371

349-
export default createNavigatorFactory(BottomTabNavigator);
372+
export function createMyNavigator(config) {
373+
return createNavigatorFactory(TabNavigator)(config);
374+
}
350375
```
351376
352377
Now, we can customize it to add additional functionality or change the behavior. For example, use a [custom router](custom-routers.md) instead of the default `TabRouter`:

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ npm install react-native-drawer-layout
2222

2323
Then, you need to install and configure the libraries that are required by the drawer:
2424

25-
1. First, install [`react-native-gesture-handler`](https://docs.swmansion.com/react-native-gesture-handler/) and [`react-native-reanimated`](https://docs.swmansion.com/react-native-reanimated/).
25+
1. First, install [`react-native-gesture-handler`](https://docs.swmansion.com/react-native-gesture-handler/) and [`react-native-reanimated`](https://docs.swmansion.com/react-native-reanimated/) (at least version 2 or 3).
2626

2727
If you have a Expo managed project, in your project directory, run:
2828

@@ -36,9 +36,9 @@ Then, you need to install and configure the libraries that are required by the d
3636
npm install react-native-gesture-handler react-native-reanimated
3737
```
3838

39-
The Drawer supports both Reanimated 1 and the latest version of Reanimated. If you want to use the latest version of Reanimated, make sure to configure it following the [installation guide](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started).
39+
2. Configure the Reanimated Babel Plugin in your project following the [installation guide](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started).
4040

41-
2. To finalize installation of `react-native-gesture-handler`, add the following at the **top** (make sure it's at the top and there's nothing else before it) of your entry file, such as `index.js` or `App.js`:
41+
3. To finalize the installation of `react-native-gesture-handler`, add the following at the **top** (make sure it's at the top and there's nothing else before it) of your entry file, such as `index.js` or `App.js`:
4242

4343
```js
4444
import 'react-native-gesture-handler';
@@ -50,7 +50,7 @@ Then, you need to install and configure the libraries that are required by the d
5050

5151
:::
5252

53-
3. If you're on a Mac and developing for iOS, you also need to install the pods (via [Cocoapods](https://cocoapods.org/)) to complete the linking.
53+
4. If you're on a Mac and developing for iOS, you also need to install the pods (via [Cocoapods](https://cocoapods.org/)) to complete the linking.
5454

5555
```bash
5656
npx pod-install ios

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ npm install @react-navigation/drawer@next
2222

2323
Then, you need to install and configure the libraries that are required by the drawer navigator:
2424

25-
1. First, install [`react-native-gesture-handler`](https://docs.swmansion.com/react-native-gesture-handler/) and [`react-native-reanimated`](https://docs.swmansion.com/react-native-reanimated/).
25+
1. First, install [`react-native-gesture-handler`](https://docs.swmansion.com/react-native-gesture-handler/) and [`react-native-reanimated`](https://docs.swmansion.com/react-native-reanimated/) (at least version 2 or 3).
2626

2727
If you have a Expo managed project, in your project directory, run:
2828

@@ -36,9 +36,9 @@ Then, you need to install and configure the libraries that are required by the d
3636
npm install react-native-gesture-handler react-native-reanimated
3737
```
3838

39-
The Drawer supports both Reanimated 1 and the latest version of Reanimated. If you want to use the latest version of Reanimated, make sure to configure it following the [installation guide](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started).
39+
2. Configure the Reanimated Babel Plugin in your project following the [installation guide](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started).
4040

41-
2. To finalize installation of `react-native-gesture-handler`, add the following at the **top** (make sure it's at the top and there's nothing else before it) of your entry file, such as `index.js` or `App.js`:
41+
3. To finalize the installation of `react-native-gesture-handler`, add the following at the **top** (make sure it's at the top and there's nothing else before it) of your entry file, such as `index.js` or `App.js`:
4242

4343
```js
4444
import 'react-native-gesture-handler';
@@ -50,7 +50,7 @@ Then, you need to install and configure the libraries that are required by the d
5050

5151
:::
5252

53-
3. If you're on a Mac and developing for iOS, you also need to install the pods (via [Cocoapods](https://cocoapods.org/)) to complete the linking.
53+
4. If you're on a Mac and developing for iOS, you also need to install the pods (via [Cocoapods](https://cocoapods.org/)) to complete the linking.
5454

5555
```bash
5656
npx pod-install ios

versioned_docs/version-7.x/material-top-tab-navigator.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ function MyTabBar({ state, descriptors, navigation, position }) {
274274
accessibilityRole="button"
275275
accessibilityState={isFocused ? { selected: true } : {}}
276276
accessibilityLabel={options.tabBarAccessibilityLabel}
277-
testID={options.tabBarTestID}
277+
testID={options.tabBarButtonTestID}
278278
onPress={onPress}
279279
onLongPress={onLongPress}
280280
style={{ flex: 1 }}
@@ -378,7 +378,7 @@ Style object for the tab bar indicator.
378378

379379
Style object for the view containing the tab bar indicator.
380380

381-
#### `tabBarTestID`
381+
#### `tabBarButtonTestID`
382382

383383
ID to locate this tab button in tests.
384384

versioned_docs/version-7.x/native-stack-navigator.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ Only supported on Android.
579579

580580
Style object for the scene content.
581581

582-
#### `customAnimationOnGesture`
582+
#### `animationMatchesGesture`
583583

584584
Whether the gesture to dismiss should use animation provided to `animation` prop. Defaults to `false`.
585585

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

+10
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,16 @@ const Tabs = createBottomTabNavigator({
246246
</Tabs>
247247
Now, if you have a stack with the history `Home > Profile (userId: bob) > Settings` and you call `navigate(Profile, { userId: 'alice' })`, 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.
248248

249+
### `navigateDeprecated`
250+
251+
:::warning
252+
253+
This method is deprecated and will be removed in a future release. It only exists for compatibility purposes. Use `navigate` instead.
254+
255+
:::
256+
257+
TODO
258+
249259
### `goBack`
250260

251261
The `goBack` method lets us go back to the previous screen in the navigator.

versioned_docs/version-7.x/screen-options.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export default function App() {
141141
</TabItem>
142142
</Tabs>
143143

144-
You can also pass a function to `options`. The function will receive the [`navigation` object](navigation-object.md) and the [`route` object](route-object.md) for that screen. This can be useful if you want to perform navigation in your options:
144+
You can also pass a function to `options`. The function will receive the [`navigation` object](navigation-object.md) and the [`route` object](route-object.md) for that screen, as well as the [`theme` object](themes.md). This can be useful if you want to perform navigation in your options:
145145

146146
<Tabs groupId="config" queryString="config">
147147
<TabItem value="static" label="Static" default>

versioned_docs/version-7.x/screen.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ const Stack = createNativeStackNavigator({
134134
</TabItem>
135135
</Tabs>
136136

137-
When you pass a function, it'll receive the [`route`](route-object.md) and [`navigation`](navigation-object.md):
137+
When you pass a function, it'll receive the [`route`](route-object.md), [`navigation`](navigation-object.md) and [`theme`](themes.md) as arguments:
138138

139139
<Tabs groupId="config" queryString="config">
140140
<TabItem value="static" label="Static" default>
@@ -144,7 +144,7 @@ const Stack = createNativeStackNavigator({
144144
screens: {
145145
Profile: {
146146
screen: ProfileScreen,
147-
options: ({ route, navigation }) => ({
147+
options: ({ route, navigation, theme }) => ({
148148
title: route.params.userId,
149149
}),
150150
},

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

+16-4
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,6 @@ This is shortcut option which configures several options to configure the style
255255

256256
See [Transparent modals](#transparent-modals) for more details on how to customize `transparentModal`.
257257

258-
#### `animationEnabled`
259-
260-
Whether transition animation should be enabled on the screen. If you set it to `false`, the screen won't animate when pushing or popping. Defaults to `true` on iOS and Android, `false` on Web.
261-
262258
#### `animationTypeForReplace`
263259

264260
The type of animation to use when this screen replaces another screen. It takes the following values:
@@ -646,6 +642,22 @@ function MyStack() {
646642

647643
## Animations
648644

645+
You can specify the `animation` option to customize the transition animation for screens being pushed or popped.
646+
647+
Supported values for `animation` are:
648+
649+
- `default` - Default animation based on the platform and OS version.
650+
- `fade` - Simple fade animation for dialogs.
651+
- `fade_from_bottom` - Standard Android-style fade in from the bottom for Android Oreo.
652+
- `reveal_from_bottom` - Standard Android-style reveal from the bottom for Android Pie.
653+
- `scale_from_center` - Scale animation from the center.
654+
- `slide_from_right` - Standard iOS-style slide in from the right.
655+
- `slide_from_left` - Similar to `slide_from_right`, but the screen will slide in from the left.
656+
- `slide_from_bottom` - Slide animation from the bottom for modals and bottom sheets.
657+
- `none` - The screens are pushed or popped immediately without any animation.
658+
659+
By default, Android and iOS use the `default` animation and other platforms use `none`.
660+
649661
### Animation related options
650662

651663
Stack Navigator exposes various options to configure the transition animation when a screen is added or removed. These transition animations can be customized on a per-screen basis by specifying the options in the `options` prop for each screen.

versioned_docs/version-7.x/static-configuration.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,14 @@ const RootStack = createNativeStackNavigator({
225225
});
226226
```
227227

228-
When you pass a function, it'll receive the [`route`](route-object.md) and [`navigation`](navigation-object.md):
228+
When you pass a function, it'll receive the [`route`](route-object.md), [`navigation`](navigation-object.md) and [`theme`](themes.md) as arguments:
229229

230230
```js
231231
const RootStack = createNativeStackNavigator({
232232
screens: {
233233
Profile: {
234234
screen: ProfileScreen,
235-
options: ({ route, navigation }) => ({
235+
options: ({ route, navigation, theme }) => ({
236236
title: route.params.userId,
237237
}),
238238
},

0 commit comments

Comments
 (0)