首页 > 解决方案 > 如何使用 MyDrawer 功能?

问题描述

[我的抽屉功能不起作用,所以我尝试添加 onPress={() => navigation.openDrawer() 功能以查看它是否有效,但似乎功能“openDrwaer”不存在,即使它在文档中@react-navigation/drawer][1]

import {useNavigation} from '@react-navigation/native';
import React from 'react';
import Icon from 'react-native-vector-icons/Feather';
import {Button, Container} from './styles';
import {createDrawerNavigator} from '@react-navigation/drawer';
import SignIn from '../../pages/SignIn';

const Drawer = createDrawerNavigator();

function MyDrawer() {
  return (
    <Drawer.Navigator>
      <Drawer.Screen name="log-out" component={SignIn} />
    </Drawer.Navigator>
  );
}

const Header: React.FC = () => {
  const navigation = useNavigation();
  return (
    <Container>
      <MyDrawer />
      <Button onPress={navigation.goBack}>
        <Icon name="arrow-left" size={30} />
      </Button>
      <Button onPress={() => navigation.openDrawer()} >
        <Icon name="menu" size={30} />
      </Button>
    </Container>
  );
};

export default Header;

标签: androidtypescriptreact-nativemobiledrawer

解决方案


推荐阅读