gpt4 book ai didi

react-native - 找不到变量: createDrawerNavigator

转载 作者:行者123 更新时间:2023-12-02 03:30:46 24 4
gpt4 key购买 nike

我正在尝试在我的应用程序中实现抽屉导航。我发现这个网站( https://reactnavigation.org/docs/en/drawer-based-navigation.html )提供了实现的代码示例,但是当我运行它时它说

can't find variable: createDrawerNavigator.

这意味着缺少导入。但是,我似乎无法找到合适的 createDrawerNavigator。想知道是否有人可以帮我解决这个问题!对于 React Native 来说还很陌生。

class MyHomeScreen extends React.Component {
static navigationOptions = {
drawerLabel: 'Home',
drawerIcon: ({
tintColor
}) => ( <
Image source = {
require('./chats-icon.png')
}
style = {
[styles.icon, {
tintColor: tintColor
}]
}
/>
),
};

render() {
return ( <
Button onPress = {
() => this.props.navigation.navigate('Notifications')
}
title = "Go to notifications" /
>
);
}
}

class MyNotificationsScreen extends React.Component {
static navigationOptions = {
drawerLabel: 'Notifications',
drawerIcon: ({
tintColor
}) => ( <
Image source = {
require('./notif-icon.png')
}
style = {
[styles.icon, {
tintColor: tintColor
}]
}
/>
),
};

render() {
return ( <
Button onPress = {
() => this.props.navigation.goBack()
}
title = "Go back home" /
>
);
}
}

const styles = StyleSheet.create({
icon: {
width: 24,
height: 24,
},
});

const MyApp = createDrawerNavigator({
Home: {
screen: MyHomeScreen,
},
Notifications: {
screen: MyNotificationsScreen,
},
});

最佳答案

您使用的每个子组件,首先必须导入它:如Pritish Vaidva提到你必须添加

import { createStackNavigator, createDrawerNavigator } from "react-navigation";

位于文件的头部。

关于react-native - 找不到变量: createDrawerNavigator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51950769/

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