@tamagui/react-native-web-lite
Version:
React Native for Web
167 lines (165 loc) • 8.44 kB
JavaScript
import Easing from "../Easing.native.js";
import { shouldUseNativeDriver } from "../NativeAnimatedHelper.native.js";
import Animation from "./Animation.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 _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 _easeInOut;
function easeInOut() {
return _easeInOut || (_easeInOut = Easing.inOut(Easing.ease)), _easeInOut;
}
var TimingAnimation = /* @__PURE__ */function (Animation2) {
_inherits(TimingAnimation2, Animation2);
function TimingAnimation2(config) {
_class_call_check(this, TimingAnimation2);
var _this, _config$easing, _config$duration, _config$delay, _config$iterations, _config$isInteraction;
return _this = _call_super(this, TimingAnimation2), _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 = shouldUseNativeDriver(config), _this._platformConfig = config.platformConfig, _this.__isInteraction = (_config$isInteraction = config.isInteraction) !== null && _config$isInteraction !== void 0 ? _config$isInteraction : !_this._useNativeDriver, _this;
}
return _create_class(TimingAnimation2, [{
key: "__getNativeAnimationConfig",
value: function () {
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
};
}
}, {
key: "start",
value: function (fromValue, onUpdate, onEnd, previousAnimation, animatedValue) {
var _this = this;
this.__active = !0, this._fromValue = fromValue, this._onUpdate = onUpdate, this.__onEnd = onEnd;
var start2 = function () {
_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(start2, this._delay) : start2();
}
}, {
key: "onUpdate",
value: function () {
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)));
}
}, {
key: "stop",
value: function () {
_get(_get_prototype_of(TimingAnimation2.prototype), "stop", this).call(this), this.__active = !1, clearTimeout(this._timeout), global.cancelAnimationFrame(this._animationFrame), this.__debouncedOnEnd({
finished: !1
});
}
}]), TimingAnimation2;
}(_wrap_native_super(Animation)),
TimingAnimation_default = TimingAnimation;
export { TimingAnimation_default as default };
//# sourceMappingURL=TimingAnimation.native.js.map