UNPKG

@tamagui/react-native-web-lite

Version:
168 lines (167 loc) 6.37 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf, __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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target, mod )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod); var AnimatedValueXY_exports = {}; __export(AnimatedValueXY_exports, { default: () => AnimatedValueXY_default }); module.exports = __toCommonJS(AnimatedValueXY_exports); var import_react_native_web_internals = require("@tamagui/react-native-web-internals"), import_AnimatedValue = __toESM(require("./AnimatedValue")), import_AnimatedWithChildren = __toESM(require("./AnimatedWithChildren")), _uniqueId = 1; class AnimatedValueXY extends import_AnimatedWithChildren.default { constructor(valueIn) { super(); var value = valueIn || { x: 0, y: 0 }; typeof value.x == "number" && typeof value.y == "number" ? (this.x = new import_AnimatedValue.default(value.x), this.y = new import_AnimatedValue.default(value.y)) : ((0, import_react_native_web_internals.invariant)( value.x instanceof import_AnimatedValue.default && value.y instanceof import_AnimatedValue.default, "AnimatedValueXY must be initialized with an object of numbers or AnimatedValues." ), this.x = value.x, this.y = value.y), this._listeners = {}; } /** * Directly set the value. This will stop any animations running on the value * and update all the bound properties. * * See https://reactnative.dev/docs/animatedvaluexy.html#setvalue */ setValue(value) { this.x.setValue(value.x), this.y.setValue(value.y); } /** * Sets an offset that is applied on top of whatever value is set, whether * via `setValue`, an animation, or `Animated.event`. Useful for compensating * things like the start of a pan gesture. * * See https://reactnative.dev/docs/animatedvaluexy.html#setoffset */ setOffset(offset) { this.x.setOffset(offset.x), this.y.setOffset(offset.y); } /** * Merges the offset value into the base value and resets the offset to zero. * The final output of the value is unchanged. * * See https://reactnative.dev/docs/animatedvaluexy.html#flattenoffset */ flattenOffset() { this.x.flattenOffset(), this.y.flattenOffset(); } /** * Sets the offset value to the base value, and resets the base value to * zero. The final output of the value is unchanged. * * See https://reactnative.dev/docs/animatedvaluexy.html#extractoffset */ extractOffset() { this.x.extractOffset(), this.y.extractOffset(); } __getValue() { return { x: this.x.__getValue(), y: this.y.__getValue() }; } /** * Stops any animation and resets the value to its original. * * See https://reactnative.dev/docs/animatedvaluexy.html#resetanimation */ resetAnimation(callback) { this.x.resetAnimation(), this.y.resetAnimation(), callback && callback(this.__getValue()); } /** * Stops any running animation or tracking. `callback` is invoked with the * final value after stopping the animation, which is useful for updating * state to match the animation position with layout. * * See https://reactnative.dev/docs/animatedvaluexy.html#stopanimation */ stopAnimation(callback) { this.x.stopAnimation(), this.y.stopAnimation(), callback && callback(this.__getValue()); } /** * Adds an asynchronous listener to the value so you can observe updates from * animations. This is useful because there is no way to synchronously read * the value because it might be driven natively. * * Returns a string that serves as an identifier for the listener. * * See https://reactnative.dev/docs/animatedvaluexy.html#addlistener */ addListener(callback) { var id = String(_uniqueId++), jointCallback = (_ref) => { var number = _ref.value; callback(this.__getValue()); }; return this._listeners[id] = { x: this.x.addListener(jointCallback), y: this.y.addListener(jointCallback) }, id; } /** * Unregister a listener. The `id` param shall match the identifier * previously returned by `addListener()`. * * See https://reactnative.dev/docs/animatedvaluexy.html#removelistener */ removeListener(id) { this.x.removeListener(this._listeners[id].x), this.y.removeListener(this._listeners[id].y), delete this._listeners[id]; } /** * Remove all registered listeners. * * See https://reactnative.dev/docs/animatedvaluexy.html#removealllisteners */ removeAllListeners() { this.x.removeAllListeners(), this.y.removeAllListeners(), this._listeners = {}; } /** * Converts `{x, y}` into `{left, top}` for use in style. * * See https://reactnative.dev/docs/animatedvaluexy.html#getlayout */ getLayout() { return { left: this.x, top: this.y }; } /** * Converts `{x, y}` into a useable translation transform. * * See https://reactnative.dev/docs/animatedvaluexy.html#gettranslatetransform */ getTranslateTransform() { return [ { translateX: this.x }, { translateY: this.y } ]; } } var AnimatedValueXY_default = AnimatedValueXY; //# sourceMappingURL=AnimatedValueXY.js.map