@tamagui/react-native-web-lite
Version:
React Native for Web
67 lines (66 loc) • 3.4 kB
JavaScript
"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 DecayAnimation_exports = {};
__export(DecayAnimation_exports, {
default: () => DecayAnimation_default
});
module.exports = __toCommonJS(DecayAnimation_exports);
var import_Animation = __toESM(require("./Animation")), import_NativeAnimatedHelper = require("../NativeAnimatedHelper");
class DecayAnimation extends import_Animation.default {
_startTime;
_lastValue;
_fromValue;
_deceleration;
_velocity;
_onUpdate;
_animationFrame;
_useNativeDriver;
constructor(config) {
super(), this._deceleration = config.deceleration ?? 0.998, this._velocity = config.velocity, this._useNativeDriver = (0, import_NativeAnimatedHelper.shouldUseNativeDriver)(config), this.__isInteraction = config.isInteraction ?? !this._useNativeDriver, this.__iterations = config.iterations ?? 1;
}
__getNativeAnimationConfig() {
return {
type: "decay",
deceleration: this._deceleration,
velocity: this._velocity,
iterations: this.__iterations
};
}
start(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));
}
onUpdate() {
const 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)));
}
stop() {
super.stop(), this.__active = !1, global.cancelAnimationFrame(this._animationFrame), this.__debouncedOnEnd({ finished: !1 });
}
}
var DecayAnimation_default = DecayAnimation;
//# sourceMappingURL=DecayAnimation.js.map