我无法使用@react-navigation/drawer示例代码

问题描述 投票:0回答:1

我遵循了这个基于抽屉的导航的最小示例。 https://reactnavigation.org/docs/drawer-based-navigation/

import * as React from 'react';
import { Button, View } from 'react-native';
import { createDrawerNavigator } from '@react-navigation/drawer';
import { NavigationContainer } from '@react-navigation/native';

function HomeScreen({ navigation }) {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Button
        onPress={() => navigation.navigate('Notifications')}
        title="Go to notifications"
      />
    </View>
  );
}

function NotificationsScreen({ navigation }) {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Button onPress={() => navigation.goBack()} title="Go back home" />
    </View>
  );
}

const Drawer = createDrawerNavigator();

export default function App() {
  return (
    <NavigationContainer>
      <Drawer.Navigator initialRouteName="Home">
        <Drawer.Screen name="Home" component={HomeScreen} />
        <Drawer.Screen name="Notifications" component={NotificationsScreen} />
      </Drawer.Navigator>
    </NavigationContainer>
  );
}

这是示例代码。 我开始了新项目

npx react-native@latest init AwesomeProject
我从未更改过任何编码。但是,我有错误。

enter image description here

enter image description here

javascript android react-native mobile react-navigation-drawer
1个回答
0
投票

似乎错误与重新动画有关。 你是否正确完成了 babel 配置以重新启动?

尝试在 babel.config.js 中添加以下内容

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    [
      'react-native-reanimated/plugin',
      {
        relativeSourceLocation: true,
      },
    ],
  ],
};

© www.soinside.com 2019 - 2024. All rights reserved.