virtual-scroller 1.7.6 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -1
- package/README.md +139 -33
- package/babel.config.js +25 -0
- package/babel.js +5 -0
- package/bundle/index-bypass.html +1 -1
- package/bundle/index-dom.html +1 -1
- package/bundle/index-grid.html +1 -2
- package/bundle/index-scrollableContainer.html +1 -1
- package/bundle/index-tbody-scrollableContainer.html +2 -0
- package/bundle/index-tbody.html +2 -0
- package/bundle/virtual-scroller-dom.js +1 -1
- package/bundle/virtual-scroller-dom.js.map +1 -1
- package/bundle/virtual-scroller-react.js +1 -1
- package/bundle/virtual-scroller-react.js.map +1 -1
- package/bundle/virtual-scroller.js +1 -1
- package/bundle/virtual-scroller.js.map +1 -1
- package/commonjs/BeforeResize.js +319 -0
- package/commonjs/BeforeResize.js.map +1 -0
- package/commonjs/DOM/Engine.js +46 -0
- package/commonjs/DOM/Engine.js.map +1 -0
- package/commonjs/DOM/ItemsContainer.js +78 -0
- package/commonjs/DOM/ItemsContainer.js.map +1 -0
- package/commonjs/DOM/{WaitForStylesToLoad.js → ListTopOffsetWatcher.js} +56 -35
- package/commonjs/DOM/ListTopOffsetWatcher.js.map +1 -0
- package/commonjs/DOM/ScrollableContainer.js +56 -81
- package/commonjs/DOM/ScrollableContainer.js.map +1 -1
- package/commonjs/DOM/VirtualScroller.js +20 -15
- package/commonjs/DOM/VirtualScroller.js.map +1 -1
- package/commonjs/DOM/tbody.js +2 -2
- package/commonjs/ItemHeights.js +13 -20
- package/commonjs/ItemHeights.js.map +1 -1
- package/commonjs/Layout.js +588 -215
- package/commonjs/Layout.js.map +1 -1
- package/commonjs/Layout.test.js +191 -0
- package/commonjs/Layout.test.js.map +1 -0
- package/commonjs/ListHeightChangeWatcher.js +126 -0
- package/commonjs/ListHeightChangeWatcher.js.map +1 -0
- package/commonjs/Resize.js +22 -21
- package/commonjs/Resize.js.map +1 -1
- package/commonjs/Scroll.js +148 -88
- package/commonjs/Scroll.js.map +1 -1
- package/commonjs/VirtualScroller.js +1269 -390
- package/commonjs/VirtualScroller.js.map +1 -1
- package/commonjs/getItemCoordinates.js.map +1 -1
- package/commonjs/getItemsDiff.js.map +1 -1
- package/commonjs/getVerticalSpacing.js +8 -8
- package/commonjs/getVerticalSpacing.js.map +1 -1
- package/commonjs/react/VirtualScroller.js +31 -37
- package/commonjs/react/VirtualScroller.js.map +1 -1
- package/commonjs/utility/debounce.js +26 -4
- package/commonjs/utility/debounce.js.map +1 -1
- package/commonjs/utility/debug.js +51 -12
- package/commonjs/utility/debug.js.map +1 -1
- package/commonjs/utility/getStateSnapshot.js +50 -0
- package/commonjs/utility/getStateSnapshot.js.map +1 -0
- package/commonjs/utility/px.js +1 -1
- package/commonjs/utility/px.js.map +1 -1
- package/commonjs/utility/px.test.js +14 -0
- package/commonjs/utility/px.test.js.map +1 -0
- package/commonjs/utility/shallowEqual.js +1 -1
- package/commonjs/utility/shallowEqual.js.map +1 -1
- package/commonjs/utility/throttle.js.map +1 -1
- package/dom/index.d.ts +23 -0
- package/index.d.ts +84 -0
- package/modules/BeforeResize.js +310 -0
- package/modules/BeforeResize.js.map +1 -0
- package/modules/DOM/Engine.js +27 -0
- package/modules/DOM/Engine.js.map +1 -0
- package/modules/DOM/ItemsContainer.js +71 -0
- package/modules/DOM/ItemsContainer.js.map +1 -0
- package/modules/DOM/{WaitForStylesToLoad.js → ListTopOffsetWatcher.js} +57 -35
- package/modules/DOM/ListTopOffsetWatcher.js.map +1 -0
- package/modules/DOM/ScrollableContainer.js +55 -80
- package/modules/DOM/ScrollableContainer.js.map +1 -1
- package/modules/DOM/VirtualScroller.js +15 -14
- package/modules/DOM/VirtualScroller.js.map +1 -1
- package/modules/ItemHeights.js +8 -19
- package/modules/ItemHeights.js.map +1 -1
- package/modules/Layout.js +582 -213
- package/modules/Layout.js.map +1 -1
- package/modules/Layout.test.js +185 -0
- package/modules/Layout.test.js.map +1 -0
- package/modules/ListHeightChangeWatcher.js +119 -0
- package/modules/ListHeightChangeWatcher.js.map +1 -0
- package/modules/Resize.js +21 -20
- package/modules/Resize.js.map +1 -1
- package/modules/Scroll.js +148 -87
- package/modules/Scroll.js.map +1 -1
- package/modules/VirtualScroller.js +1263 -390
- package/modules/VirtualScroller.js.map +1 -1
- package/modules/getItemCoordinates.js.map +1 -1
- package/modules/getItemsDiff.js.map +1 -1
- package/modules/getVerticalSpacing.js +8 -8
- package/modules/getVerticalSpacing.js.map +1 -1
- package/modules/react/VirtualScroller.js +31 -37
- package/modules/react/VirtualScroller.js.map +1 -1
- package/modules/utility/debounce.js +26 -4
- package/modules/utility/debounce.js.map +1 -1
- package/modules/utility/debug.js +47 -10
- package/modules/utility/debug.js.map +1 -1
- package/modules/utility/getStateSnapshot.js +43 -0
- package/modules/utility/getStateSnapshot.js.map +1 -0
- package/modules/utility/px.js +1 -1
- package/modules/utility/px.js.map +1 -1
- package/modules/utility/px.test.js +9 -0
- package/modules/utility/px.test.js.map +1 -0
- package/modules/utility/shallowEqual.js +1 -1
- package/modules/utility/shallowEqual.js.map +1 -1
- package/modules/utility/throttle.js.map +1 -1
- package/package.json +24 -22
- package/react/index.d.ts +27 -0
- package/source/BeforeResize.js +317 -0
- package/source/DOM/Engine.js +32 -0
- package/source/DOM/ItemsContainer.js +48 -0
- package/source/DOM/{WaitForStylesToLoad.js → ListTopOffsetWatcher.js} +48 -22
- package/source/DOM/ScrollableContainer.js +39 -56
- package/source/DOM/VirtualScroller.js +6 -7
- package/source/ItemHeights.js +10 -15
- package/source/Layout.js +626 -252
- package/source/Layout.test.js +171 -0
- package/source/ListHeightChangeWatcher.js +94 -0
- package/source/Resize.js +23 -15
- package/source/Scroll.js +139 -78
- package/source/VirtualScroller.js +1240 -286
- package/source/getVerticalSpacing.js +7 -7
- package/source/react/VirtualScroller.js +2 -18
- package/source/utility/debounce.js +20 -3
- package/source/utility/debug.js +34 -3
- package/source/utility/getStateSnapshot.js +36 -0
- package/source/utility/px.js +1 -1
- package/source/utility/px.test.js +9 -0
- package/website/index-bypass.html +195 -0
- package/website/index-grid.html +0 -1
- package/website/index-scrollableContainer.html +208 -0
- package/website/index-tbody-scrollableContainer.html +68 -0
- package/website/index-tbody.html +55 -0
- package/commonjs/DOM/RenderingEngine.js +0 -33
- package/commonjs/DOM/RenderingEngine.js.map +0 -1
- package/commonjs/DOM/Screen.js +0 -87
- package/commonjs/DOM/Screen.js.map +0 -1
- package/commonjs/DOM/WaitForStylesToLoad.js.map +0 -1
- package/commonjs/RestoreScroll.js +0 -118
- package/commonjs/RestoreScroll.js.map +0 -1
- package/modules/DOM/RenderingEngine.js +0 -19
- package/modules/DOM/RenderingEngine.js.map +0 -1
- package/modules/DOM/Screen.js +0 -80
- package/modules/DOM/Screen.js.map +0 -1
- package/modules/DOM/WaitForStylesToLoad.js.map +0 -1
- package/modules/RestoreScroll.js +0 -111
- package/modules/RestoreScroll.js.map +0 -1
- package/source/DOM/RenderingEngine.js +0 -22
- package/source/DOM/Screen.js +0 -51
- package/source/RestoreScroll.js +0 -86
package/modules/Resize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/Resize.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["../source/Resize.js"],"names":["debounce","log","Resize","bypass","scrollableContainer","onStart","onStop","onHeightChange","onWidthChange","onNoChange","isRendered","prevScrollableContainerWidth","scrollableContainerWidth","prevScrollableContainerHeight","scrollableContainerHeight","getWidth","getHeight","onResize","_onResize","SCROLLABLE_CONTAINER_RESIZE_DEBOUNCE_INTERVAL","scrollableContainerUnlistenResize","undefined"],"mappings":";;;;;;;;AAAA,OAAOA,QAAP,MAAqB,oBAArB;AACA,OAAOC,GAAP,MAAgB,iBAAhB;;IAEqBC,M;AACpB,wBAQG;AAAA;;AAAA,QAPFC,MAOE,QAPFA,MAOE;AAAA,QANFC,mBAME,QANFA,mBAME;AAAA,QALFC,OAKE,QALFA,OAKE;AAAA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EAAiB;AAChB;AACA;;AACD,WAAKO,UAAL,GAAkB,IAAlB;AACA,WAAKE,wBAAL,GAAgC,KAAKR,mBAAL,CAAyBW,QAAzB,EAAhC;AACA,WAAKD,yBAAL,GAAiC,KAAKV,mBAAL,CAAyBY,SAAzB,EAAjC;AACA,WAAKI,iCAAL,GAAyC,KAAKhB,mBAAL,CAAyBa,QAAzB,CAAkC,KAAKA,QAAvC,CAAzC;AACA;;;WAED,gBAAO;AACN,WAAKP,UAAL,GAAkB,KAAlB;;AACA,UAAI,KAAKU,iCAAT,EAA4C;AAC3C,aAAKA,iCAAL;AACA,aAAKA,iCAAL,GAAyCC,SAAzC;AACA;AACD;AAED;AACD;AACA;;;;;;;SA5CqBnB,M;AA4ErB,IAAMiB,6CAA6C,GAAG,GAAtD","sourcesContent":["import debounce from './utility/debounce'\r\nimport log from './utility/debug'\r\n\r\nexport default class Resize {\r\n\tconstructor({\r\n\t\tbypass,\r\n\t\tscrollableContainer,\r\n\t\tonStart,\r\n\t\tonStop,\r\n\t\tonHeightChange,\r\n\t\tonWidthChange,\r\n\t\tonNoChange\r\n\t}) {\r\n\t\tthis.bypass = bypass\r\n\t\tthis.scrollableContainer = scrollableContainer\r\n\r\n\t\tthis.onHeightChange = onHeightChange\r\n\t\tthis.onWidthChange = onWidthChange\r\n\t\tthis.onNoChange = onNoChange\r\n\r\n\t\tthis.onResize = debounce(\r\n\t\t\tthis._onResize,\r\n\t\t\tSCROLLABLE_CONTAINER_RESIZE_DEBOUNCE_INTERVAL,\r\n\t\t\t{ onStart, onStop }\r\n\t\t)\r\n\t}\r\n\r\n\tlisten() {\r\n\t\tif (this.bypass) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tthis.isRendered = true\r\n\t\tthis.scrollableContainerWidth = this.scrollableContainer.getWidth()\r\n\t\tthis.scrollableContainerHeight = this.scrollableContainer.getHeight()\r\n\t\tthis.scrollableContainerUnlistenResize = this.scrollableContainer.onResize(this.onResize)\r\n\t}\r\n\r\n\tstop() {\r\n\t\tthis.isRendered = false\r\n\t\tif (this.scrollableContainerUnlistenResize) {\r\n\t\t\tthis.scrollableContainerUnlistenResize()\r\n\t\t\tthis.scrollableContainerUnlistenResize = undefined\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * On scrollable container resize.\r\n\t */\r\n\t_onResize = () => {\r\n\t\t// If `VirtualScroller` has been unmounted\r\n\t\t// while `debounce()`'s `setTimeout()` was waiting, then exit.\r\n\t\tif (!this.isRendered) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tconst prevScrollableContainerWidth = this.scrollableContainerWidth\r\n\t\tconst prevScrollableContainerHeight = this.scrollableContainerHeight\r\n\t\tthis.scrollableContainerWidth = this.scrollableContainer.getWidth()\r\n\t\tthis.scrollableContainerHeight = this.scrollableContainer.getHeight()\r\n\t\tif (this.scrollableContainerWidth === prevScrollableContainerWidth) {\r\n\t\t\tif (this.scrollableContainerHeight === prevScrollableContainerHeight) {\r\n\t\t\t\t// The dimensions of the container didn't change,\r\n\t\t\t\t// so there's no need to re-layout anything.\r\n\t\t\t\tthis.onNoChange()\r\n\t\t\t} else {\r\n\t\t\t\t// Scrollable container height has changed,\r\n\t\t\t\t// so just recalculate shown item indexes.\r\n\t\t\t\t// No need to perform a re-layout from scratch.\r\n\t\t\t\tthis.onHeightChange(prevScrollableContainerHeight, this.scrollableContainerHeight)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\t// Reset item heights, because if scrollable container's width (or height)\r\n\t\t\t// has changed, then the list width (or height) most likely also has changed,\r\n\t\t\t// and also some CSS `@media()` rules might have been added or removed.\r\n\t\t\t// So re-render the list entirely.\r\n\t\t\tthis.onWidthChange(prevScrollableContainerWidth, this.scrollableContainerWidth)\r\n\t\t}\r\n\t}\r\n}\r\n\r\nconst SCROLLABLE_CONTAINER_RESIZE_DEBOUNCE_INTERVAL = 250"],"file":"Resize.js"}
|
package/modules/Scroll.js
CHANGED
|
@@ -11,103 +11,122 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
11
11
|
// Replacing `setTimeout()` with `requestAnimationFrame()` can work around that Chrome bug.
|
|
12
12
|
// https://github.com/bvaughn/react-virtualized/issues/722
|
|
13
13
|
import { setTimeout, clearTimeout } from 'request-animation-frame-timeout';
|
|
14
|
-
import { LAYOUT_REASON } from './Layout';
|
|
15
14
|
import log from './utility/debug';
|
|
16
15
|
|
|
17
|
-
var Scroll =
|
|
18
|
-
/*#__PURE__*/
|
|
19
|
-
function () {
|
|
16
|
+
var Scroll = /*#__PURE__*/function () {
|
|
20
17
|
function Scroll(_ref) {
|
|
21
18
|
var _this = this;
|
|
22
19
|
|
|
23
20
|
var bypass = _ref.bypass,
|
|
24
21
|
scrollableContainer = _ref.scrollableContainer,
|
|
25
|
-
|
|
22
|
+
itemsContainer = _ref.itemsContainer,
|
|
23
|
+
onScroll = _ref.onScroll,
|
|
26
24
|
initialScrollPosition = _ref.initialScrollPosition,
|
|
27
25
|
onScrollPositionChange = _ref.onScrollPositionChange,
|
|
28
26
|
isImmediateLayoutScheduled = _ref.isImmediateLayoutScheduled,
|
|
29
27
|
hasNonRenderedItemsAtTheTop = _ref.hasNonRenderedItemsAtTheTop,
|
|
30
28
|
hasNonRenderedItemsAtTheBottom = _ref.hasNonRenderedItemsAtTheBottom,
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
getLatestLayoutVisibleArea = _ref.getLatestLayoutVisibleArea,
|
|
30
|
+
getListTopOffset = _ref.getListTopOffset,
|
|
31
|
+
getPrerenderMargin = _ref.getPrerenderMargin,
|
|
32
|
+
onScrolledToTop = _ref.onScrolledToTop,
|
|
33
|
+
waitForScrollingToStop = _ref.waitForScrollingToStop;
|
|
33
34
|
|
|
34
35
|
_classCallCheck(this, Scroll);
|
|
35
36
|
|
|
36
|
-
_defineProperty(this, "
|
|
37
|
-
_this.
|
|
37
|
+
_defineProperty(this, "scrollByY", function (scrollByY) {
|
|
38
|
+
_this.scrollToY(_this.getScrollY() + scrollByY);
|
|
38
39
|
});
|
|
39
40
|
|
|
40
|
-
_defineProperty(this, "
|
|
41
|
-
|
|
41
|
+
_defineProperty(this, "onScrollListener", function () {
|
|
42
|
+
if (_this.onScrollPositionChange) {
|
|
43
|
+
_this.onScrollPositionChange(_this.getScrollY());
|
|
44
|
+
} // If the user has scrolled up to the top of the items container.
|
|
45
|
+
// (this option isn't currently used)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if (_this.onScrolledToTop) {
|
|
49
|
+
if (_this.getScrollY() < _this.getListTopOffset()) {
|
|
50
|
+
_this.onScrolledToTop();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (_this.bypass) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (_this.ignoreScrollEvents) {
|
|
59
|
+
return;
|
|
60
|
+
} // Prefer not performing a re-layout while the user is scrolling (if possible).
|
|
42
61
|
// If the user doesn't scroll too far and then stops for a moment,
|
|
43
62
|
// then a mid-scroll re-layout could be delayed until such a brief stop:
|
|
44
63
|
// presumably, this results in better (smoother) scrolling performance,
|
|
45
64
|
// delaying the work to when it doesn't introduce any stutter or "jank".
|
|
46
|
-
// Reset `this.
|
|
47
|
-
|
|
48
|
-
|
|
65
|
+
// Reset `this.onStopScrollingTimer` (will be re-created below).
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
_this.cancelOnStopScrollingTimer(); // See if the latest "layout" (the currently rendered set of items)
|
|
69
|
+
// is still sufficient in order to show all the items that're
|
|
70
|
+
// currently inside the viewport. If there're some non-rendered items
|
|
71
|
+
// that're visible in the current viewport, then those items
|
|
72
|
+
// should be rendered "immediately" rather than waiting until
|
|
73
|
+
// the user stops scrolling.
|
|
49
74
|
|
|
50
75
|
|
|
51
76
|
var forceUpdate = // If the items have been rendered at least once
|
|
52
|
-
_this.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
77
|
+
_this.getLatestLayoutVisibleArea() && ( // If the user has scrolled up past the "prerender margin"
|
|
78
|
+
// and there're some non-rendered items at the top,
|
|
79
|
+
// then force a re-layout.
|
|
80
|
+
//
|
|
81
|
+
// (during these calculations we assume that the list's top coordinate
|
|
82
|
+
// hasn't changed since previous layout; even if that's not exactly true,
|
|
83
|
+
// the items will be re-layout when the user stops scrolling anyway)
|
|
84
|
+
//
|
|
85
|
+
_this.getScrollY() < _this.getLatestLayoutVisibleArea().top - _this.getPrerenderMargin() && _this.hasNonRenderedItemsAtTheTop() || // If the user has scrolled down past the "prerender margin"
|
|
86
|
+
// and there're any non-rendered items left at the end,
|
|
87
|
+
// then force a re-layout.
|
|
88
|
+
//
|
|
89
|
+
// (during these calculations we assume that the list's top coordinate
|
|
90
|
+
// hasn't changed since previous layout; even if that's not exactly true,
|
|
91
|
+
// the items will be re-layout when the user stops scrolling anyway)
|
|
92
|
+
//
|
|
93
|
+
_this.getScrollY() + _this.scrollableContainer.getHeight() > _this.getLatestLayoutVisibleArea().bottom + _this.getPrerenderMargin() && _this.hasNonRenderedItemsAtTheBottom());
|
|
57
94
|
|
|
58
95
|
if (forceUpdate) {
|
|
59
|
-
log('The user has scrolled far enough:
|
|
96
|
+
log('The user has scrolled far enough: perform a re-layout');
|
|
60
97
|
} else {
|
|
61
|
-
log('The user
|
|
98
|
+
log('The user is scrolling: perform a re-layout when they stop scrolling');
|
|
62
99
|
}
|
|
63
100
|
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
101
|
+
if (forceUpdate || _this.waitForScrollingToStop === false) {
|
|
102
|
+
return _this.onScroll();
|
|
103
|
+
} // If a re-layout is already scheduled at the next "frame",
|
|
104
|
+
// don't schedule a "re-layout when user stops scrolling" timer.
|
|
70
105
|
|
|
71
|
-
_this.onUserStopsScrollingTimer = setTimeout(function () {
|
|
72
|
-
_this.onUserStopsScrollingTimer = undefined;
|
|
73
106
|
|
|
74
|
-
|
|
75
|
-
reason: LAYOUT_REASON.STOPPED_SCROLLING
|
|
76
|
-
});
|
|
77
|
-
}, // "scroll" events are usually dispatched every 16 milliseconds
|
|
78
|
-
// for 60fps refresh rate, so waiting for 100 milliseconds feels
|
|
79
|
-
// reasonable: that would be about 6 frames of inactivity period,
|
|
80
|
-
// which could mean that either the user has stopped scrolling
|
|
81
|
-
// (for a moment) or the browser is lagging and stuttering
|
|
82
|
-
// (skipping frames due to high load).
|
|
83
|
-
// If the user continues scrolling then this timeout is constantly
|
|
84
|
-
// refreshed (cancelled and then re-created).
|
|
85
|
-
WAIT_FOR_USER_TO_STOP_SCROLLING_TIMEOUT);
|
|
107
|
+
if (_this.isImmediateLayoutScheduled()) {
|
|
86
108
|
return;
|
|
87
109
|
}
|
|
88
110
|
|
|
89
|
-
_this.
|
|
90
|
-
|
|
91
|
-
|
|
111
|
+
_this.onScrollOnStopScrolling = true;
|
|
112
|
+
|
|
113
|
+
_this.watchOnStopScrolling();
|
|
92
114
|
});
|
|
93
115
|
|
|
94
116
|
this.bypass = bypass;
|
|
95
117
|
this.scrollableContainer = scrollableContainer;
|
|
96
|
-
this.
|
|
118
|
+
this.itemsContainer = itemsContainer;
|
|
119
|
+
this.onScroll = onScroll;
|
|
97
120
|
this.initialScrollPosition = initialScrollPosition;
|
|
98
121
|
this.onScrollPositionChange = onScrollPositionChange;
|
|
99
122
|
this.isImmediateLayoutScheduled = isImmediateLayoutScheduled;
|
|
100
123
|
this.hasNonRenderedItemsAtTheTop = hasNonRenderedItemsAtTheTop;
|
|
101
124
|
this.hasNonRenderedItemsAtTheBottom = hasNonRenderedItemsAtTheBottom;
|
|
102
|
-
this.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
scrollableContainerContentHeight: scrollableContainer.getContentHeight()
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
}
|
|
125
|
+
this.getLatestLayoutVisibleArea = getLatestLayoutVisibleArea;
|
|
126
|
+
this.getListTopOffset = getListTopOffset;
|
|
127
|
+
this.getPrerenderMargin = getPrerenderMargin;
|
|
128
|
+
this.onScrolledToTop = onScrolledToTop;
|
|
129
|
+
this.waitForScrollingToStop = waitForScrollingToStop;
|
|
111
130
|
}
|
|
112
131
|
|
|
113
132
|
_createClass(Scroll, [{
|
|
@@ -118,71 +137,113 @@ function () {
|
|
|
118
137
|
}
|
|
119
138
|
|
|
120
139
|
if (this.onScrollPositionChange) {
|
|
121
|
-
this.
|
|
122
|
-
this.removeScrollPositionListener = this.scrollableContainer.addScrollListener(this.updateScrollPosition);
|
|
140
|
+
this.onScrollPositionChange(this.getScrollY());
|
|
123
141
|
}
|
|
124
142
|
|
|
125
|
-
|
|
126
|
-
this.removeScrollListener = this.scrollableContainer.addScrollListener(this.onScroll);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (this.preserveScrollPositionOfTheBottomOfTheListOnMount) {
|
|
130
|
-
this.scrollToY(this.getScrollY() + (this.scrollableContainer.getContentHeight() - this.preserveScrollPositionOfTheBottomOfTheListOnMount.scrollableContainerContentHeight));
|
|
131
|
-
}
|
|
143
|
+
this.stopListeningToScroll = this.scrollableContainer.onScroll(this.onScrollListener);
|
|
132
144
|
}
|
|
133
145
|
}, {
|
|
134
146
|
key: "stop",
|
|
135
147
|
value: function stop() {
|
|
136
|
-
if (this.
|
|
137
|
-
this.
|
|
148
|
+
if (this.stopReportingScrollPositionChange) {
|
|
149
|
+
this.stopReportingScrollPositionChange();
|
|
150
|
+
this.stopReportingScrollPositionChange = undefined;
|
|
138
151
|
}
|
|
139
152
|
|
|
140
|
-
if (this.
|
|
141
|
-
this.
|
|
153
|
+
if (this.stopListeningToScroll) {
|
|
154
|
+
this.stopListeningToScroll();
|
|
155
|
+
this.stopListeningToScroll = undefined;
|
|
142
156
|
}
|
|
143
157
|
|
|
144
|
-
this.
|
|
158
|
+
if (this.onStopScrollingListener) {
|
|
159
|
+
this.onStopScrollingListener = undefined;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (this.onScrollOnStopScrolling) {
|
|
163
|
+
this.onScrollOnStopScrolling = undefined;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
this.cancelOnStopScrollingTimer();
|
|
145
167
|
}
|
|
146
168
|
}, {
|
|
147
169
|
key: "scrollToY",
|
|
148
170
|
value: function scrollToY(scrollY) {
|
|
171
|
+
this.ignoreScrollEvents = true;
|
|
149
172
|
this.scrollableContainer.scrollToY(scrollY);
|
|
150
|
-
|
|
151
|
-
}, {
|
|
152
|
-
key: "scrollByY",
|
|
153
|
-
value: function scrollByY(_scrollByY) {
|
|
154
|
-
this.scrollToY(this.getScrollY() + _scrollByY);
|
|
173
|
+
this.ignoreScrollEvents = undefined;
|
|
155
174
|
}
|
|
156
175
|
}, {
|
|
157
176
|
key: "getScrollY",
|
|
158
177
|
value: function getScrollY() {
|
|
159
178
|
return this.scrollableContainer.getScrollY();
|
|
160
179
|
}
|
|
161
|
-
/**
|
|
162
|
-
* Updates the current scroll Y position in state.
|
|
163
|
-
*/
|
|
164
|
-
|
|
165
180
|
}, {
|
|
166
|
-
key: "
|
|
167
|
-
value: function
|
|
168
|
-
if (this.
|
|
169
|
-
clearTimeout(this.
|
|
170
|
-
this.
|
|
181
|
+
key: "cancelOnStopScrollingTimer",
|
|
182
|
+
value: function cancelOnStopScrollingTimer() {
|
|
183
|
+
if (this.onStopScrollingTimer) {
|
|
184
|
+
clearTimeout(this.onStopScrollingTimer);
|
|
185
|
+
this.onStopScrollingTimer = undefined;
|
|
171
186
|
}
|
|
172
187
|
}
|
|
173
188
|
}, {
|
|
174
|
-
key: "
|
|
175
|
-
value: function
|
|
189
|
+
key: "cancelScheduledLayout",
|
|
190
|
+
value: function cancelScheduledLayout() {
|
|
176
191
|
// Cancel a "re-layout when user stops scrolling" timer.
|
|
177
|
-
this.
|
|
192
|
+
this.cancelOnStopScrollingTimer();
|
|
178
193
|
}
|
|
179
194
|
}, {
|
|
180
|
-
key: "
|
|
195
|
+
key: "watchOnStopScrolling",
|
|
196
|
+
value: function watchOnStopScrolling() {
|
|
197
|
+
var _this2 = this;
|
|
198
|
+
|
|
199
|
+
this.onStopScrollingTimer = setTimeout(function () {
|
|
200
|
+
_this2.onStopScrollingTimer = undefined;
|
|
201
|
+
|
|
202
|
+
if (_this2.onScrollOnStopScrolling) {
|
|
203
|
+
_this2.onScrollOnStopScrolling = undefined;
|
|
204
|
+
|
|
205
|
+
_this2.onScroll({
|
|
206
|
+
delayed: true
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (_this2.onStopScrollingListener) {
|
|
211
|
+
var onStopScrollingListener = _this2.onStopScrollingListener;
|
|
212
|
+
_this2.onStopScrollingListener = undefined; // `onStopScrollingListener()` may hypothetically schedule
|
|
213
|
+
// another `onStopScrolling()` listener, so set
|
|
214
|
+
// `this.onStopScrollingListener` to `undefined` before
|
|
215
|
+
// calling it rather than after.
|
|
216
|
+
|
|
217
|
+
log('~ The user has stopped scrolling ~');
|
|
218
|
+
onStopScrollingListener();
|
|
219
|
+
}
|
|
220
|
+
}, // "scroll" events are usually dispatched every 16 milliseconds
|
|
221
|
+
// for 60fps refresh rate, so waiting for 100 milliseconds feels
|
|
222
|
+
// reasonable: that would be about 6 frames of inactivity period,
|
|
223
|
+
// which could mean that either the user has stopped scrolling
|
|
224
|
+
// (for a moment) or the browser is lagging and stuttering
|
|
225
|
+
// (skipping frames due to high load).
|
|
226
|
+
// If the user continues scrolling then this timeout is constantly
|
|
227
|
+
// refreshed (cancelled and then re-created).
|
|
228
|
+
ON_STOP_SCROLLING_INACTIVE_PERIOD);
|
|
229
|
+
} // (this function isn't currently used)
|
|
230
|
+
|
|
231
|
+
}, {
|
|
232
|
+
key: "onStopScrolling",
|
|
233
|
+
value: function onStopScrolling(onStopScrollingListener) {
|
|
234
|
+
this.onStopScrollingListener = onStopScrollingListener;
|
|
181
235
|
|
|
236
|
+
if (!this.onStopScrollingTimer) {
|
|
237
|
+
this.watchOnStopScrolling();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
182
240
|
/**
|
|
183
241
|
* Returns visible area coordinates relative to the scrollable container.
|
|
184
242
|
* @return {object} `{ top: number, bottom: number }`
|
|
185
243
|
*/
|
|
244
|
+
|
|
245
|
+
}, {
|
|
246
|
+
key: "getVisibleAreaBounds",
|
|
186
247
|
value: function getVisibleAreaBounds() {
|
|
187
248
|
var scrollY = this.getScrollY();
|
|
188
249
|
return {
|
|
@@ -198,5 +259,5 @@ function () {
|
|
|
198
259
|
}();
|
|
199
260
|
|
|
200
261
|
export { Scroll as default };
|
|
201
|
-
var
|
|
262
|
+
var ON_STOP_SCROLLING_INACTIVE_PERIOD = 100;
|
|
202
263
|
//# sourceMappingURL=Scroll.js.map
|
package/modules/Scroll.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/Scroll.js"],"names":["setTimeout","clearTimeout","LAYOUT_REASON","log","Scroll","bypass","scrollableContainer","updateLayout","initialScrollPosition","onScrollPositionChange","isImmediateLayoutScheduled","hasNonRenderedItemsAtTheTop","hasNonRenderedItemsAtTheBottom","getLatestLayoutVisibleAreaIncludingMargins","preserveScrollPositionOfTheBottomOfTheListOnMount","getScrollY","cancelOnUserStopsScrollingTimer","forceUpdate","top","getHeight","bottom","onUserStopsScrollingTimer","undefined","reason","STOPPED_SCROLLING","WAIT_FOR_USER_TO_STOP_SCROLLING_TIMEOUT","SCROLL","scrollableContainerContentHeight","getContentHeight","scrollToY","updateScrollPosition","removeScrollPositionListener","addScrollListener","removeScrollListener","onScroll","scrollY","scrollByY"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA,SAASA,UAAT,EAAqBC,YAArB,QAAyC,iCAAzC;AAEA,SAASC,aAAT,QAA8B,UAA9B;AACA,OAAOC,GAAP,MAAgB,iBAAhB;;IAEqBC,M;;;AACpB,wBAWG;AAAA;;AAAA,QAVFC,MAUE,QAVFA,MAUE;AAAA,QATFC,mBASE,QATFA,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AKd,iDAAL,CAAuDa,gCAA1H,CAAf;AACA;AACD;;;2BAEM;AACN,UAAI,KAAKI,4BAAT,EAAuC;AACtC,aAAKA,4BAAL;AACA;;AACD,UAAI,KAAKE,oBAAT,EAA+B;AAC9B,aAAKA,oBAAL;AACA;;AACD,WAAKjB,+BAAL;AACA;;;8BAESmB,O,EAAS;AAClB,WAAK7B,mBAAL,CAAyBuB,SAAzB,CAAmCM,OAAnC;AACA;;;8BAESC,U,EAAW;AACpB,WAAKP,SAAL,CAAe,KAAKd,UAAL,KAAoBqB,UAAnC;AACA;;;iCAEY;AACZ,aAAO,KAAK9B,mBAAL,CAAyBS,UAAzB,EAAP;AACA;AAED;;;;;;sDAOkC;AACjC,UAAI,KAAKM,yBAAT,EAAoC;AACnCpB,QAAAA,YAAY,CAAC,KAAKoB,yBAAN,CAAZ;AACA,aAAKA,yBAAL,GAAiCC,SAAjC;AACA;AACD;;;+BAEU;AACV;AACA,WAAKN,+BAAL;AACA;;;;AAiED;;;;2CAIuB;AACtB,UAAMmB,OAAO,GAAG,KAAKpB,UAAL,EAAhB;AACA,aAAO;AACN;AACAG,QAAAA,GAAG,EAAEiB,OAFC;AAGN;AACAf,QAAAA,MAAM,EAAEe,OAAO,GAAG,KAAK7B,mBAAL,CAAyBa,SAAzB;AAJZ,OAAP;AAMA;;;;;;SApKmBf,M;AAuKrB,IAAMqB,uCAAuC,GAAG,GAAhD","sourcesContent":["// For some weird reason, in Chrome, `setTimeout()` would lag up to a second (or more) behind.\r\n// Turns out, Chrome developers have deprecated `setTimeout()` API entirely without asking anyone.\r\n// Replacing `setTimeout()` with `requestAnimationFrame()` can work around that Chrome bug.\r\n// https://github.com/bvaughn/react-virtualized/issues/722\r\nimport { setTimeout, clearTimeout } from 'request-animation-frame-timeout'\r\n\r\nimport { LAYOUT_REASON } from './Layout'\r\nimport log from './utility/debug'\r\n\r\nexport default class Scroll {\r\n\tconstructor({\r\n\t\tbypass,\r\n\t\tscrollableContainer,\r\n\t\tupdateLayout,\r\n\t\tinitialScrollPosition,\r\n\t\tonScrollPositionChange,\r\n\t\tisImmediateLayoutScheduled,\r\n\t\thasNonRenderedItemsAtTheTop,\r\n\t\thasNonRenderedItemsAtTheBottom,\r\n\t\tgetLatestLayoutVisibleAreaIncludingMargins,\r\n\t\tpreserveScrollPositionOfTheBottomOfTheListOnMount\r\n\t}) {\r\n\t\tthis.bypass = bypass\r\n\t\tthis.scrollableContainer = scrollableContainer\r\n\t\tthis.updateLayout = updateLayout\r\n\t\tthis.initialScrollPosition = initialScrollPosition\r\n\t\tthis.onScrollPositionChange = onScrollPositionChange\r\n\t\tthis.isImmediateLayoutScheduled = isImmediateLayoutScheduled\r\n\t\tthis.hasNonRenderedItemsAtTheTop = hasNonRenderedItemsAtTheTop\r\n\t\tthis.hasNonRenderedItemsAtTheBottom = hasNonRenderedItemsAtTheBottom\r\n\t\tthis.getLatestLayoutVisibleAreaIncludingMargins = getLatestLayoutVisibleAreaIncludingMargins\r\n\r\n\t\tif (preserveScrollPositionOfTheBottomOfTheListOnMount) {\r\n\t\t\tif (scrollableContainer) {\r\n\t\t\t\tthis.preserveScrollPositionOfTheBottomOfTheListOnMount = {\r\n\t\t\t\t\tscrollableContainerContentHeight: scrollableContainer.getContentHeight()\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tlisten() {\r\n\t\tif (this.initialScrollPosition !== undefined) {\r\n\t\t\tthis.scrollToY(this.initialScrollPosition)\r\n\t\t}\r\n\t\tif (this.onScrollPositionChange) {\r\n\t\t\tthis.updateScrollPosition()\r\n\t\t\tthis.removeScrollPositionListener = this.scrollableContainer.addScrollListener(this.updateScrollPosition)\r\n\t\t}\r\n\t\tif (!this.bypass) {\r\n\t\t\tthis.removeScrollListener = this.scrollableContainer.addScrollListener(this.onScroll)\r\n\t\t}\r\n\t\tif (this.preserveScrollPositionOfTheBottomOfTheListOnMount) {\r\n\t\t\tthis.scrollToY(this.getScrollY() + (this.scrollableContainer.getContentHeight() - this.preserveScrollPositionOfTheBottomOfTheListOnMount.scrollableContainerContentHeight))\r\n\t\t}\r\n\t}\r\n\r\n\tstop() {\r\n\t\tif (this.removeScrollPositionListener) {\r\n\t\t\tthis.removeScrollPositionListener()\r\n\t\t}\r\n\t\tif (this.removeScrollListener) {\r\n\t\t\tthis.removeScrollListener()\r\n\t\t}\r\n\t\tthis.cancelOnUserStopsScrollingTimer()\r\n\t}\r\n\r\n\tscrollToY(scrollY) {\r\n\t\tthis.scrollableContainer.scrollToY(scrollY)\r\n\t}\r\n\r\n\tscrollByY(scrollByY) {\r\n\t\tthis.scrollToY(this.getScrollY() + scrollByY)\r\n\t}\r\n\r\n\tgetScrollY() {\r\n\t\treturn this.scrollableContainer.getScrollY()\r\n\t}\r\n\r\n\t/**\r\n\t * Updates the current scroll Y position in state.\r\n\t */\r\n\tupdateScrollPosition = () => {\r\n\t\tthis.onScrollPositionChange(this.getScrollY())\r\n\t}\r\n\r\n\tcancelOnUserStopsScrollingTimer() {\r\n\t\tif (this.onUserStopsScrollingTimer) {\r\n\t\t\tclearTimeout(this.onUserStopsScrollingTimer)\r\n\t\t\tthis.onUserStopsScrollingTimer = undefined\r\n\t\t}\r\n\t}\r\n\r\n\tonLayout() {\r\n\t\t// Cancel a \"re-layout when user stops scrolling\" timer.\r\n\t\tthis.cancelOnUserStopsScrollingTimer()\r\n\t}\r\n\r\n\tonScroll = () => {\r\n\t\t// Prefer not performing a re-layout while the user is scrolling (if possible).\r\n\t\t// If the user doesn't scroll too far and then stops for a moment,\r\n\t\t// then a mid-scroll re-layout could be delayed until such a brief stop:\r\n\t\t// presumably, this results in better (smoother) scrolling performance,\r\n\t\t// delaying the work to when it doesn't introduce any stutter or \"jank\".\r\n\r\n\t\t// Reset `this.onUserStopsScrollingTimer` (will be re-created below).\r\n\t\tthis.cancelOnUserStopsScrollingTimer()\r\n\r\n\t\t// See whether rendering \"new\" previous/next items is required\r\n\t\t// right now, or it can wait until the user stops scrolling.\r\n\t\tconst forceUpdate =\r\n\t\t\t// If the items have been rendered at least once\r\n\t\t\tthis.getLatestLayoutVisibleAreaIncludingMargins() && (\r\n\t\t\t\t(\r\n\t\t\t\t\t// If the user has scrolled up past the extra \"margin\"\r\n\t\t\t\t\t(this.getScrollY() < this.getLatestLayoutVisibleAreaIncludingMargins().top) &&\r\n\t\t\t\t\t// and if there're any previous non-rendered items to render.\r\n\t\t\t\t\tthis.hasNonRenderedItemsAtTheTop()\r\n\t\t\t\t)\r\n\t\t\t\t||\r\n\t\t\t\t(\r\n\t\t\t\t\t// If the user has scrolled down past the extra \"margin\"\r\n\t\t\t\t\t(this.getScrollY() + this.scrollableContainer.getHeight() > this.getLatestLayoutVisibleAreaIncludingMargins().bottom) &&\r\n\t\t\t\t\t// and if there're any next non-rendered items to render.\r\n\t\t\t\t\tthis.hasNonRenderedItemsAtTheBottom()\r\n\t\t\t\t)\r\n\t\t\t)\r\n\r\n\t\tif (forceUpdate) {\r\n\t\t\tlog('The user has scrolled far enough: force re-layout')\r\n\t\t} else {\r\n\t\t\tlog('The user hasn\\'t scrolled too much: delay re-layout')\r\n\t\t}\r\n\r\n\t\tif (!forceUpdate) {\r\n\t\t\t// If a re-layout is already scheduled at the next \"frame\",\r\n\t\t\t// don't schedule a \"re-layout when user stops scrolling\" timer.\r\n\t\t\tif (this.isImmediateLayoutScheduled()) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t\tthis.onUserStopsScrollingTimer = setTimeout(\r\n\t\t\t\t() => {\r\n\t\t\t\t\tthis.onUserStopsScrollingTimer = undefined\r\n\t\t\t\t\tthis.updateLayout({ reason: LAYOUT_REASON.STOPPED_SCROLLING })\r\n\t\t\t\t},\r\n\t\t\t\t// \"scroll\" events are usually dispatched every 16 milliseconds\r\n\t\t\t\t// for 60fps refresh rate, so waiting for 100 milliseconds feels\r\n\t\t\t\t// reasonable: that would be about 6 frames of inactivity period,\r\n\t\t\t\t// which could mean that either the user has stopped scrolling\r\n\t\t\t\t// (for a moment) or the browser is lagging and stuttering\r\n\t\t\t\t// (skipping frames due to high load).\r\n\t\t\t\t// If the user continues scrolling then this timeout is constantly\r\n\t\t\t\t// refreshed (cancelled and then re-created).\r\n\t\t\t\tWAIT_FOR_USER_TO_STOP_SCROLLING_TIMEOUT\r\n\t\t\t)\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tthis.updateLayout({ reason: LAYOUT_REASON.SCROLL })\r\n\t}\r\n\r\n\t/**\r\n\t * Returns visible area coordinates relative to the scrollable container.\r\n\t * @return {object} `{ top: number, bottom: number }`\r\n\t */\r\n\tgetVisibleAreaBounds() {\r\n\t\tconst scrollY = this.getScrollY()\r\n\t\treturn {\r\n\t\t\t// The first pixel of the screen.\r\n\t\t\ttop: scrollY,\r\n\t\t\t// The pixel after the last pixel of the screen.\r\n\t\t\tbottom: scrollY + this.scrollableContainer.getHeight()\r\n\t\t}\r\n\t}\r\n}\r\n\r\nconst WAIT_FOR_USER_TO_STOP_SCROLLING_TIMEOUT = 100"],"file":"Scroll.js"}
|
|
1
|
+
{"version":3,"sources":["../source/Scroll.js"],"names":["setTimeout","clearTimeout","log","Scroll","bypass","scrollableContainer","itemsContainer","onScroll","initialScrollPosition","onScrollPositionChange","isImmediateLayoutScheduled","hasNonRenderedItemsAtTheTop","hasNonRenderedItemsAtTheBottom","getLatestLayoutVisibleArea","getListTopOffset","getPrerenderMargin","onScrolledToTop","waitForScrollingToStop","scrollByY","scrollToY","getScrollY","ignoreScrollEvents","cancelOnStopScrollingTimer","forceUpdate","top","getHeight","bottom","onScrollOnStopScrolling","watchOnStopScrolling","undefined","stopListeningToScroll","onScrollListener","stopReportingScrollPositionChange","onStopScrollingListener","scrollY","onStopScrollingTimer","delayed","ON_STOP_SCROLLING_INACTIVE_PERIOD"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA,SAASA,UAAT,EAAqBC,YAArB,QAAyC,iCAAzC;AAEA,OAAOC,GAAP,MAAgB,iBAAhB;;IAEqBC,M;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BN,SAA5B;;AAEA,YAAI,MAAI,CAACF,uBAAT,EAAkC;AACjC,UAAA,MAAI,CAACA,uBAAL,GAA+BE,SAA/B;;AACA,UAAA,MAAI,CAACtB,QAAL,CAAc;AAAE6B,YAAAA,OAAO,EAAE;AAAX,WAAd;AACA;;AAED,YAAI,MAAI,CAACH,uBAAT,EAAkC;AACjC,cAAMA,uBAAuB,GAAG,MAAI,CAACA,uBAArC;AACA,UAAA,MAAI,CAACA,uBAAL,GAA+BJ,SAA/B,CAFiC,CAGjC;AACA;AACA;AACA;;AACA3B,UAAAA,GAAG,CAAC,oCAAD,CAAH;AACA+B,UAAAA,uBAAuB;AACvB;AACD,OAnBoC,EAoBrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACAI,MAAAA,iCA5BqC,CAAtC;AA8BA,K,CAED;;;;WACA,yBAAgBJ,uBAAhB,EAAyC;AACxC,WAAKA,uBAAL,GAA+BA,uBAA/B;;AACA,UAAI,CAAC,KAAKE,oBAAV,EAAgC;AAC/B,aAAKP,oBAAL;AACA;AACD;AAED;AACD;AACA;AACA;;;;WACC,gCAAuB;AACtB,UAAMM,OAAO,GAAG,KAAKd,UAAL,EAAhB;AACA,aAAO;AACN;AACAI,QAAAA,GAAG,EAAEU,OAFC;AAGN;AACAR,QAAAA,MAAM,EAAEQ,OAAO,GAAG,KAAK7B,mBAAL,CAAyBoB,SAAzB;AAJZ,OAAP;AAMA;;;;;;SAlOmBtB,M;AAqOrB,IAAMkC,iCAAiC,GAAG,GAA1C","sourcesContent":["// For some weird reason, in Chrome, `setTimeout()` would lag up to a second (or more) behind.\r\n// Turns out, Chrome developers have deprecated `setTimeout()` API entirely without asking anyone.\r\n// Replacing `setTimeout()` with `requestAnimationFrame()` can work around that Chrome bug.\r\n// https://github.com/bvaughn/react-virtualized/issues/722\r\nimport { setTimeout, clearTimeout } from 'request-animation-frame-timeout'\r\n\r\nimport log from './utility/debug'\r\n\r\nexport default class Scroll {\r\n\tconstructor({\r\n\t\tbypass,\r\n\t\tscrollableContainer,\r\n\t\titemsContainer,\r\n\t\tonScroll,\r\n\t\tinitialScrollPosition,\r\n\t\tonScrollPositionChange,\r\n\t\tisImmediateLayoutScheduled,\r\n\t\thasNonRenderedItemsAtTheTop,\r\n\t\thasNonRenderedItemsAtTheBottom,\r\n\t\tgetLatestLayoutVisibleArea,\r\n\t\tgetListTopOffset,\r\n\t\tgetPrerenderMargin,\r\n\t\tonScrolledToTop,\r\n\t\twaitForScrollingToStop\r\n\t}) {\r\n\t\tthis.bypass = bypass\r\n\t\tthis.scrollableContainer = scrollableContainer\r\n\t\tthis.itemsContainer = itemsContainer\r\n\t\tthis.onScroll = onScroll\r\n\t\tthis.initialScrollPosition = initialScrollPosition\r\n\t\tthis.onScrollPositionChange = onScrollPositionChange\r\n\t\tthis.isImmediateLayoutScheduled = isImmediateLayoutScheduled\r\n\t\tthis.hasNonRenderedItemsAtTheTop = hasNonRenderedItemsAtTheTop\r\n\t\tthis.hasNonRenderedItemsAtTheBottom = hasNonRenderedItemsAtTheBottom\r\n\t\tthis.getLatestLayoutVisibleArea = getLatestLayoutVisibleArea\r\n\t\tthis.getListTopOffset = getListTopOffset\r\n\t\tthis.getPrerenderMargin = getPrerenderMargin\r\n\t\tthis.onScrolledToTop = onScrolledToTop\r\n\t\tthis.waitForScrollingToStop = waitForScrollingToStop\r\n\t}\r\n\r\n\tlisten() {\r\n\t\tif (this.initialScrollPosition !== undefined) {\r\n\t\t\tthis.scrollToY(this.initialScrollPosition)\r\n\t\t}\r\n\t\tif (this.onScrollPositionChange) {\r\n\t\t\tthis.onScrollPositionChange(this.getScrollY())\r\n\t\t}\r\n\t\tthis.stopListeningToScroll = this.scrollableContainer.onScroll(this.onScrollListener)\r\n\t}\r\n\r\n\tstop() {\r\n\t\tif (this.stopReportingScrollPositionChange) {\r\n\t\t\tthis.stopReportingScrollPositionChange()\r\n\t\t\tthis.stopReportingScrollPositionChange = undefined\r\n\t\t}\r\n\t\tif (this.stopListeningToScroll) {\r\n\t\t\tthis.stopListeningToScroll()\r\n\t\t\tthis.stopListeningToScroll = undefined\r\n\t\t}\r\n\t\tif (this.onStopScrollingListener) {\r\n\t\t\tthis.onStopScrollingListener = undefined\r\n\t\t}\r\n\t\tif (this.onScrollOnStopScrolling) {\r\n\t\t\tthis.onScrollOnStopScrolling = undefined\r\n\t\t}\r\n\t\tthis.cancelOnStopScrollingTimer()\r\n\t}\r\n\r\n\tscrollToY(scrollY) {\r\n\t\tthis.ignoreScrollEvents = true\r\n\t\tthis.scrollableContainer.scrollToY(scrollY)\r\n\t\tthis.ignoreScrollEvents = undefined\r\n\t}\r\n\r\n\tscrollByY = (scrollByY) => {\r\n\t\tthis.scrollToY(this.getScrollY() + scrollByY)\r\n\t}\r\n\r\n\tgetScrollY() {\r\n\t\treturn this.scrollableContainer.getScrollY()\r\n\t}\r\n\r\n\tcancelOnStopScrollingTimer() {\r\n\t\tif (this.onStopScrollingTimer) {\r\n\t\t\tclearTimeout(this.onStopScrollingTimer)\r\n\t\t\tthis.onStopScrollingTimer = undefined\r\n\t\t}\r\n\t}\r\n\r\n\tcancelScheduledLayout() {\r\n\t\t// Cancel a \"re-layout when user stops scrolling\" timer.\r\n\t\tthis.cancelOnStopScrollingTimer()\r\n\t}\r\n\r\n\tonScrollListener = () => {\r\n\t\tif (this.onScrollPositionChange) {\r\n\t\t\tthis.onScrollPositionChange(this.getScrollY())\r\n\t\t}\r\n\r\n\t\t// If the user has scrolled up to the top of the items container.\r\n\t\t// (this option isn't currently used)\r\n\t\tif (this.onScrolledToTop) {\r\n\t\t\tif (this.getScrollY() < this.getListTopOffset()) {\r\n\t\t\t\tthis.onScrolledToTop()\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (this.bypass) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tif (this.ignoreScrollEvents) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\t// Prefer not performing a re-layout while the user is scrolling (if possible).\r\n\t\t// If the user doesn't scroll too far and then stops for a moment,\r\n\t\t// then a mid-scroll re-layout could be delayed until such a brief stop:\r\n\t\t// presumably, this results in better (smoother) scrolling performance,\r\n\t\t// delaying the work to when it doesn't introduce any stutter or \"jank\".\r\n\r\n\t\t// Reset `this.onStopScrollingTimer` (will be re-created below).\r\n\t\tthis.cancelOnStopScrollingTimer()\r\n\r\n\t\t// See if the latest \"layout\" (the currently rendered set of items)\r\n\t\t// is still sufficient in order to show all the items that're\r\n\t\t// currently inside the viewport. If there're some non-rendered items\r\n\t\t// that're visible in the current viewport, then those items\r\n\t\t// should be rendered \"immediately\" rather than waiting until\r\n\t\t// the user stops scrolling.\r\n\t\tconst forceUpdate =\r\n\t\t\t// If the items have been rendered at least once\r\n\t\t\tthis.getLatestLayoutVisibleArea() && (\r\n\t\t\t\t(\r\n\t\t\t\t\t// If the user has scrolled up past the \"prerender margin\"\r\n\t\t\t\t\t// and there're some non-rendered items at the top,\r\n\t\t\t\t\t// then force a re-layout.\r\n\t\t\t\t\t//\r\n\t\t\t\t\t// (during these calculations we assume that the list's top coordinate\r\n\t\t\t\t\t// hasn't changed since previous layout; even if that's not exactly true,\r\n\t\t\t\t\t// the items will be re-layout when the user stops scrolling anyway)\r\n\t\t\t\t\t//\r\n\t\t\t\t\t(this.getScrollY() < this.getLatestLayoutVisibleArea().top - this.getPrerenderMargin()) &&\r\n\t\t\t\t\tthis.hasNonRenderedItemsAtTheTop()\r\n\t\t\t\t)\r\n\t\t\t\t||\r\n\t\t\t\t(\r\n\t\t\t\t\t// If the user has scrolled down past the \"prerender margin\"\r\n\t\t\t\t\t// and there're any non-rendered items left at the end,\r\n\t\t\t\t\t// then force a re-layout.\r\n\t\t\t\t\t//\r\n\t\t\t\t\t// (during these calculations we assume that the list's top coordinate\r\n\t\t\t\t\t// hasn't changed since previous layout; even if that's not exactly true,\r\n\t\t\t\t\t// the items will be re-layout when the user stops scrolling anyway)\r\n\t\t\t\t\t//\r\n\t\t\t\t\t(this.getScrollY() + this.scrollableContainer.getHeight() > this.getLatestLayoutVisibleArea().bottom + this.getPrerenderMargin()) &&\r\n\t\t\t\t\tthis.hasNonRenderedItemsAtTheBottom()\r\n\t\t\t\t)\r\n\t\t\t)\r\n\r\n\t\tif (forceUpdate) {\r\n\t\t\tlog('The user has scrolled far enough: perform a re-layout')\r\n\t\t} else {\r\n\t\t\tlog('The user is scrolling: perform a re-layout when they stop scrolling')\r\n\t\t}\r\n\r\n\t\tif (forceUpdate || this.waitForScrollingToStop === false) {\r\n\t\t\treturn this.onScroll()\r\n\t\t}\r\n\r\n\t\t// If a re-layout is already scheduled at the next \"frame\",\r\n\t\t// don't schedule a \"re-layout when user stops scrolling\" timer.\r\n\t\tif (this.isImmediateLayoutScheduled()) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tthis.onScrollOnStopScrolling = true\r\n\t\tthis.watchOnStopScrolling()\r\n\t}\r\n\r\n\twatchOnStopScrolling() {\r\n\t\tthis.onStopScrollingTimer = setTimeout(\r\n\t\t\t() => {\r\n\t\t\t\tthis.onStopScrollingTimer = undefined\r\n\r\n\t\t\t\tif (this.onScrollOnStopScrolling) {\r\n\t\t\t\t\tthis.onScrollOnStopScrolling = undefined\r\n\t\t\t\t\tthis.onScroll({ delayed: true })\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (this.onStopScrollingListener) {\r\n\t\t\t\t\tconst onStopScrollingListener = this.onStopScrollingListener\r\n\t\t\t\t\tthis.onStopScrollingListener = undefined\r\n\t\t\t\t\t// `onStopScrollingListener()` may hypothetically schedule\r\n\t\t\t\t\t// another `onStopScrolling()` listener, so set\r\n\t\t\t\t\t// `this.onStopScrollingListener` to `undefined` before\r\n\t\t\t\t\t// calling it rather than after.\r\n\t\t\t\t\tlog('~ The user has stopped scrolling ~')\r\n\t\t\t\t\tonStopScrollingListener()\r\n\t\t\t\t}\r\n\t\t\t},\r\n\t\t\t// \"scroll\" events are usually dispatched every 16 milliseconds\r\n\t\t\t// for 60fps refresh rate, so waiting for 100 milliseconds feels\r\n\t\t\t// reasonable: that would be about 6 frames of inactivity period,\r\n\t\t\t// which could mean that either the user has stopped scrolling\r\n\t\t\t// (for a moment) or the browser is lagging and stuttering\r\n\t\t\t// (skipping frames due to high load).\r\n\t\t\t// If the user continues scrolling then this timeout is constantly\r\n\t\t\t// refreshed (cancelled and then re-created).\r\n\t\t\tON_STOP_SCROLLING_INACTIVE_PERIOD\r\n\t\t)\r\n\t}\r\n\r\n\t// (this function isn't currently used)\r\n\tonStopScrolling(onStopScrollingListener) {\r\n\t\tthis.onStopScrollingListener = onStopScrollingListener\r\n\t\tif (!this.onStopScrollingTimer) {\r\n\t\t\tthis.watchOnStopScrolling()\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Returns visible area coordinates relative to the scrollable container.\r\n\t * @return {object} `{ top: number, bottom: number }`\r\n\t */\r\n\tgetVisibleAreaBounds() {\r\n\t\tconst scrollY = this.getScrollY()\r\n\t\treturn {\r\n\t\t\t// The first pixel of the screen.\r\n\t\t\ttop: scrollY,\r\n\t\t\t// The pixel after the last pixel of the screen.\r\n\t\t\tbottom: scrollY + this.scrollableContainer.getHeight()\r\n\t\t}\r\n\t}\r\n}\r\n\r\nconst ON_STOP_SCROLLING_INACTIVE_PERIOD = 100"],"file":"Scroll.js"}
|