Fixes default drawerWidth to match Material UI patterns. (#2773)

* Fixes default drawerWidth to match material ui patterns.

Previously: calculated based on device width regardless of orientation and did not recalculate when orientation changed.
Now: calculates based on minimum of device height/width, remains constant and guaranteed to always fit screen regardless of orientation.

This is the expected behavior based on observing Google apps (e.g. Gmail). This is also better than recalculating on every orientation change, which would result in variable width drawers and awkward empty space when in landscape in most cases.

* Remove console.log
This commit is contained in:
Dave Pack
2017-10-17 16:24:56 -07:00
parent 1bf98c1ddc
commit 94fe9fcc72
2 changed files with 6 additions and 2 deletions

View File

@@ -1,6 +1,9 @@
/* @flow */
import React from 'react';
import { ScreenOrientation } from 'expo';
ScreenOrientation.allow(ScreenOrientation.Orientation.ALL);
import {
Platform,

View File

@@ -23,13 +23,14 @@ export type DrawerNavigatorConfig = {
} & NavigationTabRouterConfig &
DrawerViewConfig;
const { height, width } = Dimensions.get('window');
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),
drawerWidth: Math.min(height, width) - (Platform.OS === 'android' ? 56 : 64),
contentComponent: DrawerItems,
drawerPosition: 'left',
drawerBackgroundColor: 'white',