mirror of
https://github.com/element-hq/element-web
synced 2024-11-24 18:25:49 +03:00
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
This commit is contained in:
parent
3e496833fc
commit
dae509d0eb
3 changed files with 23 additions and 17 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 = {
|
||||
|
|
Loading…
Reference in a new issue