react-bodymovin
Version:
React wrapper for the bodymovin animation library
82 lines (64 loc) • 3.68 kB
JavaScript
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 _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof 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; }
var React = require('react');
var isDOM = (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' && _typeof(window.document) === 'object';
function ReactBodymovinImpl(bodymovin) {
var ReactBodymovin = function (_React$Component) {
_inherits(ReactBodymovin, _React$Component);
function ReactBodymovin() {
_classCallCheck(this, ReactBodymovin);
return _possibleConstructorReturn(this, (ReactBodymovin.__proto__ || Object.getPrototypeOf(ReactBodymovin)).apply(this, arguments));
}
_createClass(ReactBodymovin, [{
key: 'componentDidMount',
value: function componentDidMount() {
if (isDOM) {
var options = Object.assign({}, this.props.options);
options.wrapper = this.wrapper;
options.renderer = 'svg';
this.animation = bodymovin.loadAnimation(options);
}
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
if (isDOM) {
this.animation.destroy();
}
}
}, {
key: 'shouldComponentUpdate',
value: function shouldComponentUpdate() {
return false;
}
}, {
key: 'render',
value: function render() {
var _this2 = this;
var storeWrapper = function storeWrapper(el) {
_this2.wrapper = el;
};
return React.createElement(
'div',
{ className: 'react-bodymovin-container', ref: storeWrapper },
this.props.children
);
}
}]);
return ReactBodymovin;
}(React.Component);
return ReactBodymovin;
}
module.exports = ReactBodymovinImpl;
;
var _temp = function () {
if (typeof __REACT_HOT_LOADER__ === 'undefined') {
return;
}
__REACT_HOT_LOADER__.register(isDOM, 'isDOM', 'src/ReactBodymovinImpl.js');
__REACT_HOT_LOADER__.register(ReactBodymovinImpl, 'ReactBodymovinImpl', 'src/ReactBodymovinImpl.js');
}();
;