UNPKG

@tamagui/react-native-web-lite

Version:
39 lines (38 loc) 2.11 kB
import { shouldUseNativeDriver } from "../NativeAnimatedHelper.mjs"; import Animation from "./Animation.mjs"; class DecayAnimation extends Animation { constructor(config) { var _config$deceleration, _config$isInteraction, _config$iterations; super(), this._deceleration = (_config$deceleration = config.deceleration) !== null && _config$deceleration !== void 0 ? _config$deceleration : 0.998, this._velocity = config.velocity, this._useNativeDriver = shouldUseNativeDriver(config), this.__isInteraction = (_config$isInteraction = config.isInteraction) !== null && _config$isInteraction !== void 0 ? _config$isInteraction : !this._useNativeDriver, this.__iterations = (_config$iterations = config.iterations) !== null && _config$iterations !== void 0 ? _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() { 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))); } stop() { super.stop(), this.__active = !1, global.cancelAnimationFrame(this._animationFrame), this.__debouncedOnEnd({ finished: !1 }); } } var DecayAnimation_default = DecayAnimation; export { DecayAnimation_default as default }; //# sourceMappingURL=DecayAnimation.mjs.map