animator.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * DevExtreme (ui/scroll_view/animator.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var noop = require("../../core/utils/common").noop;
  11. var Class = require("../../core/class");
  12. var abstract = Class.abstract;
  13. var animationFrame = require("../../animation/frame");
  14. var Animator = Class.inherit({
  15. ctor: function() {
  16. this._finished = true;
  17. this._stopped = false;
  18. this._proxiedStepCore = this._stepCore.bind(this)
  19. },
  20. start: function() {
  21. this._stopped = false;
  22. this._finished = false;
  23. this._stepCore()
  24. },
  25. stop: function() {
  26. this._stopped = true;
  27. animationFrame.cancelAnimationFrame(this._stepAnimationFrame)
  28. },
  29. _stepCore: function() {
  30. if (this._isStopped()) {
  31. this._stop();
  32. return
  33. }
  34. if (this._isFinished()) {
  35. this._finished = true;
  36. this._complete();
  37. return
  38. }
  39. this._step();
  40. this._stepAnimationFrame = animationFrame.requestAnimationFrame(this._proxiedStepCore)
  41. },
  42. _step: abstract,
  43. _isFinished: noop,
  44. _stop: noop,
  45. _complete: noop,
  46. _isStopped: function() {
  47. return this._stopped
  48. },
  49. inProgress: function() {
  50. return !(this._stopped || this._finished)
  51. }
  52. });
  53. module.exports = Animator;