Dave Pack 3e37ee6d0c 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
2017-10-17 18:24:56 -05:00

163 lines
3.9 KiB
JavaScript

/* @flow */
import React from 'react';
import { ScreenOrientation } from 'expo';
ScreenOrientation.allow(ScreenOrientation.Orientation.ALL);
import {
Platform,
ScrollView,
StyleSheet,
TouchableOpacity,
Text,
View,
} from 'react-native';
import { StackNavigator } from 'react-navigation';
import Banner from './Banner';
import CustomTabs from './CustomTabs';
import CustomTransitioner from './CustomTransitioner';
import Drawer from './Drawer';
import TabsInDrawer from './TabsInDrawer';
import ModalStack from './ModalStack';
import StacksInTabs from './StacksInTabs';
import StacksOverTabs from './StacksOverTabs';
import SimpleStack from './SimpleStack';
import SimpleTabs from './SimpleTabs';
const ExampleRoutes = {
SimpleStack: {
name: 'Stack Example',
description: 'A card stack',
screen: SimpleStack,
},
SimpleTabs: {
name: 'Tabs Example',
description: 'Tabs following platform conventions',
screen: SimpleTabs,
},
Drawer: {
name: 'Drawer Example',
description: 'Android-style drawer navigation',
screen: Drawer,
},
TabsInDrawer: {
name: 'Drawer + Tabs Example',
description: 'A drawer combined with tabs',
screen: TabsInDrawer,
},
CustomTabs: {
name: 'Custom Tabs',
description: 'Custom tabs with tab router',
screen: CustomTabs,
},
CustomTransitioner: {
name: 'Custom Transitioner',
description: 'Custom transitioner with stack router',
screen: CustomTransitioner,
},
ModalStack: {
name: Platform.OS === 'ios'
? 'Modal Stack Example'
: 'Stack with Dynamic Header',
description: Platform.OS === 'ios'
? 'Stack navigation with modals'
: 'Dynamically showing and hiding the header',
screen: ModalStack,
},
StacksInTabs: {
name: 'Stacks in Tabs',
description: 'Nested stack navigation in tabs',
screen: StacksInTabs,
},
StacksOverTabs: {
name: 'Stacks over Tabs',
description: 'Nested stack navigation that pushes on top of tabs',
screen: StacksOverTabs,
},
LinkStack: {
name: 'Link in Stack',
description: 'Deep linking into a route in stack',
screen: SimpleStack,
path: 'people/Jordan',
},
LinkTabs: {
name: 'Link to Settings Tab',
description: 'Deep linking into a route in tab',
screen: SimpleTabs,
path: 'settings',
},
};
const MainScreen = ({ navigation }) => (
<ScrollView>
<Banner />
{Object.keys(ExampleRoutes).map((routeName: string) => (
<TouchableOpacity
key={routeName}
onPress={() => {
const { path, params, screen } = ExampleRoutes[routeName];
const { router } = screen;
const action = path && router.getActionForPathAndParams(path, params);
navigation.navigate(routeName, {}, action);
}}
>
<View style={styles.item}>
<Text style={styles.title}>{ExampleRoutes[routeName].name}</Text>
<Text style={styles.description}>
{ExampleRoutes[routeName].description}
</Text>
</View>
</TouchableOpacity>
))}
</ScrollView>
);
const AppNavigator = StackNavigator(
{
...ExampleRoutes,
Index: {
screen: MainScreen,
},
},
{
initialRouteName: 'Index',
headerMode: 'none',
/*
* Use modal on iOS because the card mode comes from the right,
* which conflicts with the drawer example gesture
*/
mode: Platform.OS === 'ios' ? 'modal' : 'card',
}
);
export default () => <AppNavigator />;
const styles = StyleSheet.create({
item: {
backgroundColor: '#fff',
paddingHorizontal: 16,
paddingVertical: 12,
borderBottomWidth: StyleSheet.hairlineWidth,
borderBottomColor: '#ddd',
},
image: {
width: 120,
height: 120,
alignSelf: 'center',
marginBottom: 20,
resizeMode: 'contain',
},
title: {
fontSize: 16,
fontWeight: 'bold',
color: '#444',
},
description: {
fontSize: 13,
color: '#999',
},
});