UNPKG

@tamagui/react-native-web-lite

Version:
215 lines (214 loc) 8.45 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 AnimatedNode_exports = {}; __export(AnimatedNode_exports, { default: () => AnimatedNode_default }); module.exports = __toCommonJS(AnimatedNode_exports); var import_NativeAnimatedHelper = __toESM(require("../NativeAnimatedHelper")), import_react_native_web_internals = require("@tamagui/react-native-web-internals"); 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 _define_property(obj, key, value) { return key in obj ? Object.defineProperty(obj, key, { value, enumerable: !0, configurable: !0, writable: !0 }) : obj[key] = value, obj; } var NativeAnimatedAPI = import_NativeAnimatedHelper.default.API, _uniqueId = 1, AnimatedNode = /* @__PURE__ */ function() { function AnimatedNode2() { _class_call_check(this, AnimatedNode2), _define_property(this, "_listeners", void 0), _define_property(this, "_platformConfig", void 0), _define_property(this, "__nativeAnimatedValueListener", void 0), _define_property(this, "__isNative", void 0), _define_property(this, "__nativeTag", void 0), _define_property(this, "__shouldUpdateListenersForNewNativeTag", void 0), this._listeners = {}; } return _create_class(AnimatedNode2, [ { key: "__attach", value: function() { } }, { key: "__detach", value: function() { this.__isNative && this.__nativeTag != null && (import_NativeAnimatedHelper.default.API.dropAnimatedNode(this.__nativeTag), this.__nativeTag = void 0); } }, { key: "__getValue", value: function() { } }, { key: "__getAnimatedValue", value: function() { return this.__getValue(); } }, { key: "__addChild", value: function(child) { } }, { key: "__removeChild", value: function(child) { } }, { key: "__getChildren", value: function() { return []; } }, { key: "__makeNative", value: function(platformConfig) { if (!this.__isNative) throw new Error('This node cannot be made a "native" animated node'); this._platformConfig = platformConfig, this.hasListeners() && this._startListeningToNativeValueUpdates(); } }, { /** * 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. * * See https://reactnative.dev/docs/animatedvalue#addlistener */ key: "addListener", value: function(callback) { var id = String(_uniqueId++); return this._listeners[id] = callback, this.__isNative && this._startListeningToNativeValueUpdates(), id; } }, { /** * Unregister a listener. The `id` param shall match the identifier * previously returned by `addListener()`. * * See https://reactnative.dev/docs/animatedvalue#removelistener */ key: "removeListener", value: function(id) { delete this._listeners[id], this.__isNative && !this.hasListeners() && this._stopListeningForNativeValueUpdates(); } }, { /** * Remove all registered listeners. * * See https://reactnative.dev/docs/animatedvalue#removealllisteners */ key: "removeAllListeners", value: function() { this._listeners = {}, this.__isNative && this._stopListeningForNativeValueUpdates(); } }, { key: "hasListeners", value: function() { return !!Object.keys(this._listeners).length; } }, { key: "_startListeningToNativeValueUpdates", value: function() { var _this = this; this.__nativeAnimatedValueListener && !this.__shouldUpdateListenersForNewNativeTag || (this.__shouldUpdateListenersForNewNativeTag && (this.__shouldUpdateListenersForNewNativeTag = !1, this._stopListeningForNativeValueUpdates()), NativeAnimatedAPI.startListeningToAnimatedNodeValue(this.__getNativeTag()), this.__nativeAnimatedValueListener = import_NativeAnimatedHelper.default.nativeEventEmitter.addListener("onAnimatedValueUpdate", function(data) { data.tag === _this.__getNativeTag() && _this.__onAnimatedValueUpdateReceived(data.value); })); } }, { key: "__onAnimatedValueUpdateReceived", value: function(value) { this.__callListeners(value); } }, { key: "__callListeners", value: function(value) { for (var key in this._listeners) this._listeners[key]({ value }); } }, { key: "_stopListeningForNativeValueUpdates", value: function() { this.__nativeAnimatedValueListener && (this.__nativeAnimatedValueListener.remove(), this.__nativeAnimatedValueListener = null, NativeAnimatedAPI.stopListeningToAnimatedNodeValue(this.__getNativeTag())); } }, { key: "__getNativeTag", value: function() { import_NativeAnimatedHelper.default.assertNativeAnimatedModule(), (0, import_react_native_web_internals.invariant)(this.__isNative, 'Attempt to get native tag from node not marked as "native"'); var _this___nativeTag, nativeTag = (_this___nativeTag = this.__nativeTag) !== null && _this___nativeTag !== void 0 ? _this___nativeTag : import_NativeAnimatedHelper.default.generateNewNodeTag(); if (this.__nativeTag == null) { this.__nativeTag = nativeTag; var config = this.__getNativeConfig(); this._platformConfig && (config.platformConfig = this._platformConfig), import_NativeAnimatedHelper.default.API.createAnimatedNode(nativeTag, config), this.__shouldUpdateListenersForNewNativeTag = !0; } return nativeTag; } }, { key: "__getNativeConfig", value: function() { throw new Error("This JS animated node type cannot be used as native animated node"); } }, { key: "toJSON", value: function() { return this.__getValue(); } }, { key: "__getPlatformConfig", value: function() { return this._platformConfig; } }, { key: "__setPlatformConfig", value: function(platformConfig) { this._platformConfig = platformConfig; } } ]), AnimatedNode2; }(), AnimatedNode_default = AnimatedNode; //# sourceMappingURL=AnimatedNode.js.map