You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
4.9 KiB
132 lines
4.9 KiB
'use strict';
|
|
|
|
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 _react = require('react');
|
|
|
|
var _react2 = _interopRequireDefault(_react);
|
|
|
|
var _reactDom = require('react-dom');
|
|
|
|
var _reactDom2 = _interopRequireDefault(_reactDom);
|
|
|
|
var _cssAnimation = require('@ant-design/css-animation');
|
|
|
|
var _cssAnimation2 = _interopRequireDefault(_cssAnimation);
|
|
|
|
var _animate = require('./util/animate');
|
|
|
|
var _animate2 = _interopRequireDefault(_animate);
|
|
|
|
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; } /* eslint react/prop-types: 0 */
|
|
|
|
|
|
var transitionMap = {
|
|
enter: 'transitionEnter',
|
|
appear: 'transitionAppear',
|
|
leave: 'transitionLeave'
|
|
};
|
|
|
|
var AnimateChild = function (_React$Component) {
|
|
_inherits(AnimateChild, _React$Component);
|
|
|
|
function AnimateChild() {
|
|
_classCallCheck(this, AnimateChild);
|
|
|
|
return _possibleConstructorReturn(this, (AnimateChild.__proto__ || Object.getPrototypeOf(AnimateChild)).apply(this, arguments));
|
|
}
|
|
|
|
_createClass(AnimateChild, [{
|
|
key: 'componentWillUnmount',
|
|
value: function componentWillUnmount() {
|
|
this.stop();
|
|
}
|
|
}, {
|
|
key: 'componentWillEnter',
|
|
value: function componentWillEnter(done) {
|
|
if (_animate2['default'].isEnterSupported(this.props)) {
|
|
this.transition('enter', done);
|
|
} else {
|
|
done();
|
|
}
|
|
}
|
|
}, {
|
|
key: 'componentWillAppear',
|
|
value: function componentWillAppear(done) {
|
|
if (_animate2['default'].isAppearSupported(this.props)) {
|
|
this.transition('appear', done);
|
|
} else {
|
|
done();
|
|
}
|
|
}
|
|
}, {
|
|
key: 'componentWillLeave',
|
|
value: function componentWillLeave(done) {
|
|
if (_animate2['default'].isLeaveSupported(this.props)) {
|
|
this.transition('leave', done);
|
|
} else {
|
|
// always sync, do not interupt with react component life cycle
|
|
// update hidden -> animate hidden ->
|
|
// didUpdate -> animate leave -> unmount (if animate is none)
|
|
done();
|
|
}
|
|
}
|
|
}, {
|
|
key: 'transition',
|
|
value: function transition(animationType, finishCallback) {
|
|
var _this2 = this;
|
|
|
|
var node = _reactDom2['default'].findDOMNode(this);
|
|
var props = this.props;
|
|
var transitionName = props.transitionName;
|
|
var nameIsObj = typeof transitionName === 'object';
|
|
this.stop();
|
|
var end = function end() {
|
|
_this2.stopper = null;
|
|
finishCallback();
|
|
};
|
|
if ((_cssAnimation.isCssAnimationSupported || !props.animation[animationType]) && transitionName && props[transitionMap[animationType]]) {
|
|
var name = nameIsObj ? transitionName[animationType] : transitionName + '-' + animationType;
|
|
var activeName = name + '-active';
|
|
if (nameIsObj && transitionName[animationType + 'Active']) {
|
|
activeName = transitionName[animationType + 'Active'];
|
|
}
|
|
this.stopper = (0, _cssAnimation2['default'])(node, {
|
|
name: name,
|
|
active: activeName
|
|
}, end);
|
|
} else {
|
|
this.stopper = props.animation[animationType](node, end);
|
|
}
|
|
}
|
|
}, {
|
|
key: 'stop',
|
|
value: function stop() {
|
|
var stopper = this.stopper;
|
|
if (stopper) {
|
|
this.stopper = null;
|
|
stopper.stop();
|
|
}
|
|
}
|
|
}, {
|
|
key: 'render',
|
|
value: function render() {
|
|
return this.props.children;
|
|
}
|
|
}]);
|
|
|
|
return AnimateChild;
|
|
}(_react2['default'].Component);
|
|
|
|
exports['default'] = AnimateChild;
|
|
module.exports = exports['default']; |