如何打开抽屉在按下从堆栈.屏幕在反应本机



我正试图从homeScreen打开抽屉。当我向右滑动时抽屉打开了。我想打开菜单图标的Draer onPress。但它不起作用。我用了openDrawer,toggleDrawer,但什么都不管用。

这是我的代码


function MyDrawer() {
return (
<Drawer.Navigator initialRouteName="homeScreen">
<Drawer.Screen name="homeSreen" component={homeScreen} 

options={{
headerLeft: () => <Icon
name="menu"
size={25}
color="#D4AF37"
onPress={() => navigation.toggleDrawer()}
/>
}} 
/>
</Drawer.Navigator>
);
}
function App({ navigation }) {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="splashScreen" component={splashScreen} options={{headerShown: false}} />
<Stack.Screen name="loginScreen" component={loginScreen}  options={{headerShown: false}} />
<Stack.Screen name="homeScreen" component={MyDrawer}  />
</Stack.Navigator>
</NavigationContainer>
);
}
export default App;

在react navigation V5 中

navigation.dispatch(DrawerActions.openDrawer());
navigation.dispatch(DrawerActions.closeDrawer());
navigation.dispatch(DrawerActions.toggleDrawer());

尝试在函数MyDrawer((中添加导航

像这个function MyDrawer({navigation}) {...}

您可以使用this.props.navigation.openDrawer()打开抽屉

<TouchableOpacity
onPress={() => {
this.props.navigation.openDrawer();
}}>
<Icon name="bars" size={21} color="rgb(112, 112, 112)" />
</TouchableOpacity>

相关内容

  • 没有找到相关文章

最新更新