UNPKG

@kirz/react-native-toolkit

Version:

Toolkit to speed up React Native development

63 lines 3.68 kB
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); } import { Easing, cancelAnimation, runOnJS, withDelay, withSequence, withTiming } from 'react-native-reanimated'; import { PromiseUtils } from './promise/utils'; export 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; cancelAnimation(this.progress); const onFinish = (_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.onFinish; this.progress.value = withSequence(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) ?? Easing.linear }), withDelay(((_this$options5 = this.options) === null || _this$options5 === void 0 ? void 0 : _this$options5.delay) ?? 0, withTiming(this.endValue, { duration: this.duration, easing: ((_this$options6 = this.options) === null || _this$options6 === void 0 ? void 0 : _this$options6.easing) ?? Easing.linear }, isFinished => { if (!isFinished) { return; } if (onFinish) { 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; 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 = 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) ?? Easing.linear }, isFinished => { if (!isFinished) { return; } if (onReset) { runOnJS(onReset)(); } }); await PromiseUtils.wait(resetDuration); } pause() { cancelAnimation(this.progress); } stop() { cancelAnimation(this.progress); this.progress.value = this.startValue; } } //# sourceMappingURL=AutoplayAction.js.map