在Stack-Navigator屏幕中打开React-Native抽屉菜单

时间:2018-12-22 09:33:19

标签: reactjs react-native navigation-drawer stack-navigator

在我的应用程序中,我有3个堆栈 StackOne

export const StackOne = createStackNavigator({
  OneScreen: { screen:one  },
  TwoScreen: { screen:two  },
  ThreeScreen: { screen:three  },
}, { initialRouteName: 'OneScreen', }
);

StackTwo

export const StackTwo = createStackNavigator({
  OneScreenTwo: { screen:oneTwo  },
  TwoScreenTwo: { screen:twoTwo  },
  ThreeScreenTwo: { screen:threeTwo  },
}, { initialRouteName: 'OneScreenTwo', }
);

我这样使用抽屉式导航。 MainDrawer

const MainDrawer = createDrawerNavigator(
  {
    One: { screen: StackOne },
    Two: { screen: StackTwo },
    Other: { screen: OtherScreen},
  },
  {}
);

一切正常。管理抽屉-堆叠得很好 唯一的问题是当我在StackOne's ScreenTwo左右滑动时仍打开抽屉菜单。 不仅每个屏幕上的该屏幕都打开抽屉菜单。

我尝试了几个链接,但找不到成功。 希望有人帮忙。 我点击此链接Navigation

谢谢

2 个答案:

答案 0 :(得分:4)

您需要在StackNavigator上指定navigationOptions而不是TwoScreen等,否则将配置StackNavigator而不是DrawerNavigator:

StackOne.navigationOptions = ({ navigation }) => ({
  drawerLockMode: navigation.state.index === 0 ? 'unlocked' : 'locked-closed',
}); 

工作示例:https://snack.expo.io/@riwu/stack-nav-lock-drawer

答案 1 :(得分:0)

export const StackOne = createStackNavigator({
  OneScreen: { screen:one  },
  TwoScreen: { screen:two  },
  ThreeScreen: { screen:three  },
}, { initialRouteName: 'OneScreen', }
);


StackOne.navigationOptions = ({ navigation }) => {
  let drawerLockMode = 'unlocked';
  if (navigation.state.routes[navigation.state.index] != 'OneScreen') {
    drawerLockMode = 'locked-closed';
  }
  return {
    drawerLockMode,
  };
};


export const StackTwo = createStackNavigator({
  OneScreenTwo: { screen:oneTwo  },
  TwoScreenTwo: { screen:twoTwo  },
  ThreeScreenTwo: { screen:threeTwo  },
}, { initialRouteName: 'OneScreenTwo', }
);

StackTwo .navigationOptions = ({ navigation }) => {
  let drawerLockMode = 'unlocked';
  if (navigation.state.routes[navigation.state.index] != 'OneScreenTwo') {
    drawerLockMode = 'locked-closed';
  }
  return {
    drawerLockMode,
  };
};

创建导航选项并解决问题。