UNPKG

addimated

Version:

An always interruptable, declarative animation library for React

132 lines (113 loc) 3.72 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.AnimatedValueXY = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var _invariant = _interopRequireDefault(require("invariant")); var _AnimatedValue = require("./AnimatedValue"); var _AnimatedWithChildren2 = require("./AnimatedWithChildren"); var AnimatedValueXY = /*#__PURE__*/ function (_AnimatedWithChildren) { (0, _inherits2.default)(AnimatedValueXY, _AnimatedWithChildren); function AnimatedValueXY(valueIn, manager) { var _this; (0, _classCallCheck2.default)(this, AnimatedValueXY); _this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(AnimatedValueXY).call(this)); var value = valueIn || { x: 0, y: 0 }; if (typeof value.x === "number" && typeof value.y === "number") { _this.x = new _AnimatedValue.AnimatedValue(value.x, manager); _this.y = new _AnimatedValue.AnimatedValue(value.y, manager); } else { !(value.x instanceof _AnimatedValue.AnimatedValue && value.y instanceof _AnimatedValue.AnimatedValue) ? process.env.NODE_ENV !== "production" ? (0, _invariant.default)(false, "AnimatedValueXY must be initalized with an object of numbers or " + "AnimatedValues.") : invariant(false) : void 0; _this.x = value.x; _this.y = value.y; } return _this; } (0, _createClass2.default)(AnimatedValueXY, [{ key: "setValue", value: function setValue(value) { this.x.setValue(value.x); this.y.setValue(value.y); } }, { key: "setOffset", value: function setOffset(offset) { this.x.setOffset(offset.x); this.y.setOffset(offset.y); } }, { key: "flattenOffset", value: function flattenOffset() { this.x.flattenOffset(); this.y.flattenOffset(); } }, { key: "extractOffset", value: function extractOffset() { this.x.extractOffset(); this.y.extractOffset(); } }, { key: "__getValue", value: function __getValue() { return { x: this.x.__getValue(), y: this.y.__getValue() }; } }, { key: "stopAnimations", value: function stopAnimations(callback) { this.x.stopAnimations(); this.y.stopAnimations(); callback && callback(this.__getValue()); } /** * Converts `{x, y}` into `{left, top}` for use in style, e.g. * *```javascript * style={this.state.anim.getLayout()} *``` */ }, { key: "getLayout", value: function getLayout() { return { left: this.x, top: this.y }; } /** * Converts `{x, y}` into a useable translation transform, e.g. * *```javascript * style={{ * transform: this.state.anim.getTranslateTransform() * }} *``` */ }, { key: "getTranslateTransform", value: function getTranslateTransform() { return [{ translateX: this.x }, { translateY: this.y }]; } }]); return AnimatedValueXY; }(_AnimatedWithChildren2.AnimatedWithChildren); exports.AnimatedValueXY = AnimatedValueXY; //# sourceMappingURL=AnimatedValueXY.js.map