@tamagui/react-native-web-lite
Version:
React Native for Web
83 lines (82 loc) • 4.84 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 TimingAnimation_exports = {};
__export(TimingAnimation_exports, {
default: () => TimingAnimation_default
});
module.exports = __toCommonJS(TimingAnimation_exports);
var import_Easing = __toESM(require("../Easing")), import_NativeAnimatedHelper = require("../NativeAnimatedHelper"), import_Animation = __toESM(require("./Animation")), _easeInOut;
function easeInOut() {
return _easeInOut || (_easeInOut = import_Easing.default.inOut(import_Easing.default.ease)), _easeInOut;
}
class TimingAnimation extends import_Animation.default {
constructor(config) {
var _config$easing, _config$duration, _config$delay, _config$iterations, _config$isInteraction;
super(), this._toValue = config.toValue, this._easing = (_config$easing = config.easing) !== null && _config$easing !== void 0 ? _config$easing : easeInOut(), this._duration = (_config$duration = config.duration) !== null && _config$duration !== void 0 ? _config$duration : 500, this._delay = (_config$delay = config.delay) !== null && _config$delay !== void 0 ? _config$delay : 0, this.__iterations = (_config$iterations = config.iterations) !== null && _config$iterations !== void 0 ? _config$iterations : 1, this._useNativeDriver = (0, import_NativeAnimatedHelper.shouldUseNativeDriver)(config), this._platformConfig = config.platformConfig, this.__isInteraction = (_config$isInteraction = config.isInteraction) !== null && _config$isInteraction !== void 0 ? _config$isInteraction : !this._useNativeDriver;
}
__getNativeAnimationConfig() {
for (var frameDuration = 16.666666666666668, frames = [], numFrames = Math.round(this._duration / frameDuration), frame = 0; frame < numFrames; frame++)
frames.push(this._easing(frame / numFrames));
return frames.push(this._easing(1)), {
type: "frames",
frames,
toValue: this._toValue,
iterations: this.__iterations,
platformConfig: this._platformConfig
};
}
start(fromValue, onUpdate, onEnd, previousAnimation, animatedValue) {
this.__active = !0, this._fromValue = fromValue, this._onUpdate = onUpdate, this.__onEnd = onEnd;
var start = () => {
this._duration === 0 && !this._useNativeDriver ? (this._onUpdate(this._toValue), this.__debouncedOnEnd({
finished: !0
})) : (this._startTime = Date.now(), this._useNativeDriver ? this.__startNativeAnimation(animatedValue) : this._animationFrame = requestAnimationFrame(
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
this.onUpdate.bind(this)
));
};
this._delay ? this._timeout = setTimeout(start, this._delay) : start();
}
onUpdate() {
var now = Date.now();
if (now >= this._startTime + this._duration) {
this._duration === 0 ? this._onUpdate(this._toValue) : this._onUpdate(
this._fromValue + this._easing(1) * (this._toValue - this._fromValue)
), this.__debouncedOnEnd({
finished: !0
});
return;
}
this._onUpdate(
this._fromValue + this._easing((now - this._startTime) / this._duration) * (this._toValue - this._fromValue)
), this.__active && (this._animationFrame = requestAnimationFrame(this.onUpdate.bind(this)));
}
stop() {
super.stop(), this.__active = !1, clearTimeout(this._timeout), global.cancelAnimationFrame(this._animationFrame), this.__debouncedOnEnd({
finished: !1
});
}
}
var TimingAnimation_default = TimingAnimation;
//# sourceMappingURL=TimingAnimation.js.map