【发布时间】:2021-11-26 10:09:03
【问题描述】:
我正在尝试从 DrawerNavigation 的标头调用 openDrawer 选项,但导航道具不包含 openDrawer 函数。
import React from 'react';
import {View, TouchableOpacity} from 'react-native';
import {createDrawerNavigator} from '@react-navigation/drawer';
import Icon from 'react-native-vector-icons/Ionicons';
import {dimensions} from '../../constants/utils';
import CustomDrawerContent from './components/CustomDrawerContent';
const Drawer = createDrawerNavigator();
const DrawerNavigator = () => {
screenOptionsProps = {
screenOptions: {
headerLeft: props => (
<View>
<TouchableOpacity onPress={() => navigation.openDrawer()}>
<Icon
name="reorder-three-sharp"
size={dimensions.width * 0.08}
{...props}
/>
</TouchableOpacity>
</View>
),
},
};
return (
<Drawer.Navigator
{...screenOptionsProps}
drawerContent={props => <CustomDrawerContent {...props} />}>
<Drawer.Screen name="Dashboard" component={Dashboard} />
</Drawer.Navigator>
);
};
export default DrawerNavigator;
当图标被点击时,抽屉应该被打开,但导航道具没有收到任何东西,并且在安慰导航道具未定义为值时。 DrawerContent 中传入的 props 里面有 openDrawer() 方法,但是如何在 screenOptions 中使用它。
【问题讨论】:
-
我认为你的仪表板组件应该有这个汉堡包图标,用于打开或关闭抽屉。
标签: react-native react-navigation-v6