无法从自定义标题切换堆栈导航器中的抽屉

Esi*_*siS 2 react-native react-navigation

我有StackNavigator一个带有自定义标头的组件DrawerNavigator。自定义标题有一个按钮,应在按下时切换抽屉。我已经添加了 React Navigation 文档中提供的操作,但不起作用。

可以在这里找到有问题的小吃

我究竟做错了什么?谢谢你。

igo*_*ves 5

您可以导入: import { DrawerActions } from 'react-navigation';

然后在Header 中使用它:

const Header = (props) => {
 return (
    <View style={{marginTop: 25}}>
      <Button
        onPress={() => props.navigation.dispatch(DrawerActions.toggleDrawer())}
        title="Toggle"
        color="#841584" />
    </View>)
}
Run Code Online (Sandbox Code Playgroud)