📅  最后修改于: 2023-12-03 14:59:07.856000             🧑  作者: Mango
react-navigation bottom-tabs
is a navigation library for React Native that provides a tab-based navigation interface. It allows developers to create bottom tab bars with multiple screens and easily switch between them.
To install react-navigation bottom-tabs
, use the following command in your terminal:
npm install @react-navigation/bottom-tabs
or
yarn add @react-navigation/bottom-tabs
To use react-navigation bottom-tabs
, follow these steps:
createBottomTabNavigator
function.tabBarIcon
and tabBarLabel
properties for each screen.component
prop to the main NavigationContainer
component.Here is an example of how to use react-navigation bottom-tabs
:
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { NavigationContainer } from '@react-navigation/native';
import { Ionicons } from '@expo/vector-icons';
import HomeScreen from './screens/HomeScreen';
import ProfileScreen from './screens/ProfileScreen';
const Tab = createBottomTabNavigator();
function App() {
return (
<NavigationContainer>
<Tab.Navigator>
<Tab.Screen
name="Home"
component={HomeScreen}
options={{
tabBarIcon: ({ focused, color, size }) => (
<Ionicons
name={focused ? 'home' : 'home-outline'}
color={color}
size={size}
/>
),
tabBarLabel: 'Home',
}}
/>
<Tab.Screen
name="Profile"
component={ProfileScreen}
options={{
tabBarIcon: ({ focused, color, size }) => (
<Ionicons
name={focused ? 'person' : 'person-outline'}
color={color}
size={size}
/>
),
tabBarLabel: 'Profile',
}}
/>
</Tab.Navigator>
</NavigationContainer>
);
}
export default App;
react-navigation bottom-tabs
provides a convenient way to implement tab-based navigation in React Native applications. Its flexibility and customization options make it easy to create engaging user interfaces with multiple screens. Install it using the provided commands and start building amazing tab-based navigation experiences in your React Native projects.