From b3e6cbfddd7115bfd9aa1d44fd6535bba3ec2883 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 21 Feb 2019 18:51:18 +0100 Subject: [PATCH] restore scroll state when timeline resizes using ResizeObserver (only where supported, polyfill doesn't give good results) --- src/components/structures/ScrollPanel.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/components/structures/ScrollPanel.js b/src/components/structures/ScrollPanel.js index a1a7d08e0b..db19b1d0cc 100644 --- a/src/components/structures/ScrollPanel.js +++ b/src/components/structures/ScrollPanel.js @@ -160,6 +160,13 @@ module.exports = React.createClass({ componentDidMount: function() { this.checkScroll(); + + if (typeof ResizeObserver !== "undefined") { + this._timelineSizeObserver = new ResizeObserver(() => { + this._restoreSavedScrollState(); + }); + this._timelineSizeObserver.observe(this.refs.itemlist); + } }, componentDidUpdate: function() { @@ -181,6 +188,10 @@ module.exports = React.createClass({ // // (We could use isMounted(), but facebook have deprecated that.) this.unmounted = true; + if (this._timelineSizeObserver) { + this._timelineSizeObserver.disconnect(); + this._timelineSizeObserver = null; + } }, onScroll: function(ev) {