两侧都有React-Native DrawerNavigator菜单

时间:2018-02-12 20:11:47

标签: javascript reactjs react-native react-navigation react-native-ios

我有一个带有DrawerNavigator的本机应用程序。对于菜单,我有自己的组件。这很好用。 现在我想在右侧添加第二个侧面菜单。 可以在Slack App中使用两个DrawerNavigator吗? 此解决方案对我不起作用:https://snack.expo.io/ry7lYempe 因为我不希望TabController作为父级。两个抽屉都应该可以在所有屏幕上访问。

我的代码如下所示:

import React from 'react'
import reducer from './src/reducers'
import { DrawerNavigator } from 'react-navigation';
import SidebarMenu from './src/components/layout/SidebarMenu'

import { createStore } from 'redux';
import { Provider } from 'react-redux';

let store = createStore(reducer);

import News from './src/screens/News'
import HowTo from './src/screens/HowTo'


export default class MyApp extends React.Component {

    render() {

        return (
            <Provider store={store}>
                <MainNavigator />
            </Provider>
        );
    }
}

const MainNavigator = DrawerNavigator(
    {
        News: {
            path: '/news',
            screen: News
        },
        HowTo: {
            path: '/howto',
            screen: HowTo
        }
    },
    {
        initialRouteName: 'News',
        drawerPosition: 'left',
        contentComponent: SidebarMenu
    }
);

更新反应导航到最新版本后解决。

2 个答案:

答案 0 :(得分:2)

您可以添加所需的任何抽屉,请查看此示例https://snack.expo.io/BJoChzewM

在您的情况下,您可以添加&#34; MainNavigator&#34;在另一个DrawerNavigator组件中。不要忘记设置drawerOpenRoute / drawerCloseRoute以防止任何副作用。

答案 1 :(得分:0)

@KamleshKatpara这是我的解决方案(我嵌套了两个导航器):

const DrawerExample = DrawerNavigator(
    {
        Home: {
            path: '/',
            screen: Home
        }
    },
    {
        initialRouteName: 'Home',
        drawerPosition: 'left',
        contentComponent: SidebarMenu
    }
);

const MainDrawerExample = DrawerNavigator({
    Drafts: {
        screen: DrawerExample,
    }
}, {
    drawerPosition: 'right',
    contentComponent: BookmarkMenu,
    drawerOpenRoute: 'DrawerRightOpen',
    drawerCloseRoute: 'DrawerRightClose',
    drawerToggleRoute: 'DrawerRightToggle'
});