如何在React native中的createStackNavigator中创建createDrawerNavigator?

时间:2019-09-04 02:20:26

标签: react-native navigation-drawer react-navigation drawer react-navigation-drawer

我正在使用react-navigation v3来响应本机应用程序。 当我在createStackNavigator中创建createDrawerNavigator时,无法打开抽屉,但如果在根导航器中创建createDrawerNavigator,则可以打开它。 这是我的代码。有人对我有解决办法吗?

AppNavigator.js

const AppNavigator =  createSwitchNavigator(
  {
    StackNavigatorMain: StackNavigatorMain,
    StackMenu: StackMenu
  },
  {
    headerMode: "null",
    navigationOptions: {
      headerVisible: false
    },
    initialRouteName: "StackNavigatorMain"
  }
);

export default createAppContainer(AppNavigator);

StackNavigatorMain.js

const StackNavigatorMain = createStackNavigator(
    {   
        routeHome: Home,
        routeLogin: Login,
        routeForgotPassword: ForgotPassword,
        routeSignUp: SignUp,
    },
    {
        headerMode: "none",
        initialRouteName: strings.routeHome,

    }
)
export default StackNavigatorMain

StackMenu.js

const StackMenu = createStackNavigator({
  //Drawer Optons and indexing
  MenuNavigator: MenuNavigator,
},
  {
    headerMode: "null",
    navigationOptions: {
      headerVisible: false
    },
  }
);

export default StackMenu;

MenuNavigator.js

const MenuNavigator = createDrawerNavigator({
  //Drawer Optons and indexing
  Setting: Setting
},
  {
    drawerWidth: responsiveWidth(180),
    overlayColor: 'transparent',
    // drawerLockMode: 'locked-open',
    contentComponent: AppSideMenu
  }
);

export default MenuNavigator;

index.js

export default class App extends Component {
  render() {
    return (
      <AppNavigator/>
    );
  };
}

在“组件”屏幕中的“按按钮”上调用打开的抽屉

onClicked = () => {
        // props.navigation.openDrawer();
        props.navigation.dispatch(DrawerActions.openDrawer());
}

0 个答案:

没有答案