mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-02-12 09:21:09 +08:00
Exporting the underlying views makes it easy to build custom navigators on top of our views. Libraries such as react-native-router-flux rely on such exports to build custom routing solutions while being able to take advantage of our work. This can also be the solution to adding custom behaviour without us needing to add separate config to override the router.
@react-navigation/bottom-tabs
Bottom tab navigator for React Navigation following iOS design guidelines.
Installation
Open a Terminal in your project's folder and run,
yarn add @react-navigation/core @react-navigation/bottom-tabs
Now we need to install react-native-safe-area-context.
If you are using Expo, to ensure that you get the compatible versions of the libraries, run:
expo install react-native-safe-area-context
If you are not using Expo, run the following:
yarn add react-native-safe-area-context
If you are using Expo, you are done. Otherwise, continue to the next steps.
To complete the linking on iOS, make sure you have Cocoapods installed. Then run:
cd ios
pod install
cd ..
Usage
import { MaterialCommunityIcons } from 'react-native-vector-icons';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
const getTabBarIcon = name => ({ color, size }) => (
<MaterialCommunityIcons name={name} color={color} size={size} />
);
const BottomTabs = createBottomTabNavigator();
export default function App() {
return (
<BottomTabs.Navigator>
<BottomTabs.Screen
name="article"
component={Article}
options={{
tabBarLabel: 'Article',
tabBarIcon: getTabBarIcon('file-document-box'),
}}
/>
<BottomTabs.Screen
name="chat"
component={Chat}
options={{
tabBarLabel: 'Chat',
tabBarIcon: getTabBarIcon('message-reply'),
}}
/>
<BottomTabs.Screen
name="contacts"
component={Contacts}
options={{
tabBarLabel: 'Contacts',
tabBarIcon: getTabBarIcon('contacts'),
}}
/>
</BottomTabs.Navigator>
);
}