@tamagui/react-native-web-lite
Version:
React Native for Web
83 lines (82 loc) • 3.34 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: !0 });
}, __copyProps = (to, from, except, desc) => {
if (from && typeof from == "object" || typeof from == "function")
for (let key of __getOwnPropNames(from))
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
var AnimatedValueXY_exports = {};
__export(AnimatedValueXY_exports, {
AnimatedValueXY: () => AnimatedValueXY,
default: () => AnimatedValueXY_default
});
module.exports = __toCommonJS(AnimatedValueXY_exports);
var import_AnimatedValue = require("./AnimatedValue"), import_AnimatedWithChildren = require("./AnimatedWithChildren"), import_react_native_web_internals = require("@tamagui/react-native-web-internals");
let _uniqueId = 1;
class AnimatedValueXY extends import_AnimatedWithChildren.AnimatedWithChildren {
constructor(valueIn) {
super();
const value = valueIn || { x: 0, y: 0 };
typeof value.x == "number" && typeof value.y == "number" ? (this.x = new import_AnimatedValue.AnimatedValue(value.x), this.y = new import_AnimatedValue.AnimatedValue(value.y)) : ((0, import_react_native_web_internals.invariant)(
value.x instanceof import_AnimatedValue.AnimatedValue && value.y instanceof import_AnimatedValue.AnimatedValue,
"AnimatedValueXY must be initialized with an object of numbers or AnimatedValues."
), this.x = value.x, this.y = value.y), this._listeners = {};
}
setValue(value) {
this.x.setValue(value.x), this.y.setValue(value.y);
}
setOffset(offset) {
this.x.setOffset(offset.x), this.y.setOffset(offset.y);
}
flattenOffset() {
this.x.flattenOffset(), this.y.flattenOffset();
}
extractOffset() {
this.x.extractOffset(), this.y.extractOffset();
}
__getValue() {
return {
x: this.x.__getValue(),
y: this.y.__getValue()
};
}
resetAnimation(callback) {
this.x.resetAnimation(), this.y.resetAnimation(), callback && callback(this.__getValue());
}
stopAnimation(callback) {
this.x.stopAnimation(), this.y.stopAnimation(), callback && callback(this.__getValue());
}
addListener(callback) {
const id = String(_uniqueId++), jointCallback = ({ value }) => {
callback(this.__getValue());
};
return this._listeners[id] = {
x: this.x.addListener(jointCallback),
y: this.y.addListener(jointCallback)
}, id;
}
removeListener(id) {
this.x.removeListener(this._listeners[id].x), this.y.removeListener(this._listeners[id].y), delete this._listeners[id];
}
removeAllListeners() {
this.x.removeAllListeners(), this.y.removeAllListeners(), this._listeners = {};
}
getLayout() {
return {
left: this.x,
top: this.y
};
}
getTranslateTransform() {
return [{ translateX: this.x }, { translateY: this.y }];
}
}
var AnimatedValueXY_default = AnimatedValueXY;
//# sourceMappingURL=AnimatedValueXY.js.map