Skip to content

Commit cd42f2d

Browse files
committed
Document tabBarSelectionEnabled
1 parent d14ec2f commit cd42f2d

2 files changed

Lines changed: 27 additions & 66 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,14 @@ Only supported on iOS 26 and above.
495495
<source src="/assets/navigators/bottom-tabs/highlights/minimize-on-scroll.mp4" />
496496
</video>
497497

498+
#### `tabBarSelectionEnabled`
499+
500+
Whether this tab can be selected.
501+
502+
When `false`, tapping on the tab in tab bar won't select the tab. Custom behavior can be implemented by listening to [`tabPress`](#tabpress) event.
503+
504+
Defaults to `true`.
505+
498506
#### `bottomAccessory`
499507

500508
Function that returns a React element to display as an accessory view. The function receives an options object with a `placement` parameter that can be one of the following values:
@@ -556,8 +564,6 @@ This event is fired when the user presses the tab button for the current screen
556564
- If the screen for the tab renders a scroll view, you can use [`useScrollToTop`](use-scroll-to-top.md) to scroll it to top
557565
- If the screen for the tab renders a stack navigator, a `popToTop` action is performed on the stack
558566

559-
The default behavior of the tab press is controlled natively and cannot be prevented.
560-
561567
```js
562568
React.useEffect(() => {
563569
const unsubscribe = navigation.addListener('tabPress', (e) => {
@@ -569,6 +575,8 @@ React.useEffect(() => {
569575
}, [navigation]);
570576
```
571577

578+
The default behavior of the tab press is controlled natively and cannot be prevented. Use the [`tabBarSelectionEnabled`](#tabbarselectionenabled) option to prevent the tab from being selected when pressed if you want to implement custom behavior.
579+
572580
#### `transitionStart`
573581

574582
This event is fired when the transition animation starts for the current screen.

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

Lines changed: 17 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,14 @@ Only supported with `native` implementation on iOS 26 and above.
10351035
<source src="/assets/navigators/bottom-tabs/highlights/minimize-on-scroll.mp4" />
10361036
</video>
10371037

1038+
#### `tabBarSelectionEnabled`
1039+
1040+
Whether this tab can be selected.
1041+
1042+
When `false`, tapping on the tab in tab bar won't select the tab. Custom behavior can be implemented by listening to [`tabPress`](#tabpress) event.
1043+
1044+
Defaults to `true`.
1045+
10381046
#### `bottomAccessory`
10391047

10401048
Function that returns a React element to display as an accessory view. The function receives an options object with a `placement` parameter that can be one of the following values:
@@ -1161,73 +1169,18 @@ This event is fired when the user presses the tab button for the current screen
11611169
- If the screen for the tab renders a scroll view, you can use [`useScrollToTop`](use-scroll-to-top.md) to scroll it to top
11621170
- If the screen for the tab renders a stack navigator, a `popToTop` action is performed on the stack
11631171

1164-
To prevent the default behavior, you can call `event.preventDefault`.
1165-
1166-
:::note
1167-
1168-
Calling `event.preventDefault` is only supported with the `custom` implementation. The default behavior cannot be prevented with the `native` implementation.
1169-
1170-
:::
1171-
1172-
```js name="Tab Press Event" snack static2dynamic
1173-
import * as React from 'react';
1174-
import { Alert, Text, View } from 'react-native';
1175-
import {
1176-
createStaticNavigation,
1177-
useNavigation,
1178-
} from '@react-navigation/native';
1179-
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
1180-
1181-
function HomeScreen() {
1182-
const navigation = useNavigation('Home');
1183-
1184-
// codeblock-focus-start
1185-
React.useEffect(() => {
1186-
const unsubscribe = navigation.addListener('tabPress', (e) => {
1187-
// Prevent default behavior
1188-
e.preventDefault();
1189-
1190-
// Do something manually
1191-
// ...
1192-
});
1193-
1194-
return unsubscribe;
1195-
}, [navigation]);
1196-
// codeblock-focus-end
1197-
1198-
return (
1199-
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
1200-
<Text>Home Screen</Text>
1201-
<Text style={{ marginTop: 10, color: 'gray' }}>
1202-
Tab press event is prevented
1203-
</Text>
1204-
</View>
1205-
);
1206-
}
1207-
1208-
function SettingsScreen() {
1209-
return (
1210-
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
1211-
<Text>Settings Screen</Text>
1212-
</View>
1213-
);
1214-
}
1215-
1216-
const MyTabs = createBottomTabNavigator({
1217-
screens: {
1218-
Home: HomeScreen,
1219-
Settings: SettingsScreen,
1220-
},
1221-
});
1222-
1223-
const Navigation = createStaticNavigation(MyTabs);
1172+
```js
1173+
React.useEffect(() => {
1174+
const unsubscribe = navigation.addListener('tabPress', (e) => {
1175+
// Do something manually
1176+
// ...
1177+
});
12241178

1225-
export default function App() {
1226-
return <Navigation />;
1227-
}
1179+
return unsubscribe;
1180+
}, [navigation]);
12281181
```
12291182

1230-
If you have a custom tab bar, make sure to emit this event.
1183+
The default behavior of the tab press is controlled natively and cannot be prevented. Use the [`tabBarSelectionEnabled`](#tabbarselectionenabled) option to prevent the tab from being selected when pressed if you want to implement custom behavior.
12311184

12321185
:::note
12331186

0 commit comments

Comments
 (0)