UNPKG

muban-transition-component

Version:

Javascript transitions for Muban components

114 lines (90 loc) 3.53 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports.default = void 0; var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")); var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")); var _EventDispatcher = _interopRequireDefault(require("seng-event/lib/EventDispatcher")); _EventDispatcher.default; function mubanTransitionMixin(Base) { return ( /*#__PURE__*/ function (_Base) { (0, _inheritsLoose2.default)(MubanTransitionMixin, _Base); function MubanTransitionMixin() { var _this; for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _Base.call.apply(_Base, [this].concat(args)) || this; Object.defineProperty((0, _assertThisInitialized2.default)(_this), "transitionController", { configurable: true, enumerable: true, writable: true, value: void 0 }); Object.defineProperty((0, _assertThisInitialized2.default)(_this), "enterViewThreshold", { configurable: true, enumerable: true, writable: true, value: 0.25 }); Object.defineProperty((0, _assertThisInitialized2.default)(_this), "inViewProgressThreshold", { configurable: true, enumerable: true, writable: true, value: 0 }); Object.defineProperty((0, _assertThisInitialized2.default)(_this), "hasEntered", { configurable: true, enumerable: true, writable: true, value: false }); Object.defineProperty((0, _assertThisInitialized2.default)(_this), "currentViewProgress", { configurable: true, enumerable: true, writable: true, value: 0 }); return _this; } var _proto = MubanTransitionMixin.prototype; _proto.enterView = function enterView() { this.transitionIn(); this.startLoopingAnimation(); }; _proto.leaveView = function leaveView() { this.stopLoopingAnimation(); }; // @ts-ignore _proto.inViewProgress = function inViewProgress(progress) {}; _proto.beyondView = function beyondView() { if (!this.hasEntered) { // Todo maybe seek to progress(1) to avoid (unnecessary) performance issue's this.transitionIn(); } }; _proto.transitionIn = function transitionIn(forceTransition) { if (forceTransition === void 0) { forceTransition = false; } return this.transitionController.transitionIn(forceTransition); }; _proto.transitionOut = function transitionOut(forceTransition, id, reset) { if (forceTransition === void 0) { forceTransition = false; } return this.transitionController.transitionOut(forceTransition, id, reset); }; _proto.startLoopingAnimation = function startLoopingAnimation(id, reset) { this.transitionController.startLoopingAnimation(id, reset); }; _proto.stopLoopingAnimation = function stopLoopingAnimation() { this.transitionController.stopLoopingAnimation(); }; return MubanTransitionMixin; }(Base) ); } var _default = mubanTransitionMixin; exports.default = _default;