@@ -227,9 +227,13 @@ Example:
227227<samp id =" material-top-tab-custom-tab-bar " />
228228
229229``` js
230- import { Animated , View , TouchableOpacity } from ' react-native' ;
230+ import { Animated , View , TouchableOpacity , Platform } from ' react-native' ;
231+ import { useLinkBuilder , useTheme } from ' @react-navigation/native' ;
231232
232233function MyTabBar ({ state, descriptors, navigation, position }) {
234+ const { colors } = useTheme ();
235+ const { buildHref } = useLinkBuilder ();
236+
233237 return (
234238 < View style= {{ flexDirection: ' row' }}>
235239 {state .routes .map ((route , index ) => {
@@ -238,8 +242,8 @@ function MyTabBar({ state, descriptors, navigation, position }) {
238242 options .tabBarLabel !== undefined
239243 ? options .tabBarLabel
240244 : options .title !== undefined
241- ? options .title
242- : route .name ;
245+ ? options .title
246+ : route .name ;
243247
244248 const isFocused = state .index === index;
245249
@@ -251,8 +255,7 @@ function MyTabBar({ state, descriptors, navigation, position }) {
251255 });
252256
253257 if (! isFocused && ! event .defaultPrevented ) {
254- // The `merge: true` option makes sure that the params inside the tab screen are preserved
255- navigation .navigate ({ name: route .name , merge: true });
258+ navigation .navigate (route .name , route .params );
256259 }
257260 };
258261
@@ -266,20 +269,21 @@ function MyTabBar({ state, descriptors, navigation, position }) {
266269 const inputRange = state .routes .map ((_ , i ) => i);
267270 const opacity = position .interpolate ({
268271 inputRange,
269- outputRange: inputRange .map (i => (i === index ? 1 : 0 )),
272+ outputRange: inputRange .map (( i ) => (i === index ? 1 : 0 )),
270273 });
271274
272275 return (
273276 < TouchableOpacity
274- accessibilityRole= " button"
277+ href= {buildHref (route .name , route .params )}
278+ accessibilityRole= {Platform .OS === ' web' ? ' link' : ' button' }
275279 accessibilityState= {isFocused ? { selected: true } : {}}
276280 accessibilityLabel= {options .tabBarAccessibilityLabel }
277281 testID= {options .tabBarButtonTestID }
278282 onPress= {onPress}
279283 onLongPress= {onLongPress}
280284 style= {{ flex: 1 }}
281285 >
282- < Animated .Text style= {{ opacity }}>
286+ < Animated .Text style= {{ opacity, color : colors . text }}>
283287 {label}
284288 < / Animated .Text >
285289 < / TouchableOpacity>
@@ -291,9 +295,9 @@ function MyTabBar({ state, descriptors, navigation, position }) {
291295
292296// ...
293297
294- < Tab .Navigator tabBar= {props => < MyTabBar {... props} / > }>
295- {... }
296- < / Tab .Navigator >
298+ < Tab .Navigator tabBar= {( props ) => < MyTabBar {... props} / > }>
299+ {/* ... */ }
300+ < / Tab .Navigator > ;
297301```
298302
299303This example will render a basic tab bar with labels.
0 commit comments