我使用以下代码使用抽屉导航和底部标签:
<NavigationContainer>
<Drawer.Navigator>
<Drawer.Screen name="Root" component={this.Root} />
<Drawer.Screen name="HomeScreen" component={HomeScreen} />
</Drawer.Navigator>
</NavigationContainer>
root 代码
Root() {
return (
<Stack
screenProps={{
updateTheme: 'light'
}}
theme={'light'}
/>
);
}
现在,当我尝试使用带有 onPress={() => this.props.navigation.toggleDrawer()}
的按钮打开抽屉时,它会抛出一个错误,指出这个道具导航不是一个功能,但是如果我从代码中删除屏幕根,它会在底部导航时完美运行消失了,因为 root 有堆栈。我怎样才能克服这个问题?我正在使用 React Native 5 导航。