如何仅在特定屏幕(例如主屏幕)上启用抽屉导航[反应本机] [反应导航]

Cod*_*Joe 3 react-native react-navigation react-navigation-drawer react-navigation-stack react-navigation-v5

此问题的用例是让抽屉菜单(如“设置”)仅在“主屏幕”中可用。在“主屏幕”上可能有许多按钮链接到堆栈导航的其他屏幕,其中抽屉不可用。

主要问题是如何仅在 Stack Navigator 的特定屏幕上启用抽屉导航?在下面的示例中,抽屉在堆栈的所有页面上都可用。我尝试过gestureEnabled但没有成功:

  const StackHome = () => (
    <Stack.Navigator>
      <Stack.Screen name="Home" component={Home} />
      <Stack.Screen name="Example1" component={Example1} />
      <Stack.Screen name="Example2" component={Example2} />
    </Stack.Navigator>
  );
  <Drawer.Navigator initialRouteName="Home">
      <Drawer.Screen name="Home" component={StackHome} />
      <Drawer.Screen name="Settings" component={Settings} />
  </Drawer.Navigator>
Run Code Online (Sandbox Code Playgroud)

另一方面,如果我尝试将其作为屏幕Drawer之一Stack,那么我总是有相同的标题栏(例如“标题”)

sat*_*164 6

将抽屉式导航器放在主屏幕内:

const DrawerHome = () => (
  <Drawer.Navigator screenOptions={{ headerShown: true }}>
    <Drawer.Screen name="Home" component={Home} />
    <Drawer.Screen name="Settings" component={Settings} />
  </Drawer.Navigator>
);

const StackHome = () => (
  <Stack.Navigator>
    <Stack.Screen
      name="DrawerHome"
      component={DrawerHome}
      options={{ headerShown: false }}
    />
    <Stack.Screen name="Example1" component={Example1} />
    <Stack.Screen name="Example2" component={Example2} />
  </Stack.Navigator>
);
Run Code Online (Sandbox Code Playgroud)