@tamagui/react-native-web-lite
Version:
React Native for Web
166 lines (164 loc) • 7.88 kB
JavaScript
import Animation from "./Animation.native.js";
import { shouldUseNativeDriver } from "../NativeAnimatedHelper.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 _construct(Parent, args, Class) {
return _is_native_reflect_construct() ? _construct = Reflect.construct : _construct = function (Parent2, args2, Class2) {
var a = [null];
a.push.apply(a, args2);
var Constructor = Function.bind.apply(Parent2, a),
instance = new Constructor();
return Class2 && _set_prototype_of(instance, Class2.prototype), instance;
}, _construct.apply(null, arguments);
}
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;
}
function _get(target, property, receiver) {
return typeof Reflect < "u" && Reflect.get ? _get = Reflect.get : _get = function (target2, property2, receiver2) {
var base = _super_prop_base(target2, property2);
if (base) {
var desc = Object.getOwnPropertyDescriptor(base, property2);
return desc.get ? desc.get.call(receiver2 || target2) : desc.value;
}
}, _get(target, property, receiver || target);
}
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 _is_native_function(fn) {
return Function.toString.call(fn).indexOf("[native code]") !== -1;
}
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 _super_prop_base(object, property) {
for (; !Object.prototype.hasOwnProperty.call(object, property) && (object = _get_prototype_of(object), object !== null););
return object;
}
function _type_of(obj) {
"@swc/helpers - typeof";
return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
function _wrap_native_super(Class) {
var _cache = typeof Map == "function" ? /* @__PURE__ */new Map() : void 0;
return _wrap_native_super = function (Class2) {
if (Class2 === null || !_is_native_function(Class2)) return Class2;
if (typeof Class2 != "function") throw new TypeError("Super expression must either be null or a function");
if (typeof _cache < "u") {
if (_cache.has(Class2)) return _cache.get(Class2);
_cache.set(Class2, Wrapper);
}
function Wrapper() {
return _construct(Class2, arguments, _get_prototype_of(this).constructor);
}
return Wrapper.prototype = Object.create(Class2.prototype, {
constructor: {
value: Wrapper,
enumerable: !1,
writable: !0,
configurable: !0
}
}), _set_prototype_of(Wrapper, Class2);
}, _wrap_native_super(Class);
}
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 DecayAnimation = /* @__PURE__ */function (Animation2) {
_inherits(DecayAnimation2, Animation2);
function DecayAnimation2(config) {
_class_call_check(this, DecayAnimation2);
var _this;
_this = _call_super(this, DecayAnimation2), _define_property(_this, "_startTime", void 0), _define_property(_this, "_lastValue", void 0), _define_property(_this, "_fromValue", void 0), _define_property(_this, "_deceleration", void 0), _define_property(_this, "_velocity", void 0), _define_property(_this, "_onUpdate", void 0), _define_property(_this, "_animationFrame", void 0), _define_property(_this, "_useNativeDriver", void 0);
var _config_deceleration;
_this._deceleration = (_config_deceleration = config.deceleration) !== null && _config_deceleration !== void 0 ? _config_deceleration : 0.998, _this._velocity = config.velocity, _this._useNativeDriver = shouldUseNativeDriver(config);
var _config_isInteraction;
_this.__isInteraction = (_config_isInteraction = config.isInteraction) !== null && _config_isInteraction !== void 0 ? _config_isInteraction : !_this._useNativeDriver;
var _config_iterations;
return _this.__iterations = (_config_iterations = config.iterations) !== null && _config_iterations !== void 0 ? _config_iterations : 1, _this;
}
return _create_class(DecayAnimation2, [{
key: "__getNativeAnimationConfig",
value: function () {
return {
type: "decay",
deceleration: this._deceleration,
velocity: this._velocity,
iterations: this.__iterations
};
}
}, {
key: "start",
value: function (fromValue, onUpdate, onEnd, previousAnimation, animatedValue) {
this.__active = !0, this._lastValue = fromValue, this._fromValue = fromValue, this._onUpdate = onUpdate, this.__onEnd = onEnd, this._startTime = Date.now(), this._useNativeDriver ? this.__startNativeAnimation(animatedValue) : this._animationFrame = requestAnimationFrame(this.onUpdate.bind(this));
}
}, {
key: "onUpdate",
value: function () {
var now = Date.now(),
value = this._fromValue + this._velocity / (1 - this._deceleration) * (1 - Math.exp(-(1 - this._deceleration) * (now - this._startTime)));
if (this._onUpdate(value), Math.abs(this._lastValue - value) < 0.1) {
this.__debouncedOnEnd({
finished: !0
});
return;
}
this._lastValue = value, this.__active && (this._animationFrame = requestAnimationFrame(this.onUpdate.bind(this)));
}
}, {
key: "stop",
value: function () {
_get(_get_prototype_of(DecayAnimation2.prototype), "stop", this).call(this), this.__active = !1, global.cancelAnimationFrame(this._animationFrame), this.__debouncedOnEnd({
finished: !1
});
}
}]), DecayAnimation2;
}(_wrap_native_super(Animation)),
DecayAnimation_default = DecayAnimation;
export { DecayAnimation_default as default };
//# sourceMappingURL=DecayAnimation.native.js.map