UNPKG

@tamagui/react-native-web-lite

Version:
223 lines (221 loc) 8.45 kB
import { invariant } from "@tamagui/react-native-web-internals"; import AnimatedValue from "./AnimatedValue.native.js"; import AnimatedWithChildren from "./AnimatedWithChildren.native.js"; function _assert_this_initialized(self) { if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return self; } function _call_super(_this, derived, args) { return derived = _get_prototype_of(derived), _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args)); } function _class_call_check(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } function _create_class(Constructor, protoProps, staticProps) { return protoProps && _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Constructor; } function _get_prototype_of(o) { return _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function (o2) { return o2.__proto__ || Object.getPrototypeOf(o2); }, _get_prototype_of(o); } function _inherits(subClass, superClass) { if (typeof superClass != "function" && superClass !== null) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: !0, configurable: !0 } }), superClass && _set_prototype_of(subClass, superClass); } function _possible_constructor_return(self, call) { return call && (_type_of(call) === "object" || typeof call == "function") ? call : _assert_this_initialized(self); } function _set_prototype_of(o, p) { return _set_prototype_of = Object.setPrototypeOf || function (o2, p2) { return o2.__proto__ = p2, o2; }, _set_prototype_of(o, p); } function _type_of(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj; } function _is_native_reflect_construct() { try { var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch {} return (_is_native_reflect_construct = function () { return !!result; })(); } var _uniqueId = 1, AnimatedValueXY = /* @__PURE__ */function (AnimatedWithChildren2) { _inherits(AnimatedValueXY2, AnimatedWithChildren2); function AnimatedValueXY2(valueIn) { _class_call_check(this, AnimatedValueXY2); var _this; _this = _call_super(this, AnimatedValueXY2); var value = valueIn || { x: 0, y: 0 }; return typeof value.x == "number" && typeof value.y == "number" ? (_this.x = new AnimatedValue(value.x), _this.y = new AnimatedValue(value.y)) : (invariant(value.x instanceof AnimatedValue && value.y instanceof AnimatedValue, "AnimatedValueXY must be initialized with an object of numbers or AnimatedValues."), _this.x = value.x, _this.y = value.y), _this._listeners = {}, _this; } return _create_class(AnimatedValueXY2, [{ /** * 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 */ key: "setValue", value: function (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 */ key: "setOffset", value: function (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 */ key: "flattenOffset", value: function () { 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 */ key: "extractOffset", value: function () { this.x.extractOffset(), this.y.extractOffset(); } }, { key: "__getValue", value: function () { 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 */ key: "resetAnimation", value: function (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 */ key: "stopAnimation", value: function (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 */ key: "addListener", value: function (callback) { var _this = this, id = String(_uniqueId++), jointCallback = function (_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 */ key: "removeListener", value: function (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 */ key: "removeAllListeners", value: function () { 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 */ key: "getLayout", value: function () { return { left: this.x, top: this.y }; } }, { /** * Converts `{x, y}` into a useable translation transform. * * See https://reactnative.dev/docs/animatedvaluexy.html#gettranslatetransform */ key: "getTranslateTransform", value: function () { return [{ translateX: this.x }, { translateY: this.y }]; } }]), AnimatedValueXY2; }(AnimatedWithChildren), AnimatedValueXY_default = AnimatedValueXY; export { AnimatedValueXY_default as default }; //# sourceMappingURL=AnimatedValueXY.native.js.map