Android 对新闻问题做出反应
我试图通过在页眉的汉堡上包含onPress()来导航抽屉,但它与navigation.toggleDrawer()函数不兼容 代码如下:Android 对新闻问题做出反应,android,reactjs,react-native,navigation,Android,Reactjs,React Native,Navigation,我试图通过在页眉的汉堡上包含onPress()来导航抽屉,但它与navigation.toggleDrawer()函数不兼容 代码如下: import * as React from 'react'; import { Button, View } from 'react-native'; import { createDrawerNavigator } from '@react-navigation/drawer'; import { NavigationContainer } from '@
import * as React from 'react';
import { Button, View } from 'react-native';
import { createDrawerNavigator } from '@react-navigation/drawer';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { Ionicons } from '@expo/vector-icons';
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.navigate('Home')} title="Go back home" />
</View>
);
}
const Drawer = createDrawerNavigator();
function draw() {
return (
<Drawer.Navigator initialRouteName="Home" >
<Drawer.Screen name="Home" component={HomeScreen}
options={{
drawerIcon: () => <Ionicons name='md-home' size={30} color='#130f40' />,
}}
/>
<Drawer.Screen name="Notifications" component={NotificationsScreen}
options={{
drawerIcon: () => <Ionicons name='md-notifications' size={30} color='#130f40' />,
}}
/>
</Drawer.Navigator>
);
}
const Stack = createStackNavigator();
function Def(){
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Home"
component={draw}
options={{
title: 'My home',
headerStyle: {
backgroundColor: '#5f27cd',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
headerLeft: () => (<Ionicons name='md-menu' style={{paddingLeft: "20px"}} size={30} color='white' onPress={() => navigation.toggleDrawer()} />),
}}
/>
</Stack.Navigator>
</NavigationContainer>
)
}
export default Def;
import*as React from'React';
从“react native”导入{按钮,视图};
从'@react导航/drawer'导入{createDrawerNavigator};
从'@react-navigation/native'导入{NavigationContainer};
从'@react navigation/stack'导入{createStackNavigator};
从“@expo/vector icons”导入{Ionicons};
功能主屏幕({navigation}){
返回(
navigation.navigate('Notifications')}
title=“转到通知”
/>
);
}
函数通知屏幕({navigation}){
返回(
navigation.navigate('Home')}title=“回家”/>
);
}
const Drawer=createDrawerNavigator();
函数绘图(){
返回(
,
}}
/>
,
}}
/>
);
}
const Stack=createStackNavigator();
函数Def(){
返回(
(navigation.toggleDrawer()}/>),
}}
/>
)
}
导出默认Def;
我在Ionicons中添加了navigation.toggleDrawer()函数和onPress()函数,但它不起作用。错误表示未定义导航 试试这个
headerLeft: ({navigation}) => (<Ionicons name='md-menu' style={{paddingLeft: "20px"}} size={30} color='white' onPress={() => navigation.toggleDrawer()} />)
headerLeft:({navigation})=>(navigation.toggleDrawer()}/>)
希望有帮助是打字错误吗
toggleDrawer
和toggleDrawer
的拼写不同。编辑以更正抽屉导航文档中的toggleDrawer键入错误,它是导航。toggleDrawer();它不工作:(它现在给出以下错误[