React native 反应本机导航抽屉未打开
我是个新手。通过大量搜索,我发现给抽屉一个固定的宽度可以解决这个问题。但这并不能解决我的问题。我不知道代码出了什么问题。每次运行代码时,我都会得到“undefined不是对象”。这是代码 这是我的仪表板文件React native 反应本机导航抽屉未打开,react-native,navigation-drawer,React Native,Navigation Drawer,我是个新手。通过大量搜索,我发现给抽屉一个固定的宽度可以解决这个问题。但这并不能解决我的问题。我不知道代码出了什么问题。每次运行代码时,我都会得到“undefined不是对象”。这是代码 这是我的仪表板文件 export class Dashboard extends Component { static navigationOptions = ({ navigation }: { navigation: any }) => ({ drawerLabel: "Dashboard
export class Dashboard extends Component {
static navigationOptions = ({ navigation }: { navigation: any }) => ({
drawerLabel: "Dashboard",
title: "Dashboard",
headerLeft: (
<View style={{ paddingHorizontal: 10 }}>
<TouchableOpacity onPress={() => navigation.navigate("DrawerOpen")}>
<Icon name="menu" size={30} color="black" />
</TouchableOpacity>
</View>
)
});
render() {
return (
<Text>Dashboard</Text>
)
}
}
const MainScreenNavigator = StackNavigator({
DashboardScreen: { screen: Profile },
ProfileScreen: { screen: Profile },
},
{
initialRouteName: "DashboardScreen",
}
);
const Drawer = DrawerNavigator(
{
Main: { screen: MainScreenNavigator }
},
{
drawerWidth: 200
}
);
export default Drawer;
export class Profile extends Component<NavigationScreenProps<ProfileProps>> {
constructor(props: NavigationScreenProps<ProfileProps>) {
super(props);
this.state = {
status: "initial" // initial | failed | success
}
}
static navigationOptions = ( {navigation} : {navigation : any} ) => ({
drawerLabel: "Pied Piper",
title: "Pied Piper",
headerLeft: (
<View style={{ paddingHorizontal: 10 }}>
<TouchableOpacity onPress={() => navigation.navigate("DrawerOpen")}>
<Icon name="menu" size={30} color="blue" />
</TouchableOpacity>
</View>
)
});
render() {
return (
<View style={ProfileStyle.container}>
<Text>Profile</Text>
</View>
);
}
}
export default Profile;
导出类仪表板扩展组件{
静态导航选项=({navigation}:{navigation:any})=>({
抽屉标签:“仪表板”,
标题:“仪表板”,
左校长:(
导航。导航(“抽屉”)}>
)
});
render(){
返回(
仪表板
)
}
}
常量MainScreenNavigator=StackNavigator({
仪表板屏幕:{screen:Profile},
ProfileScreen:{screen:Profile},
},
{
initialRouteName:“仪表板屏幕”,
}
);
const Drawer=付款人(
{
主:{屏幕:主屏幕导航器}
},
{
抽屉宽度:200
}
);
导出默认抽屉;
这是我的个人资料文件
export class Dashboard extends Component {
static navigationOptions = ({ navigation }: { navigation: any }) => ({
drawerLabel: "Dashboard",
title: "Dashboard",
headerLeft: (
<View style={{ paddingHorizontal: 10 }}>
<TouchableOpacity onPress={() => navigation.navigate("DrawerOpen")}>
<Icon name="menu" size={30} color="black" />
</TouchableOpacity>
</View>
)
});
render() {
return (
<Text>Dashboard</Text>
)
}
}
const MainScreenNavigator = StackNavigator({
DashboardScreen: { screen: Profile },
ProfileScreen: { screen: Profile },
},
{
initialRouteName: "DashboardScreen",
}
);
const Drawer = DrawerNavigator(
{
Main: { screen: MainScreenNavigator }
},
{
drawerWidth: 200
}
);
export default Drawer;
export class Profile extends Component<NavigationScreenProps<ProfileProps>> {
constructor(props: NavigationScreenProps<ProfileProps>) {
super(props);
this.state = {
status: "initial" // initial | failed | success
}
}
static navigationOptions = ( {navigation} : {navigation : any} ) => ({
drawerLabel: "Pied Piper",
title: "Pied Piper",
headerLeft: (
<View style={{ paddingHorizontal: 10 }}>
<TouchableOpacity onPress={() => navigation.navigate("DrawerOpen")}>
<Icon name="menu" size={30} color="blue" />
</TouchableOpacity>
</View>
)
});
render() {
return (
<View style={ProfileStyle.container}>
<Text>Profile</Text>
</View>
);
}
}
export default Profile;
导出类配置文件扩展组件{
构造器(道具:导航屏幕操作){
超级(道具);
此.state={
状态:“初始”//initial |失败|成功
}
}
静态导航选项=({navigation}:{navigation:any})=>({
抽屉标签:“彩绘风笛手”,
标题:“彩笛手”,
左校长:(
导航。导航(“抽屉”)}>
)
});
render(){
返回(
轮廓
);
}
}
导出默认配置文件;
需要更具体的代码我只有这些使用导航抽屉的文件我使用react、react native和react navigation(1.5.11版)的正确导入语句运行了代码,运行正常,没有任何错误,抽屉项目仅在实际代码中显示一个项目,你有正确的导入语句吗?你用的是JS还是TS?在我的例子中,我使用的是TS,也许在JS中,这段代码工作得很好。