@tamagui/react-native-web-lite
Version:
React Native for Web
164 lines (163 loc) • 6.73 kB
JavaScript
import NativeAnimatedHelper from "../NativeAnimatedHelper.native.js";
import { invariant } from "@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 = NativeAnimatedHelper.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 && (NativeAnimatedHelper.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 = NativeAnimatedHelper.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 () {
NativeAnimatedHelper.assertNativeAnimatedModule(), 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 : NativeAnimatedHelper.generateNewNodeTag();
if (this.__nativeTag == null) {
this.__nativeTag = nativeTag;
var config = this.__getNativeConfig();
this._platformConfig && (config.platformConfig = this._platformConfig), NativeAnimatedHelper.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;
export { AnimatedNode_default as default };
//# sourceMappingURL=AnimatedNode.native.js.map