UNPKG

weex-nuke

Version:

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

147 lines (123 loc) 5.33 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = undefined; 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 _nukeEnv = require('../Env/index.js'); 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; } /** @jsx createElement */ /** * Copyright (c) 2015-present, Alibaba Group Holding Limited. * All rights reserved. * * @providesModule Slider */ var Slide = void 0; if (_nukeEnv.isWeb) { Slide = require('./slider.js'); } var Slider = function (_Component) { _inherits(Slider, _Component); function Slider(props) { _classCallCheck(this, Slider); var _this = _possibleConstructorReturn(this, (Slider.__proto__ || Object.getPrototypeOf(Slider)).call(this, props)); _this.onChange = function (e) { _this.props.onChange && _this.props.onChange(e); }; _this.onScroll = function (e) { _this.props.onScroll && _this.props.onScroll(e); }; _this.state = { index: props.index || 0 }; return _this; } _createClass(Slider, [{ key: 'componentDidMount', value: function componentDidMount() { var index = this.state.index; // android端需在tree模式下重新setState才能初始化非第一帧。 if (this.props.append == 'tree' && index != 0 && _nukeEnv.appInfo.android) { this.setState({ index: index }); } } }, { key: 'handleNativeProps', value: function handleNativeProps() { // 兼容API标准 var nativeProps = _extends({ onChange: this.onChange, onScroll: this.onScroll, offsetXAccuracy: this.props.accuracy || '10', autoPlay: this.props.autoPlay || this.props.autoplay, showIndicators: this.props.showsPagination, paginationStyle: Object.assign({ position: 'absolute', width: this.props.width, height: '40rem', bottom: '20rem', left: 0, itemColor: 'rgba(255, 255, 255, 0.5)', itemSelectedColor: 'rgb(255, 80, 0)', itemSize: '8rem' }, this.props.paginationStyle), interval: this.props.autoPlayInterval || this.props.autoplayTimeout }, { style: _extends({ width: this.props.width, height: this.props.height, overflow: 'hidden' }, this.props.style) }, { append: this.props.append || 'node' }); nativeProps.index = this.state.index; return nativeProps; } }, { key: 'render', value: function render() { // 兼容API标准 var props = _extends({}, this.props, { onChange: this.onChange, autoplayInterval: this.props.autoPlayInterval || this.props.autoplayTimeout, autoPlay: this.props.autoPlay || this.props.autoplay }); if (_nukeEnv.isWeex) { var children = this.props.children; var nativeProps = this.handleNativeProps(); return (0, _rax.createElement)( 'slider', nativeProps, nativeProps.showIndicators ? (0, _rax.createElement)('indicator', { style: nativeProps.paginationStyle }) : null, children ); } else { return (0, _rax.createElement)(Slide, _extends({ ref: 'Slider' }, props)); } } }, { key: 'slideTo', value: function slideTo(index) { if (_nukeEnv.isWeex) { this.setState({ index: index }); } else { this.props.onChange({ 'index': index }); this.refs.Slider.slideTo(index); } } }]); return Slider; }(_rax.Component); exports.default = Slider; module.exports = exports['default'];