UNPKG

yylib-quick-mobile

Version:

yylib-quick-mobile

130 lines (103 loc) 5.21 kB
'use strict'; var _tabBar = require('antd-mobile/lib/tab-bar'); var _tabBar2 = _interopRequireDefault(_tabBar); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); require('antd-mobile/lib/tab-bar/style/css'); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _YYIcon = require('./../icon/YYIcon'); var _YYIcon2 = _interopRequireDefault(_YYIcon); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var YYTabBarDev = function (_React$Component) { _inherits(YYTabBarDev, _React$Component); function YYTabBarDev() { _classCallCheck(this, YYTabBarDev); var _this = _possibleConstructorReturn(this, (YYTabBarDev.__proto__ || Object.getPrototypeOf(YYTabBarDev)).call(this)); _this.state = { selectTabBar: null }; return _this; } _createClass(YYTabBarDev, [{ key: 'onChange', value: function onChange(options) { if (options && options.nid) { this.setState({ selectTabBar: options.nid }); if (this.props.onChange && typeof this.props.onChange == "function") { this.props.onChange(options); } } } }, { key: 'getChildern', value: function getChildern() { var _this2 = this; var children = this.props.children; children = children && children.constructor == Array ? children : [children]; if (children && children.length) { Array.prototype.slice.call(children); return children.map(function (child, index) { var _child$props = child.props, uititle = _child$props.uititle, badge = _child$props.badge, icon = _child$props.icon, iconColor = _child$props.iconColor, selectedIconColor = _child$props.selectedIconColor, dot = _child$props.dot, selected = _child$props.selected, nid = _child$props.nid; return _react2.default.createElement( _tabBar2.default.Item, { title: uititle, badge: badge, icon: _react2.default.createElement(_YYIcon2.default, { type: icon, color: iconColor }), selectedIcon: _react2.default.createElement(_YYIcon2.default, { type: icon, color: selectedIconColor }), dot: dot, selected: !_this2.state.selectTabBar ? index == 0 : _this2.state.selectTabBar == nid, onPress: _this2.onChange.bind(_this2, child.props), key: index }, child.props.children ); }); } return []; } }, { key: 'render', value: function render() { var _props = this.props, barTintColor = _props.barTintColor, tintColor = _props.tintColor, unselectedTintColor = _props.unselectedTintColor, visible = _props.visible, restProps = _objectWithoutProperties(_props, ['barTintColor', 'tintColor', 'unselectedTintColor', 'visible']); return _react2.default.createElement( 'div', { style: { position: 'fixed', height: '100%', width: '100%', top: 0 } }, _react2.default.createElement( _tabBar2.default, _extends({}, restProps, { barTintColor: barTintColor, tintColor: tintColor, unselectedTintColor: unselectedTintColor, hidden: !visible }), this.getChildern() ) ); } }]); return YYTabBarDev; }(_react2.default.Component); ; YYTabBarDev.defaultProps = { visible: true }; module.exports = YYTabBarDev;