Remove NavigatorTypes (#3331)

This commit is contained in:
Brent Vatne 2018-01-26 15:54:46 -08:00 committed by GitHub
parent 9e026ec2c8
commit 4ae2a42a4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 77 deletions

View File

@ -9,8 +9,6 @@ import DrawerView from '../views/Drawer/DrawerView';
import DrawerItems from '../views/Drawer/DrawerNavigatorItems'; import DrawerItems from '../views/Drawer/DrawerNavigatorItems';
import SafeAreaView from '../views/SafeAreaView'; import SafeAreaView from '../views/SafeAreaView';
import NavigatorTypes from './NavigatorTypes';
// A stack navigators props are the intersection between // A stack navigators props are the intersection between
// the base navigator props (navgiation, screenProps, etc) // the base navigator props (navgiation, screenProps, etc)
// and the view's props // and the view's props
@ -66,16 +64,12 @@ const DrawerNavigator = (routeConfigs, config = {}) => {
} = mergedConfig; } = mergedConfig;
const contentRouter = TabRouter(routeConfigs, tabsConfig); const contentRouter = TabRouter(routeConfigs, tabsConfig);
const drawerRouter = TabRouter( const drawerRouter = TabRouter(
{ {
[drawerCloseRoute]: { [drawerCloseRoute]: {
screen: createNavigator( screen: createNavigator(contentRouter, routeConfigs, config)(props => (
contentRouter, <DrawerScreen {...props} />
routeConfigs, )),
config,
NavigatorTypes.DRAWER
)(props => <DrawerScreen {...props} />),
}, },
[drawerOpenRoute]: { [drawerOpenRoute]: {
screen: () => null, screen: () => null,
@ -89,26 +83,23 @@ const DrawerNavigator = (routeConfigs, config = {}) => {
} }
); );
const navigator = createNavigator( const navigator = createNavigator(drawerRouter, routeConfigs, config)(
drawerRouter, props => (
routeConfigs, <DrawerView
config, {...props}
NavigatorTypes.DRAWER drawerBackgroundColor={drawerBackgroundColor}
)(props => ( drawerLockMode={drawerLockMode}
<DrawerView useNativeAnimations={useNativeAnimations}
{...props} drawerWidth={drawerWidth}
drawerBackgroundColor={drawerBackgroundColor} contentComponent={contentComponent}
drawerLockMode={drawerLockMode} contentOptions={contentOptions}
useNativeAnimations={useNativeAnimations} drawerPosition={drawerPosition}
drawerWidth={drawerWidth} drawerOpenRoute={drawerOpenRoute}
contentComponent={contentComponent} drawerCloseRoute={drawerCloseRoute}
contentOptions={contentOptions} drawerToggleRoute={drawerToggleRoute}
drawerPosition={drawerPosition} />
drawerOpenRoute={drawerOpenRoute} )
drawerCloseRoute={drawerCloseRoute} );
drawerToggleRoute={drawerToggleRoute}
/>
));
return createNavigationContainer(navigator); return createNavigationContainer(navigator);
}; };

View File

@ -1,9 +0,0 @@
const STACK = 'react-navigation/STACK';
const TABS = 'react-navigation/TABS';
const DRAWER = 'react-navigation/DRAWER';
export default {
STACK,
TABS,
DRAWER,
};

View File

@ -3,7 +3,6 @@ import createNavigationContainer from '../createNavigationContainer';
import createNavigator from './createNavigator'; import createNavigator from './createNavigator';
import CardStackTransitioner from '../views/CardStack/CardStackTransitioner'; import CardStackTransitioner from '../views/CardStack/CardStackTransitioner';
import StackRouter from '../routers/StackRouter'; import StackRouter from '../routers/StackRouter';
import NavigatorTypes from './NavigatorTypes';
import NavigationActions from '../NavigationActions'; import NavigationActions from '../NavigationActions';
// A stack navigators props are the intersection between // A stack navigators props are the intersection between
@ -34,26 +33,23 @@ export default (routeConfigMap, stackConfig = {}) => {
const router = StackRouter(routeConfigMap, stackRouterConfig); const router = StackRouter(routeConfigMap, stackRouterConfig);
// Create a navigator with CardStackTransitioner as the view // Create a navigator with CardStackTransitioner as the view
const navigator = createNavigator( const navigator = createNavigator(router, routeConfigMap, stackConfig)(
router, props => (
routeConfigMap, <CardStackTransitioner
stackConfig, {...props}
NavigatorTypes.STACK headerMode={headerMode}
)(props => ( mode={mode}
<CardStackTransitioner cardStyle={cardStyle}
{...props} transitionConfig={transitionConfig}
headerMode={headerMode} onTransitionStart={onTransitionStart}
mode={mode} onTransitionEnd={(lastTransition, transition) => {
cardStyle={cardStyle} const { state, dispatch } = props.navigation;
transitionConfig={transitionConfig} dispatch(NavigationActions.completeTransition());
onTransitionStart={onTransitionStart} onTransitionEnd && onTransitionEnd();
onTransitionEnd={(lastTransition, transition) => { }}
const { state, dispatch } = props.navigation; />
dispatch(NavigationActions.completeTransition()); )
onTransitionEnd && onTransitionEnd(); );
}}
/>
));
return createNavigationContainer(navigator); return createNavigationContainer(navigator);
}; };

View File

@ -8,8 +8,6 @@ import TabView from '../views/TabView/TabView';
import TabBarTop from '../views/TabView/TabBarTop'; import TabBarTop from '../views/TabView/TabBarTop';
import TabBarBottom from '../views/TabView/TabBarBottom'; import TabBarBottom from '../views/TabView/TabBarBottom';
import NavigatorTypes from './NavigatorTypes';
// A tab navigators props are the intersection between // A tab navigators props are the intersection between
// the base navigator props (navgiation, screenProps, etc) // the base navigator props (navgiation, screenProps, etc)
// and the view's props // and the view's props
@ -30,12 +28,7 @@ const TabNavigator = (routeConfigs, config = {}) => {
const router = TabRouter(routeConfigs, tabsConfig); const router = TabRouter(routeConfigs, tabsConfig);
const navigator = createNavigator( const navigator = createNavigator(router, routeConfigs, config)(props => (
router,
routeConfigs,
config,
NavigatorTypes.TABS
)(props => (
<TabView <TabView
{...props} {...props}
tabBarComponent={tabBarComponent} tabBarComponent={tabBarComponent}

View File

@ -3,19 +3,10 @@ import React from 'react';
/** /**
* Creates a navigator based on a router and a view that renders the screens. * Creates a navigator based on a router and a view that renders the screens.
*/ */
export default function createNavigator( export default function createNavigator(router, routeConfigs, navigatorConfig) {
router,
routeConfigs,
navigatorConfig,
navigatorType
) {
return NavigationView => { return NavigationView => {
class Navigator extends React.Component { class Navigator extends React.Component {
static router = router; static router = router;
static routeConfigs = routeConfigs;
static navigatorConfig = navigatorConfig;
static navigatorType = navigatorType;
static navigationOptions = null; static navigationOptions = null;
render() { render() {