Skip to content

Instantly share code, notes, and snippets.

@ronal2do
Created March 15, 2017 22:25
Show Gist options
  • Save ronal2do/988f9334d81e0aa905f1d5bc2b3bf34f to your computer and use it in GitHub Desktop.
Save ronal2do/988f9334d81e0aa905f1d5bc2b3bf34f to your computer and use it in GitHub Desktop.
A CustomDrawerNavigator for reactnavigation.
import React from 'react';
import {
Dimensions,
Platform,
Text,
} from 'react-native';
// Modified the imports to rely on public api from react-navigation
import { createNavigationContainer, createNavigator, TabRouter } from 'react-navigation';
// Modified the imports to rely on private api from react-navigation
import DrawerScreen from 'react-navigation/src/views/Drawer/DrawerScreen';
import DrawerView from 'react-navigation/src/views/Drawer/DrawerView';
import Globals from '../utils/Globals';
const DefaultDrawerConfig = {
/*
* Default drawer width is screen width - header width
* https://material.io/guidelines/patterns/navigation-drawer.html
*/
drawerWidth: Dimensions.get('window').width - (Platform.OS === 'android' ? 56 : 64),
contentComponent: DrawerView.Items,
// contentComponent: (<Text>Olá amigos</Text>),
// drawerPosition: 'left',
contentOptions: {
activeTintColor: Globals.app.color,
style: {
// marginTop: 150,
}
}
};
const CustomDrawerNavigator = (
routeConfigs,
config,
) => {
const mergedConfig = { ...DefaultDrawerConfig, ...config };
const {
containerConfig,
drawerWidth,
contentComponent,
contentOptions,
drawerPosition,
...tabsConfig
} = mergedConfig;
const contentRouter = TabRouter(routeConfigs, tabsConfig);
const drawerRouter = TabRouter({
DrawerClose: {
screen: createNavigator(contentRouter)((props) =>
<DrawerScreen {...props} />
),
},
DrawerOpen: {
screen: () => null,
},
}, {
initialRouteName: 'DrawerClose',
});
return createNavigationContainer(createNavigator(drawerRouter)((props) =>
<DrawerView
{...props}
style={{
backgroundColor: Globals.app.backgroundColorLight,
}}
drawerWidth={drawerWidth}
contentComponent={contentComponent}
contentOptions={contentOptions}
drawerPosition={drawerPosition}
/>
), containerConfig);
};
export default CustomDrawerNavigator;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment