UNPKG

weex-nuke

Version:

基于 Rax 、Weex 的高性能组件体系 ~~

164 lines (122 loc) 5.87 kB
/** @jsx createElement */ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); 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; }; }(); var _rax = require('rax'); var _nukeEpUtils = require('../../EpUtils/index.js'); var _nukeThemeProvider = require('../../ThemeProvider/index.js'); var _emitter = require('../util/emitter.js'); var _emitter2 = _interopRequireDefault(_emitter); var _index = require('../styles/index.js'); var _index2 = _interopRequireDefault(_index); var _nukeView = require('../../View/index.js'); var _nukeView2 = _interopRequireDefault(_nukeView); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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; } // 在weex及非android4.4以下的机器中才使用ep绑定 var expressionBinding = {}; try { expressionBinding = require('@weex-module/expressionBinding'); } catch (e) {} var Item = function (_Component) { _inherits(Item, _Component); function Item(props) { _classCallCheck(this, Item); var _this = _possibleConstructorReturn(this, (Item.__proto__ || Object.getPrototypeOf(Item)).call(this, props)); _this.onHorizontalPan = function (e) { if (e.state === 'start') { _this.isPanning = true; _emitter2.default.emit('slider', { element: (0, _rax.findDOMNode)(_this) }); } else if (e.state === 'end') { setTimeout(function () { _this.isPanning = false; }, 50); } }; _this.onItemAppear = function (e) { if (_nukeEpUtils.Detection.epEnable && _nukeEpUtils.Detection.Android) { var element = (0, _rax.findDOMNode)(_this); if (element && element.ref) { expressionBinding.enableBinding(element.ref, 'pan'); } } var _this$props = _this.props, onAppear = _this$props.onAppear, exposure = _this$props.exposure; if (exposure === true && !_this.isAppear) { _this.isAppear = true; } if (typeof onAppear === 'function') { onAppear(e); } }; _this.onItemDisAppear = function (e) { if (_nukeEpUtils.Detection.epEnable && _nukeEpUtils.Detection.Android) { var element = (0, _rax.findDOMNode)(_this); if (element && element.ref) { expressionBinding.disableBinding(element.ref, 'pan'); } } var onDisAppear = _this.props.onDisAppear; if (typeof onDisAppear === 'function') { onDisAppear(e); } }; _this.onClick = function (e) { // console.log('click-->', e); }; _this.isPaning = false; _this.isAppear = false; return _this; } _createClass(Item, [{ key: 'componentDidMount', value: function componentDidMount() { var _this2 = this; setTimeout(function () { if (_nukeEpUtils.Detection.epEnable && _nukeEpUtils.Detection.Android) { try { var element = (0, _rax.findDOMNode)(_this2); if (element && element.ref) { expressionBinding.enableBinding(element.ref, 'pan'); } } catch (e) { console.error('pancell findDOMNode error'); } } }, 300); } // use for andorid // @todo 事件绑定存在问题,当list作为子元素时无法触发横向滚动 // @todo bug android事件冒泡需要在list的cell中再次绑定onHorizontalPan,作为事件anchor }, { key: 'render', value: function render() { var _props = this.props, style = _props.style, children = _props.children, themeStyle = _props.themeStyle; return (0, _rax.createElement)(_nukeView2.default, _extends({}, this.props, { style: [themeStyle.container, style], preventMoveEvent: false, onAppear: this.onItemAppear, onClick: this.onClick, onDisAppear: this.onItemDisAppear, onHorizontalPan: this.onHorizontalPan })); } }]); return Item; }(_rax.Component); // Item.propTypes = {}; // Item.defaultProps = {}; Item.displayName = 'Ep-Tabbar'; exports.default = (0, _nukeThemeProvider.connectStyle)(_index2.default)(Item); module.exports = exports['default'];