ui.scroll_view.native.slide_down.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * DevExtreme (ui/scroll_view/ui.scroll_view.native.slide_down.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 Callbacks = require("../../core/utils/callbacks");
  11. var NativeStrategy = require("./ui.scrollable.native");
  12. var Deferred = require("../../core/utils/deferred").Deferred;
  13. var STATE_RELEASED = 0;
  14. var STATE_READY = 1;
  15. var STATE_LOADING = 2;
  16. var LOADING_HEIGHT = 80;
  17. var SlideDownNativeScrollViewStrategy = NativeStrategy.inherit({
  18. _init: function(scrollView) {
  19. this.callBase(scrollView);
  20. this._$topPocket = scrollView._$topPocket;
  21. this._$bottomPocket = scrollView._$bottomPocket;
  22. this._initCallbacks()
  23. },
  24. _initCallbacks: function() {
  25. this.pullDownCallbacks = Callbacks();
  26. this.releaseCallbacks = Callbacks();
  27. this.reachBottomCallbacks = Callbacks()
  28. },
  29. render: function() {
  30. this.callBase();
  31. this._renderPullDown();
  32. this._renderBottom();
  33. this._releaseState();
  34. this._updateDimensions()
  35. },
  36. _renderPullDown: function() {
  37. this._$topPocket.empty()
  38. },
  39. _renderBottom: function() {
  40. this._$bottomPocket.empty().append("<progress>")
  41. },
  42. _releaseState: function() {
  43. if (this._state === STATE_RELEASED) {
  44. return
  45. }
  46. this._state = STATE_RELEASED
  47. },
  48. _updateDimensions: function() {
  49. this._scrollOffset = this._$container.prop("scrollHeight") - this._$container.prop("clientHeight");
  50. this._containerSize = {
  51. height: this._$container.prop("clientHeight"),
  52. width: this._$container.prop("clientWidth")
  53. };
  54. this._contentSize = this._componentContentSize = {
  55. height: this._$container.prop("scrollHeight"),
  56. width: this._$container.prop("scrollWidth")
  57. }
  58. },
  59. handleScroll: function(e) {
  60. this.callBase(e);
  61. if (this._isReachBottom(this._lastLocation.top)) {
  62. this._reachBottom()
  63. }
  64. },
  65. _isReachBottom: function(location) {
  66. this._scrollContent = this._$container.prop("scrollHeight") - this._$container.prop("clientHeight");
  67. return this._reachBottomEnabled && location < -this._scrollContent + LOADING_HEIGHT
  68. },
  69. _reachBottom: function() {
  70. if (this._state === STATE_LOADING) {
  71. return
  72. }
  73. this._state = STATE_LOADING;
  74. this.reachBottomCallbacks.fire()
  75. },
  76. pullDownEnable: function(enabled) {
  77. this._pullDownEnabled = enabled
  78. },
  79. reachBottomEnable: function(enabled) {
  80. this._reachBottomEnabled = enabled;
  81. this._$bottomPocket.toggle(enabled)
  82. },
  83. pendingRelease: function() {
  84. this._state = STATE_READY
  85. },
  86. release: function() {
  87. var deferred = new Deferred;
  88. this._state = STATE_RELEASED;
  89. this.releaseCallbacks.fire();
  90. this.update();
  91. return deferred.resolve().promise()
  92. }
  93. });
  94. module.exports = SlideDownNativeScrollViewStrategy;