react-navigation-drawer
Version:
Drawer navigator component for React Navigation
2 lines • 3.35 kB
JavaScript
import _extends from"@babel/runtime/helpers/extends";import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";import _possibleConstructorReturn from"@babel/runtime/helpers/possibleConstructorReturn";import _getPrototypeOf from"@babel/runtime/helpers/getPrototypeOf";import _inherits from"@babel/runtime/helpers/inherits";var _jsxFileName="/Users/satya/Workspace/Callstack/drawer/src/views/DrawerSidebar.tsx";import*as React from'react';import{StyleSheet,View}from'react-native';import{NavigationActions}from'react-navigation';var DrawerSidebar=function(_React$PureComponent){_inherits(DrawerSidebar,_React$PureComponent);function DrawerSidebar(){var _getPrototypeOf2;var _this;_classCallCheck(this,DrawerSidebar);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this=_possibleConstructorReturn(this,(_getPrototypeOf2=_getPrototypeOf(DrawerSidebar)).call.apply(_getPrototypeOf2,[this].concat(args)));_this.getScreenOptions=function(routeKey){var descriptor=_this.props.descriptors[routeKey];if(!descriptor.options){throw new Error('Cannot access screen descriptor options from drawer sidebar');}return descriptor.options;};_this.getLabel=function(_ref){var focused=_ref.focused,tintColor=_ref.tintColor,route=_ref.route;var _this$getScreenOption=_this.getScreenOptions(route.key),drawerLabel=_this$getScreenOption.drawerLabel,title=_this$getScreenOption.title;if(drawerLabel){return typeof drawerLabel==='function'?drawerLabel({tintColor:tintColor,focused:focused}):drawerLabel;}if(typeof title==='string'){return title;}return route.routeName;};_this.renderIcon=function(_ref2){var focused=_ref2.focused,tintColor=_ref2.tintColor,route=_ref2.route;var _this$getScreenOption2=_this.getScreenOptions(route.key),drawerIcon=_this$getScreenOption2.drawerIcon;if(drawerIcon){return typeof drawerIcon==='function'?drawerIcon({tintColor:tintColor,focused:focused}):drawerIcon;}return null;};_this.handleItemPress=function(_ref3){var route=_ref3.route,focused=_ref3.focused;if(focused){_this.props.navigation.closeDrawer();}else{_this.props.navigation.dispatch(NavigationActions.navigate({routeName:route.routeName}));}};return _this;}_createClass(DrawerSidebar,[{key:"render",value:function render(){var ContentComponent=this.props.contentComponent;if(!ContentComponent){return null;}var state=this.props.navigation.state;if(typeof state.index!=='number'){throw new Error('The index of the route should be state in the navigation state');}return React.createElement(View,{style:[styles.container,this.props.style],__source:{fileName:_jsxFileName,lineNumber:101}},React.createElement(ContentComponent,_extends({},this.props.contentOptions,{navigation:this.props.navigation,descriptors:this.props.descriptors,drawerOpenProgress:this.props.drawerOpenProgress,items:state.routes,activeItemKey:state.routes[state.index]?state.routes[state.index].key:null,screenProps:this.props.screenProps,getLabel:this.getLabel,renderIcon:this.renderIcon,onItemPress:this.handleItemPress,drawerPosition:this.props.drawerPosition,__source:{fileName:_jsxFileName,lineNumber:102}})));}}]);return DrawerSidebar;}(React.PureComponent);export default DrawerSidebar;var styles=StyleSheet.create({container:{flex:1}});
//# sourceMappingURL=DrawerSidebar.js.map