📌  相关文章
📜  @react-navigation bottom-tabs install - Shell-Bash (1)

📅  最后修改于: 2023-12-03 14:59:07.856000             🧑  作者: Mango

react-navigation bottom-tabs

Introduction

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.

Installation

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
Usage

To use react-navigation bottom-tabs, follow these steps:

  1. Create a new navigator using the createBottomTabNavigator function.
  2. Define your screens as components using React Native components.
  3. Define your tabs in the navigator by specifying the tabBarIcon and tabBarLabel properties for each screen.
  4. Pass the newly created navigator as the 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;
Conclusion

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.