UNPKG

@kirz/react-native-toolkit

Version:

Toolkit to speed up React Native development

70 lines (69 loc) 4.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AutoplayAction = void 0; var _reactNativeReanimated = require("react-native-reanimated"); var _utils = require("./promise/utils"); function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } class AutoplayAction { constructor(progress, duration, options) { this.progress = progress; this.duration = duration; this.options = options; _defineProperty(this, "startValue", 0); _defineProperty(this, "endValue", 1); } async start(start, end) { var _this$options, _this$options2, _this$options3, _this$options4, _this$options5, _this$options6; this.startValue = start ?? 0; this.endValue = end ?? this.startValue + 1; (0, _reactNativeReanimated.cancelAnimation)(this.progress); const onFinish = (_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.onFinish; this.progress.value = (0, _reactNativeReanimated.withSequence)((0, _reactNativeReanimated.withTiming)(this.startValue, { duration: ((_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2.resetDuration) ?? 200, easing: ((_this$options3 = this.options) === null || _this$options3 === void 0 ? void 0 : _this$options3.resetEasing) ?? ((_this$options4 = this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.easing) ?? _reactNativeReanimated.Easing.linear }), (0, _reactNativeReanimated.withDelay)(((_this$options5 = this.options) === null || _this$options5 === void 0 ? void 0 : _this$options5.delay) ?? 0, (0, _reactNativeReanimated.withTiming)(this.endValue, { duration: this.duration, easing: ((_this$options6 = this.options) === null || _this$options6 === void 0 ? void 0 : _this$options6.easing) ?? _reactNativeReanimated.Easing.linear }, isFinished => { if (!isFinished) { return; } if (onFinish) { (0, _reactNativeReanimated.runOnJS)(onFinish)(); } }))); } async reset(start, end) { var _this$options7, _this$options8, _this$options9, _this$options10; this.startValue = start ?? this.startValue; this.endValue = end ?? this.endValue ?? this.startValue + 1; (0, _reactNativeReanimated.cancelAnimation)(this.progress); const onReset = (_this$options7 = this.options) === null || _this$options7 === void 0 ? void 0 : _this$options7.onReset; const resetDuration = ((_this$options8 = this.options) === null || _this$options8 === void 0 ? void 0 : _this$options8.resetDuration) ?? 200; this.progress.value = (0, _reactNativeReanimated.withTiming)(this.startValue, { duration: resetDuration, easing: ((_this$options9 = this.options) === null || _this$options9 === void 0 ? void 0 : _this$options9.resetEasing) ?? ((_this$options10 = this.options) === null || _this$options10 === void 0 ? void 0 : _this$options10.easing) ?? _reactNativeReanimated.Easing.linear }, isFinished => { if (!isFinished) { return; } if (onReset) { (0, _reactNativeReanimated.runOnJS)(onReset)(); } }); await _utils.PromiseUtils.wait(resetDuration); } pause() { (0, _reactNativeReanimated.cancelAnimation)(this.progress); } stop() { (0, _reactNativeReanimated.cancelAnimation)(this.progress); this.progress.value = this.startValue; } } exports.AutoplayAction = AutoplayAction; //# sourceMappingURL=AutoplayAction.js.map