Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Improved scrolling & pagination #2676

Merged
merged 13 commits into from
Mar 1, 2019
Merged
33 changes: 27 additions & 6 deletions src/components/structures/ScrollPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ if (DEBUG_SCROLL) {
* scroll down further. If stickyBottom is disabled, we just save the scroll
* offset as normal.
*/


function createTimelineResizeDetector(scrollNode, itemlist, callback) {
if (typeof ResizeObserver !== "undefined") {
const ro = new ResizeObserver(callback);
ro.observe(itemlist);
return ro;
} else if (typeof IntersectionObserver !== "undefined") {
const threshold = [];
for (let i = 0; i < 1000; ++i) {
threshold.push(i / 1000);
}
threshold.push(1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Could also do i <= 1000 in the loop, if you like.

const io = new IntersectionObserver(
callback,
{root: scrollNode, threshold},
);
io.observe(itemlist);
return io;
}
}

module.exports = React.createClass({
displayName: 'ScrollPanel',

Expand Down Expand Up @@ -161,12 +183,11 @@ module.exports = React.createClass({
componentDidMount: function() {
this.checkScroll();

if (typeof ResizeObserver !== "undefined") {
this._timelineSizeObserver = new ResizeObserver(() => {
this._restoreSavedScrollState();
});
this._timelineSizeObserver.observe(this.refs.itemlist);
}
this._timelineSizeObserver = createTimelineResizeDetector(
this._getScrollNode(),
this.refs.itemlist,
() => { this._restoreSavedScrollState(); },
);
},

componentDidUpdate: function() {
Expand Down