react-native 中的抽屉导航错误:undefined 不是一个对象(评估'_this.props.navigation.openDrawer()')

error with a drawer navigation in react-native :undefined is not an object (evaluating '_this.props.navigation.openDrawer()')

我已经设置了一个完美运行的导航器抽屉,但是从今天早上开始我就遇到了这个错误。我不知道它是从哪里来的。因为我没有对抽屉做任何改动。 我无法使用关闭抽屉的功能。


   <Left style={{flex :1, flexDirection: 'row'}}>
       <Icon 
              onPress={() => this.props.navigation.openDrawer()} name="menu"
              tyle={{color: 'black', marginRight: 15,}} />
   </Left>

错误是:

undefined is not an object (evaluating '_this.props.navigation.openDrawer()')

你可以试试这个

import { DrawerActions } from 'react-navigation';

this.props.navigation.dispatch(DrawerActions.closeDrawer());
this.props.navigation.dispatch(DrawerActions.openDrawer());