UNPKG

react-navigation-drawer

Version:

Drawer navigator component for React Navigation

2 lines 3.08 kB
import _defineProperty from"@babel/runtime/helpers/defineProperty";function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly)symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;});keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(source,true).forEach(function(key){_defineProperty(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{ownKeys(source).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}}return target;}import{SwitchRouter,NavigationActions}from'react-navigation';import*as DrawerActions from'./DrawerActions';function withDefaultValue(obj,key,defaultValue){if(obj.hasOwnProperty(key)&&typeof obj[key]!=='undefined'){return obj;}obj[key]=defaultValue;return obj;}var getActiveRouteKey=function getActiveRouteKey(route){if(route.routes&&typeof route.index==='number'&&route.routes[route.index]){return getActiveRouteKey(route.routes[route.index]);}return route.key;};export default(function(routeConfigs){var config=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};config=_objectSpread({},config);config=withDefaultValue(config,'resetOnBlur',config.unmountInactiveRoutes?true:!!config.resetOnBlur);config=withDefaultValue(config,'backBehavior','initialRoute');var switchRouter=SwitchRouter(routeConfigs,config);return _objectSpread({},switchRouter,{getActionCreators:function getActionCreators(route,navStateKey){return _objectSpread({openDrawer:function openDrawer(){return DrawerActions.openDrawer({key:navStateKey});},closeDrawer:function closeDrawer(){return DrawerActions.closeDrawer({key:navStateKey});},toggleDrawer:function toggleDrawer(){return DrawerActions.toggleDrawer({key:navStateKey});}},switchRouter.getActionCreators(route,navStateKey));},getStateForAction:function getStateForAction(action,state){if(!state){return _objectSpread({},switchRouter.getStateForAction(action,undefined),{isDrawerOpen:false});}var isRouterTargeted=action.key==null||action.key===state.key;if(isRouterTargeted){if(action.type===DrawerActions.CLOSE_DRAWER||action.type===NavigationActions.BACK&&state.isDrawerOpen){return _objectSpread({},state,{isDrawerOpen:false});}if(action.type===DrawerActions.OPEN_DRAWER){return _objectSpread({},state,{isDrawerOpen:true});}if(action.type===DrawerActions.TOGGLE_DRAWER){return _objectSpread({},state,{isDrawerOpen:!state.isDrawerOpen});}}var switchedState=switchRouter.getStateForAction(action,state);if(switchedState===null){return null;}if(switchedState!==state){if(getActiveRouteKey(switchedState)!==getActiveRouteKey(state)&&state.isDrawerOpen){return _objectSpread({},switchedState,{isDrawerOpen:false});}return switchedState;}return state;}});}); //# sourceMappingURL=DrawerRouter.js.map