nuke-biz-custom-loading
Version:
nuke-biz-custom-loading
167 lines (144 loc) • 5.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
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 _weexNuke = require('weex-nuke');
var _styles = require('./styles');
var _styles2 = _interopRequireDefault(_styles);
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; } /** @jsx createElement */
var connectStyle = _weexNuke.ThemeProvider.connectStyle;
var isWeb = _weexNuke.Env.isWeb;
var CustomLoading = function (_Component) {
_inherits(CustomLoading, _Component);
function CustomLoading(props) {
_classCallCheck(this, CustomLoading);
var _this = _possibleConstructorReturn(this, (CustomLoading.__proto__ || Object.getPrototypeOf(CustomLoading)).call(this, props));
var defaultVisible = props.defaultVisible;
_this.state = {
shown: defaultVisible
};
_this.show = _this.show.bind(_this);
_this.hide = _this.hide.bind(_this);
_this.onShow = _this.onShow.bind(_this);
_this.onHide = _this.onHide.bind(_this);
return _this;
}
_createClass(CustomLoading, [{
key: 'componentDidMount',
value: function componentDidMount() {
this.loading = this.refs.mask;
if (this.state.shown) {
this.show();
}
}
}, {
key: 'shouldComponentUpdate',
value: function shouldComponentUpdate(nextProps, nextState) {
return nextState.shown !== this.state.shown;
}
}, {
key: 'onShow',
value: function onShow() {
this.props.onShow && this.props.onShow();
}
}, {
key: 'onHide',
value: function onHide() {
this.setState({
shown: false
});
this.props.onHide && this.props.onHide();
}
}, {
key: 'show',
value: function show() {
if (this.loading) {
this.setState({
shown: true
});
this.loading.show && this.loading.show();
}
}
}, {
key: 'hide',
value: function hide() {
if (this.loading) {
this.loading.hide && this.loading.hide();
}
}
}, {
key: 'wrapPress',
value: function wrapPress(e) {
if (isWeb) {
e.stopPropagation();
}
}
}, {
key: 'touchMove',
value: function touchMove(e) {
if (isWeb) {
e.preventDefault();
}
}
}, {
key: 'render',
value: function render() {
var styles = this.props.themeStyle;
var _props = this.props,
_props$image = _props.image,
image = _props$image === undefined ? { style: {} } : _props$image,
animate = _props.animate,
_props$style = _props.style,
style = _props$style === undefined ? {} : _props$style;
var imageWrap = Object.assign({}, styles.imageWrap, image.style.width ? { width: image.style.width } : {}, image.style.height ? { height: image.style.height } : {});
return (0, _rax.createElement)(
_weexNuke.Mask,
{
style: [styles.mask, style],
maskClosable: false,
defaultVisible: false,
animate: animate,
onShow: this.onShow,
onHide: this.onHide,
onTouchmove: this.touchMove,
ref: 'mask'
},
(0, _rax.createElement)(
_weexNuke.View,
{ style: imageWrap },
(0, _rax.createElement)(_weexNuke.Image, {
source: { uri: image.uri },
style: [styles.image, image.style],
resizeMode: 'cover',
quality: 'original'
})
)
);
}
}]);
return CustomLoading;
}(_rax.Component);
CustomLoading.propTypes = {
themeStyle: _rax.PropTypes.any,
style: _rax.PropTypes.any,
image: _rax.PropTypes.any,
onHide: _rax.PropTypes.func,
onShow: _rax.PropTypes.func
};
CustomLoading.defaultProps = {
themeStyle: {},
image: {},
style: {},
animate: true,
onHide: function onHide() {},
onShow: function onShow() {}
};
CustomLoading.displayName = 'CustomLoading';
var StyledCustomLoading = connectStyle(_styles2.default)(CustomLoading);
exports.default = StyledCustomLoading;
module.exports = exports['default'];