From dae509d0eb8614a4d2521b3679226f0fb2ac5ced Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 26 Nov 2018 16:42:58 +0100 Subject: [PATCH] introduce resizeFromContainerOffset method on distributor up till now, resize received the offset of the resize handle within the container upon resizing, and would then calculate it's new size. For this first item in the container, this is the same, and has therefor not been a problem yet. Now however, we'll need to be able to programatically (from localStorage) set the size of any roomsublist, so need a method we can call with just the size and not an offset within the container. The resizer calls the new method, which subsequently calls resize. This also has the nice side-effect that you can now easily call super.resize after having transformed the new item size --- src/resizer/distributors.js | 27 +++++++++++++++------------ src/resizer/resizer.js | 2 +- src/resizer/room.js | 11 +++++++---- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/resizer/distributors.js b/src/resizer/distributors.js index 3c3fd72621..caf677a18f 100644 --- a/src/resizer/distributors.js +++ b/src/resizer/distributors.js @@ -18,43 +18,46 @@ limitations under the License. distributors translate a moving cursor into CSS/DOM changes by calling the sizer -they have one method, `resize` that receives +they have two methods: + `resize` receives then new item size + `resizeFromContainerOffset` receives resize handle location + within the container bounding box. For internal use. + This method usually ends up calling `resize` once the start offset is subtracted. the offset from the container edge of where the mouse cursor is. */ class FixedDistributor { - constructor(sizer, item, config) { + constructor(sizer, item, id, config) { this.sizer = sizer; this.item = item; + this.id = id; this.beforeOffset = sizer.getItemOffset(this.item); this.onResized = config && config.onResized; } - resize(offset) { - const itemSize = offset - this.beforeOffset; + resize(itemSize) { this.sizer.setItemSize(this.item, itemSize); if (this.onResized) { - this.onResized(itemSize, this.item); + this.onResized(itemSize, this.id, this.item); } return itemSize; } - sizeFromOffset(offset) { - return offset - this.beforeOffset; + resizeFromContainerOffset(offset) { + this.resize(offset - this.beforeOffset); } } class CollapseDistributor extends FixedDistributor { - constructor(sizer, item, config) { - super(sizer, item, config); + constructor(sizer, item, id, config) { + super(sizer, item, id, config); this.toggleSize = config && config.toggleSize; this.onCollapsed = config && config.onCollapsed; this.isCollapsed = false; } - resize(offset) { - const newSize = this.sizeFromOffset(offset); + resize(newSize) { const isCollapsedSize = newSize < this.toggleSize; if (isCollapsedSize && !this.isCollapsed) { this.isCollapsed = true; @@ -68,7 +71,7 @@ class CollapseDistributor extends FixedDistributor { this.isCollapsed = false; } if (!isCollapsedSize) { - super.resize(offset); + super.resize(newSize); } } } diff --git a/src/resizer/resizer.js b/src/resizer/resizer.js index c5112e5139..b7d17bc807 100644 --- a/src/resizer/resizer.js +++ b/src/resizer/resizer.js @@ -88,7 +88,7 @@ export class Resizer { const onMouseMove = (event) => { const offset = sizer.offsetFromEvent(event); - distributor.resize(offset); + distributor.resizeFromContainerOffset(offset); }; const body = document.body; diff --git a/src/resizer/room.js b/src/resizer/room.js index 2b79c4adf8..70f8be219a 100644 --- a/src/resizer/room.js +++ b/src/resizer/room.js @@ -36,16 +36,19 @@ class RoomSizer extends Sizer { } class RoomDistributor extends FixedDistributor { - resize(offset) { - const itemSize = offset - this.sizer.getItemOffset(this.item); + resize(itemSize) { const scrollItem = this.item.querySelector(".mx_RoomSubList_scroll"); const fixedHeight = this.item.offsetHeight - scrollItem.offsetHeight; if (itemSize > (fixedHeight + scrollItem.scrollHeight)) { - this.sizer.setItemSize(this.item, "resized-all"); + super.resize("resized-all"); } else { - this.sizer.setItemSize(this.item, itemSize); + super.resize(itemSize); } } + + resizeFromContainerOffset(offset) { + return this.resize(offset - this.sizer.getItemOffset(this.item)); + } } module.exports = {