【问题标题】:React native bottom tab navigation error, brand new app from expo template反应原生底部标签导航错误,来自博览会模板的全新应用
【发布时间】:2020-09-01 15:50:22
【问题描述】:

我刚刚使用 expo 模板创建了一个新应用程序,并且在不更改代码的情况下执行它会引发以下错误

    C02SW0WD:Projects user$ expo init testTabApp
? Choose a template: 
  ----- Managed workflow -----
  blank                 a minimal app as clean as an empty canvas 
  blank (TypeScript)    same as blank but with TypeScript configuration 
***❯ tabs                  several example screens and tabs using react-navigation*** 
  ----- Bare workflow -----
  minimal               bare and minimal, just the essentials to get you started 
  minimal (TypeScript)  same as minimal but with TypeScript configuration 

作为附加测试,我创建了一个黑色项目,也使用 expo init(空白 -> 一个像空白画布一样干净的最小应用程序),该应用程序按预期工作......然后我添加了底部选项卡导航所需的 npms:

  1. 纱线添加@react-navigation/native
  2. 纱线添加@react-navigation/bottom-tabs
  3. 纱线添加 react-native-screens
  4. 纱线添加 react-native-safe-area-context

之后我创建了两个空屏幕并修改了 App.js 以使用底部标签导航,如下所示:

import React from 'react';
import { Text, View } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import Chat from './screens/Chat';
import Home from './screens/Home';

const Tab = createBottomTabNavigator();

export default function App() {
  return (
    <NavigationContainer>
      <Tab.Navigator>
        <Tab.Screen name="Home" component={Home} />
        <Tab.Screen name="Chat" component={Chat} />
      </Tab.Navigator>
    </NavigationContainer>
  );
}

再次,关于“未定义不是函数('...Object.fromEntries...'附近)”的相同错误

有什么想法吗??

【问题讨论】:

    标签: react-native expo react-native-navigation


    【解决方案1】:

    更新:该问题已在软件包中修复,请将其更新到最新版本。 https://github.com/react-navigation/react-navigation/commit/51f4d11fdf4bd2bb06f8cd4094f051816590e62c

    缺少方法Object.fromEntries。 添加yarn add @babel/polyfill 并更新您的.babelrc 文件以使用它:

    {
        "presets": [
            "module:metro-react-native-babel-preset",
            "@babel/polyfill"
        ]
    }
    

    在那之后应该可以工作,更多信息可以在网站https://babeljs.io/docs/en/babel-polyfill上找到

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-23
      • 2020-04-23
      • 2021-11-08
      • 2021-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-03
      相关资源
      最近更新 更多