provide collapsed callback to also collapse on react side of things

This commit is contained in:
Bruno Windels 2018-10-16 14:56:49 +02:00
parent 529845d8fc
commit c095e30ae4
2 changed files with 17 additions and 5 deletions

View file

@ -98,12 +98,17 @@ const LoggedInView = React.createClass({
vertical: "mx_ResizeHandle_vertical",
reverse: "mx_ResizeHandle_reverse"
};
const collapseToggleSize = 260 - 50;
const config = {
toggleSize: 260 - 50,
onCollapsed: (collapsed) => {
this.setState({collapseLhs: collapsed});
}
};
makeResizeable(
this.resizeContainer,
classNames,
CollapseDistributor,
collapseToggleSize);
config);
},
componentWillMount: function() {
@ -524,7 +529,7 @@ const LoggedInView = React.createClass({
<DragDropContext onDragEnd={this._onDragEnd}>
<div ref={(div) => this.resizeContainer = div} className={bodyClasses}>
<LeftPanel
collapsed={this.props.collapseLhs || false}
collapsed={this.props.collapseLhs || this.state.collapseLhs || false}
disabled={this.props.leftDisabled}
/>
<ResizeHandle/>

View file

@ -17,18 +17,25 @@ class FixedDistributor {
class CollapseDistributor extends FixedDistributor {
constructor(container, items, handleIndex, direction, sizer, toggleSize) {
constructor(container, items, handleIndex, direction, sizer, config) {
super(container, items, handleIndex, direction, sizer);
this.toggleSize = toggleSize;
this.toggleSize = config && config.toggleSize;
this.onCollapsed = config && config.onCollapsed;
}
resize(offset) {
let newSize = offset - this.sizer.getItemOffset(this.item);
if (newSize < this.toggleSize) {
this.item.classList.add("collapsed");
if (this.onCollapsed) {
this.onCollapsed(true, this.item);
}
}
else {
this.item.classList.remove("collapsed");
if (this.onCollapsed) {
this.onCollapsed(false, this.item);
}
}
super.resize(newSize);
}