gpt4 book ai didi

react-native - 未定义不是抽屉导航中的函数(评估 '(0,_reactNavigation.stacknavigator)' )

转载 作者:行者123 更新时间:2023-12-02 05:53:39 24 4
gpt4 key购买 nike

在我的应用程序中,我需要抽屉导航,为此我使用 this 中的示例代码。我已将所有内容集成到我的应用程序中,但出现以下错误

undefined is not a function (evaluating '(0,_reactNavigation.stacknavigator)')

也安装了这个。

npm install react-navigation --save

但不知道为什么会出现这个错误,所以请指导我如何解决这个问题。

这是我的 app.js

import React, { Component } from 'react';
import { StyleSheet , Platform , View , Text , Image ,
TouchableOpacity , YellowBox } from 'react-native';
import { DrawerNavigator, StackNavigator } from 'react-navigation';

class NavigationDrawerStructure extends Component {
//Structure for the navigatin Drawer
toggleDrawer = () => {
//Props to open/close the drawer
this.props.navigationProps.toggleDrawer();
};
render() {
return (
<View style={{ flexDirection: 'row' }}>
<TouchableOpacity onPress={this.toggleDrawer.bind(this)}>
{/*Donute Button Image */}
<Image
source={require('./image/drawer.png')}
style={{ width: 25, height: 25, marginLeft: 5 }}
/>
</TouchableOpacity>
</View>
);
}
}

class Screen1 extends Component {
//Screen1 Component
render() {
return (
<View style={styles.MainContainer}>
<Text style={{ fontSize: 23 }}> Screen 1 </Text>
</View>
);
}
}

class Screen2 extends Component {
//Screen2 Component
render() {
return (
<View style={styles.MainContainer}>
<Text style={{ fontSize: 23 }}> Screen 2 </Text>
</View>
);
}
}

class Screen3 extends Component {
//Screen3 Component
render() {
return (
<View style={styles.MainContainer}>
<Text style={{ fontSize: 23 }}> Screen 3 </Text>
</View>
);
}
}

const FirstActivity_StackNavigator = StackNavigator({
//All the screen from the Screen1 will be indexed here
First: {
screen: Screen1,
navigationOptions: ({ navigation }) => ({
title: 'Screen1',
headerLeft: <NavigationDrawerStructure navigationProps={navigation} />,
headerStyle: {
backgroundColor: '#FF9800',
},
headerTintColor: '#fff',
}),
},
});

const Screen2_StackNavigator = StackNavigator({
//All the screen from the Screen2 will be indexed here
Second: {
screen: Screen2,
navigationOptions: ({ navigation }) => ({
title: 'Screen2',
headerLeft: <NavigationDrawerStructure navigationProps={navigation} />,
headerStyle: {
backgroundColor: '#FF9800',
},
headerTintColor: '#fff',
}),
},
});

const Screen3_StackNavigator = StackNavigator({
//All the screen from the Screen3 will be indexed here
Third: {
screen: Screen3,
navigationOptions: ({ navigation }) => ({
title: 'Screen3',
headerLeft: <NavigationDrawerStructure navigationProps={navigation} />,
headerStyle: {
backgroundColor: '#FF9800',
},
headerTintColor: '#fff',
}),
},
});

const DrawerNavigatorExample = DrawerNavigator({
//Drawer Optons and indexing
Screen1: { //Title
screen: FirstActivity_StackNavigator,
},

Screen2: {//Title
screen: Screen2_StackNavigator,
},

Screen3: {//Title
screen: Screen3_StackNavigator,
},
});
export default DrawerNavigatorExample;

const styles = StyleSheet.create({
MainContainer: {
flex: 1,
paddingTop: 20,
alignItems: 'center',
marginTop: 50,
justifyContent: 'center',
},
});

这是 package.json

{
"name": "DrawerNavigation",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.6.1",
"react-native": "0.57.5",
"react-native-vector-icons": "^6.1.0",
"react-navigation": "^3.0.0"
},
"devDependencies": {
"babel-jest": "23.6.0",
"jest": "23.6.0",
"metro-react-native-babel-preset": "0.49.2",
"react-test-renderer": "16.6.1"
},
"jest": {
"preset": "react-native"
}
}

如果我遵循以下示例也会遇到相同的错误。

https://medium.com/@mehulmistri/drawer-navigation-with-custom-side-menu-react-native-fbd5680060ba

enter image description here

任何人都可以帮忙

最佳答案

我希望这对你有帮助,它对我也有帮助!

App.js

import { createStackNavigator, createAppContainer } from 'react-navigation';
import HomeScreen from './yourScreenPath';

const AppNavigator = createStackNavigator({
Home: { screen: HomeScreen }
});

export default createAppContainer(AppNavigator);

查看链接:React Navigation

编辑:

较新的版本没有createStackNavigator,现在可以在 React Navigation Stack 找到该函数.

关于react-native - 未定义不是抽屉导航中的函数(评估 '(0,_reactNavigation.stacknavigator)' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53388478/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com