javascript - React Native 底部选项卡导航不起作用

标签 javascript reactjs react-native expo

我正在使用 React Native 和 Expo 尝试构建底部选项卡导航,但不确定导致错误的原因,我使用 React Navigation6

应用程序.js:

import React from 'react';
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import { NavigationContainer } from '@react-navigation/native';
import BottomBar from './src/Navbar/BottomBar';

export default function App() {
  return(
      <NavigationContainer>
         <BottomBar/>
      </NavigationContainer>
  )
};

错误:


Unable to resolve module src/Screens/Navigation/BottomNav from /Users/wafaturaifi/Desktop/Requests/App.js: src/Screens/Navigation/BottomNav could not be found within the project or in these directories:
  node_modules

If you are sure the module exists, try these steps:
 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*

BottomBar.js:

import React, { useEffect, useContext } from "react";
import { View } from "react-native";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import HomeScreen from '../Screens/Home';
import MoreScreen from '../Screens/More';
import PostScreen from '../Screens/Post';
import RequestsScreen from '../Screens/Requests';
import SummaryScreen from '../Screens/Summary';

const Tab = createBottomTabNavigator();

const BottomBar=() => {
  return (
    <Tab.Navigator>
      <Tab.Screen name="Home" component={HomeScreen} />
      <Tab.Screen name="Summary" component={SummaryScreen} />
      <Tab.Screen name="Add" component={AddScreen} />
      <Tab.Screen name="Requests" component={RequestsScreen} />
      <Tab.Screen name="More" component={MoreScreen} />
    </Tab.Navigator>
  );
}
export default BottomBar;

文件结构:

enter image description here

最佳答案

此问题是因为要使用 React Navigation,您需要运行以下命令

npm install react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context @react-native-community/masked-view

yarn add react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context @react-native-community/masked-view

关于javascript - React Native 底部选项卡导航不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71560069/

相关文章:

javascript - PHP/Javascript/AJAX - 使用表单重定向页面,然后提交

javascript - 代理不适用于生产中的 create-react-app

reactjs - 如何使用react-toastr?

react-native - React Native 找不到变量 $refresh req$

javascript - 如何使用 Cordova 在缩略图中显示缩小尺寸的图像

javascript - 如何在 dist 目录中生成单独的 package.json 文件?

javascript - ReactJS:渲染数组 block

javascript - CheckBoxes React Native Map函数返回错误: Too many re-renders. React限制渲染数量以防止无限循环

react-native - 框中出现奇怪的十字,代替了 React-native-paper 的复选框

javascript - 如何配置 Brunch.io 将 index.js 文件从 app/复制到 public/