【问题标题】:createMaterialTopTabNavigator() has been moved to 'react-navigation-tabs' error react-nativecreateMaterialTopTabNavigator() 已移至“react-navigation-tabs”错误 react-native
【发布时间】:2019-10-12 23:59:13
【问题描述】:

在我的一个旧项目中,我已经从 react-navigation 3 升级到 react-navigation 4,当我尝试运行时,我得到了这个“createMaterialTopTabNavigator() has beenmoved to 'react-navigation-tabs'”错误。在我的其他项目中,代码运行良好。我什至删除了 node_modules 并重新安装了它,但我仍然收到此错误。有人可以帮我解决这个问题吗?

这是我的 App.js

import {createAppContainer, createSwitchNavigator, NavigationActions} from 'react-navigation'
import { createStackNavigator } from 'react-navigation-stack';
import { createMaterialTopTabNavigator } from 'react-navigation-tabs';
import { createDrawerNavigator, DrawerNavigatorItems, DrawerActions } from 'react-navigation-drawer';

const TabNavigator = createMaterialTopTabNavigator(
{
  Upcoming: { screen: UpcomingScreen },
  Accepted: { screen: AcceptedScreen },
  Ongoing: { screen: OngoingScreen },
  Completed: { screen: CompletedScreen },
},
{
  tabBarOptions: {
      activeTintColor: '#000000',
      inactiveTintColor: '#000000',
      upperCaseLabel: false,
      style: {
        backgroundColor: '#ffffff',
        paddingTop: calcHeight(2)
      },
      labelStyle: {
        textAlign: 'center',
        fontSize: 12,
        fontFamily: Fonts.LatoRegular,
        fontWeight: 'normal'
      },
      indicatorStyle: {
        borderBottomColor: '#365888',
        borderBottomWidth: 2,
      },
  },
},
);

这是 package.json

{
  "name": "rttDriver",
  "version": "0.0.1",
  "private": true,
  "rnpm": {
      "assets": [
      "./assets/fonts"
    ]
  },
  "scripts": {
      "start": "node node_modules/react-native/local-cli/cli.js start",
      "test": "jest"
  },
  "dependencies": {
  "@react-native-community/async-storage": "^1.6.1",
  "moment": "^2.24.0",
  "react": "16.8.3",
  "react-native": "0.59.9",
  "react-native-elements": "^1.1.0",
  "react-native-geolocation-service": "^3.0.0",
  "react-native-gesture-handler": "^1.4.1",
  "react-native-image-picker": "^0.28.0",
  "react-native-popup-dialog": "^0.18.3",
  "react-native-reanimated": "^1.3.0",
  "react-native-screens": "^1.0.0-alpha.23",
  "react-native-signature-capture": "^0.4.9",
  "react-native-svg": "^9.11.1",
  "react-native-svg-uri": "^1.2.3",
  "react-native-swiper": "^1.5.14",
  "react-native-vector-icons": "^6.6.0",
  "react-navigation": "^4.0.10",
  "react-navigation-drawer": "^1.4.0",
  "react-navigation-stack": "^1.9.4",
  "react-navigation-tabs": "^2.0.0-alpha.0"
  },
 "devDependencies": {
    "@babel/core": "7.5.5",
    "@babel/runtime": "7.5.5",
    "babel-jest": "24.9.0",
    "jest": "24.9.0",
    "jetifier": "^1.6.4",
    "metro-react-native-babel-preset": "0.56.0",
    "react-test-renderer": "16.8.3"
 },
 "jest": {
    "preset": "react-native"
  }
 }

我已经附上了下面的图片

【问题讨论】:

    标签: react-native react-navigation react-native-tabnavigator


    【解决方案1】:

    您似乎正在使用 react navigatin v4.x.x,在此版本中,所有类型的导航都移到了单独的子库中,请从 react-navigation-tabs 导入您的材料顶级导航器

    import createMaterialTopTabNavigator from 'react-navigation-tabs';
    

    【讨论】:

    • 嗨@soban,感谢您的回复,正如我在 App.js 文件中提到的那样,我已经单独移动了 createMaterialTopTabNavigator。
    • 不,这就是我想弄清楚的,为什么会出现这个错误
    • 好的,然后卸载你的应用,然后 react-native run-ios/android
    • 然后 npm start --reset-cache
    • 你有没有注意到模块的导入从{create...}变成了create..?
    【解决方案2】:

    【讨论】:

      【解决方案3】:

      只要输入

      npm install @react-navigation/bottom-tabs

      进入终端并重新启动它

      【讨论】:

        猜你喜欢
        • 2020-01-09
        • 1970-01-01
        • 2019-06-25
        • 1970-01-01
        • 2020-08-26
        • 2020-05-19
        • 1970-01-01
        • 1970-01-01
        • 2021-12-08
        相关资源
        最近更新 更多