Skip to content

Commit 0e91be6

Browse files
committed
Fix docs for search tab on iOS for native bottom tabs
1 parent fb36ddb commit 0e91be6

File tree

1 file changed

+126
-8
lines changed

1 file changed

+126
-8
lines changed

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

Lines changed: 126 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,138 @@ The [`tabBarIcon`](#tabbaricon) and [`tabBarLabel`](#tabbarlabel) options will o
119119

120120
The `tabBarSystemItem` option has special styling and behavior when set to `search` on iOS 26+.
121121

122-
Additionally, when the `search` tab is selected, the tab bar transforms into a search field if the screen in the tab navigator or a nested [native stack navigator](native-stack-navigator.md) has [`headerSearchBarOptions`](native-stack-navigator.md#headersearchbaroptions) configured and the native header is shown with [`headerShown: true`](native-stack-navigator.md#headershown). This won't work if a custom header is provided with the `header` option.
122+
Additionally, when the `search` tab is selected, the tab bar transforms into a search field if:
123+
124+
- The screen has a nested [native stack navigator](native-stack-navigator.md)
125+
- The focused screen in the nested native stack has [`headerSearchBarOptions`](native-stack-navigator.md#headersearchbaroptions)
126+
127+
This won't work if `headerSearchBarOptions` is set on the tab screen itself.
123128

124129
Example:
125130

126-
```js
127-
tabBarSystemItem: 'search',
128-
headerShown: true,
129-
headerSearchBarOptions: {
130-
placeholder: 'Search',
131-
},
131+
```js name="Search Tab on iOS 26" snack static2dynamic
132+
import * as React from 'react';
133+
import { Platform, View, Text, FlatList } from 'react-native';
134+
import {
135+
createStaticNavigation,
136+
useNavigation,
137+
} from '@react-navigation/native';
138+
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
139+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
140+
141+
const DATA = [
142+
'Apple',
143+
'Banana',
144+
'Cherry',
145+
'Durian',
146+
'Elderberry',
147+
'Fig',
148+
'Grape',
149+
];
150+
151+
function HomeScreen() {
152+
return (
153+
<View
154+
style={{
155+
flex: 1,
156+
alignItems: 'center',
157+
justifyContent: 'center',
158+
}}
159+
>
160+
<Text>Home Screen</Text>
161+
</View>
162+
);
163+
}
164+
165+
function FruitsListScreen() {
166+
const [searchText, setSearchText] = React.useState('');
167+
168+
const filteredData = DATA.filter((item) =>
169+
item.toLowerCase().includes(searchText.toLowerCase())
170+
);
171+
172+
const navigation = useNavigation('FruitsList');
173+
174+
React.useEffect(() => {
175+
navigation.setOptions({
176+
headerSearchBarOptions: {
177+
placeholder: 'Search fruits',
178+
onChange: (e) => {
179+
setSearchText(e.nativeEvent.text);
180+
},
181+
},
182+
});
183+
}, [navigation]);
184+
185+
return (
186+
<FlatList
187+
data={filteredData}
188+
keyExtractor={(item) => item}
189+
renderItem={({ item }) => (
190+
<View
191+
style={{ padding: 16, borderBottomWidth: 1, borderColor: '#ccc' }}
192+
>
193+
<Text>{item}</Text>
194+
</View>
195+
)}
196+
/>
197+
);
198+
}
199+
200+
// codeblock-focus-start
201+
const SearchStack = createNativeStackNavigator({
202+
screens: {
203+
FruitsList: {
204+
screen: FruitsListScreen,
205+
options: {
206+
title: 'Search',
207+
// highlight-start
208+
headerSearchBarOptions: {
209+
placeholder: 'Search fruits',
210+
},
211+
// highlight-end
212+
},
213+
},
214+
},
215+
});
216+
217+
const HomeTabs = createBottomTabNavigator({
218+
screens: {
219+
Home: {
220+
screen: HomeScreen,
221+
options: {
222+
tabBarIcon: Platform.select({
223+
ios: {
224+
type: 'sfSymbol',
225+
name: 'house',
226+
},
227+
android: {
228+
type: 'materialSymbol',
229+
name: 'home',
230+
},
231+
}),
232+
},
233+
},
234+
Search: {
235+
// highlight-next-line
236+
screen: SearchStack,
237+
options: {
238+
// highlight-next-line
239+
tabBarSystemItem: 'search',
240+
},
241+
},
242+
},
243+
});
244+
// codeblock-focus-end
245+
246+
const Navigation = createStaticNavigation(HomeTabs);
247+
248+
export default function App() {
249+
return <Navigation />;
250+
}
132251
```
133252

134253
<video playsInline autoPlay muted loop>
135-
136254
<source src="/assets/navigators/bottom-tabs/highlights/search-tab.mp4" />
137255
</video>
138256

0 commit comments

Comments
 (0)