App.js
<Store>
<Navbar />
<AppNavigator ref={navigatorRef => {
NavigationService.setTopLevelNavigator(navigatorRef);
}} />
</Store>
我希望能够访问
props.navigation.openDrawer();
从导航栏但我得到
undefined is not an object (evaluating 'props.navigation.openDrawer')
onPress
Navbar.js:70:29
etc..
如何允许导航栏访问抽屉?
我想你正在关注无需导航道具即可导航 https://reactnavigation.org/docs/en/navigating-without-navigation-prop.html(如果你不这样做,那么你应该在你的情况下)。然后在NavigationService.js
添加 openDrawer 方法
// NavigationService.js
import { DrawerActions } from 'react-navigation-drawer';
...
// add this function
function openDrawer(routeName, params) {
_navigator.dispatch(DrawerActions.openDrawer());
}
export default {
...
// and export it
openDrawer
};
然后代替props.navigation.openDrawer()
, use
NavigationService.openDrawer()
不要忘记进行相应的导入
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)