无法从堆栈标头React Native v5打开抽屉

时间:2020-08-17 11:23:17

标签: react-native navigation-drawer

我正在尝试从标题中打开抽屉,但是我无法弄清楚,下面是我的代码:

import { NavigationContainer,useNavigation,DrawerActions } from '@react-navigation/native';
.
.
.
render({ 
return (
      <Root>
      <NavigationContainer ref={navigationRef}>

        <Stack.Navigator >
          <Stack.Screen name="Mediclic" component={AppDraw}
            options={
              headerLeft: () =>
                <TouchableOpacity style={{ marginLeft: 5 }} onPress={() => navigation.openDrawer() }>
                  <MaterialIcons name='menu' size={28} color={'white'} />
                </TouchableOpacity>,
            }
            } />
</Stack.Navigator>
      </NavigationContainer>
 );
  }
}
const AppDraw = () =>

  <Drawer.Navigator>
    <Drawer.Screen name="Accueil" component={AccueilScreen} />
    <Drawer.Screen name="A propos" component={AboutScreen} />
  </Drawer.Navigator>

您可以看到堆栈导航器和抽屉在同一个文件中,但仍然无法使它正常工作 就我而言,我得到TypoErro:undefined不是一个对象(navigation.opendrawer)

我也尝试了调度,但没有成功。

有人可以帮我吗,我已经为此努力了一个多星期! 谢谢

2 个答案:

答案 0 :(得分:0)

在要打开抽屉的屏幕上使抽屉成为子屏幕 假设我要在AccueilScreen中打开抽屉。

我在您的代码中做什么

使用

children = {this.AppDraw}而不是component = {AppDraw} 并写

JpaTokenStore.Builder#claimTimeout(TemporalAmount)

代替

claimTimeout

尝试这个,希望对您有帮助

<Stack.Screen name="Accueil" children={this.AppDraw}

答案 1 :(得分:0)

我仅使用以下方法解决了该问题:

onPress={() =>  
navigation.dispatch(DrawerActions.toggleDrawer()) }

如果有人使用抽屉式导航V5,我建议您使用它!