小编Vin*_*elo的帖子

使用toggleDrawer导航时出错。ToggleDrawer不是函数

我目前在我的应用程序上使用堆栈导航,但我决定为用户菜单增加一个抽屉。

\n

我设法在我的页面中插入Drawer,但其中一些是MapView内容,因此用户无法真正从屏幕上拖动菜单...\n所以我决定实现一个按钮来调用ToggleDrawer函数,这是在文档中介绍的。但我收到错误:

\n
\n

类型错误:navigation.ToggleDrawer 不是函数。(在\'navigation.ToggleDrawer()\'中,\'navigation.ToggleDrawer\'未定义)

\n
\n

这是我的地图屏幕,我尝试在其中插入按钮,如下所示:

\n
onPress={() => navigation.ToggleDrawer()}\n
Run Code Online (Sandbox Code Playgroud)\n

如果我从 useNavitation() 中删除,<any>我会收到以下信息:\nProperty \'ToggleDrawer\' does not exist on type \'NavigationProp

\n
export default function IncidentsMap() {\n    const navigation = useNavigation<any>();\n\n\n    return (\n\n        <View style={styles.container}>\n\n            {typeof location?.coords.latitude == \'number\' ?\n                <View style={styles.container}>\n                    <MapView\n                        provider={PROVIDER_GOOGLE}\n                        style={styles.map}\n                        >\n\n                            <Callout tooltip={true} onPress={handleNavigateToIncidentDetails}>\n                                <View style={styles.calloutContainer}>\n                                    <Text style={styles.calloutText}>Enchente rasa</Text>\n                                </View>\n                            </Callout>\n                        </Marker>\n                    </MapView>\n                    <View style={styles.footer}>\n                        <Text style={styles.footerText}>Reporte um incidente</Text>\n                        <RectButton style={styles.createFloodButton} onPress={handleNavigateToCreateIncident}>\n                            <Feather name=\'plus\' size={20} color={\'#fff\'}/>\n …
Run Code Online (Sandbox Code Playgroud)

typescript navigation-drawer react-native react-typescript

5
推荐指数
1
解决办法
6134
查看次数