Complete the code to import the component needed to create a custom tab bar in React Native.
import { [1] } from 'react-native';
The View component is used as a container to build custom tab bars in React Native.
Complete the code to define a functional component named CustomTabBar.
const CustomTabBar = ([1]) => { return null; };
Functional components receive props as their argument to access passed data.
Fix the error in the code to render a tab button with a label from props.
return ( <View> <Text>[1]</Text> </View> );
Inside a functional component, props are accessed directly as props.label.
Fill both blanks to handle a press event on the tab button.
<TouchableOpacity onPress=[1]> <Text>[2]</Text> </TouchableOpacity>
The onPress event is handled by props.onPress, and the label text is props.label.
Fill all three blanks to create a custom tab bar that maps over routes and renders buttons.
const CustomTabBar = ({ state, descriptors, navigation }) => {
return (
<View style={{ flexDirection: '[1]' }}>
{state.routes.map((route, index) => {
const { options } = descriptors[route.key];
const label = options.tabBarLabel ?? options.title ?? route.name;
const isFocused = state.index === index;
const onPress = () => {
navigation.navigate(route.name);
};
return (
<TouchableOpacity
key={route.key}
onPress={onPress}
style={{ flex: 1, alignItems: '[2]' }}
>
<Text style={{ color: isFocused ? '[3]' : '#222' }}>
{label}
</Text>
</TouchableOpacity>
);
})}
</View>
);
};The tab bar arranges buttons in a row. Buttons align items to center. The focused tab text color is blue.