addimated
Version:
An always interruptable, declarative animation library for React
118 lines (107 loc) • 3.19 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import invariant from "invariant";
import { AnimatedValue } from "./AnimatedValue";
import { AnimatedWithChildren } from "./AnimatedWithChildren";
var AnimatedValueXY =
/*#__PURE__*/
function (_AnimatedWithChildren) {
_inherits(AnimatedValueXY, _AnimatedWithChildren);
function AnimatedValueXY(valueIn, manager) {
var _this;
_classCallCheck(this, AnimatedValueXY);
_this = _possibleConstructorReturn(this, _getPrototypeOf(AnimatedValueXY).call(this));
var value = valueIn || {
x: 0,
y: 0
};
if (typeof value.x === "number" && typeof value.y === "number") {
_this.x = new AnimatedValue(value.x, manager);
_this.y = new AnimatedValue(value.y, manager);
} else {
!(value.x instanceof AnimatedValue && value.y instanceof AnimatedValue) ? process.env.NODE_ENV !== "production" ? invariant(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;
}
_createClass(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;
}(AnimatedWithChildren);
export { AnimatedValueXY };
//# sourceMappingURL=AnimatedValueXY.js.map