react-navigation-drawer
Version:
Drawer navigator component for React Navigation
2 lines • 3.93 kB
JavaScript
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends"));var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _possibleConstructorReturn2=_interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));var _getPrototypeOf3=_interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));var _inherits2=_interopRequireDefault(require("@babel/runtime/helpers/inherits"));var React=_interopRequireWildcard(require("react"));var _reactNative=require("react-native");var _reactNavigation=require("react-navigation");var _jsxFileName="/Users/satya/Workspace/Callstack/drawer/src/views/DrawerSidebar.tsx";var DrawerSidebar=function(_React$PureComponent){(0,_inherits2.default)(DrawerSidebar,_React$PureComponent);function DrawerSidebar(){var _getPrototypeOf2;var _this;(0,_classCallCheck2.default)(this,DrawerSidebar);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this=(0,_possibleConstructorReturn2.default)(this,(_getPrototypeOf2=(0,_getPrototypeOf3.default)(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(_reactNavigation.NavigationActions.navigate({routeName:route.routeName}));}};return _this;}(0,_createClass2.default)(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(_reactNative.View,{style:[styles.container,this.props.style],__source:{fileName:_jsxFileName,lineNumber:101}},React.createElement(ContentComponent,(0,_extends2.default)({},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);var _default=DrawerSidebar;exports.default=_default;var styles=_reactNative.StyleSheet.create({container:{flex:1}});
//# sourceMappingURL=DrawerSidebar.js.map