2018-10-30 17:12:21 +00:00
|
|
|
/*
|
|
|
|
Copyright 2018 New Vector Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import ResizeHandle from '../views/elements/ResizeHandle';
|
|
|
|
import {Resizer, FixedDistributor} from '../../resizer';
|
|
|
|
|
|
|
|
export default class MainSplit extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this._setResizeContainerRef = this._setResizeContainerRef.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
_createResizer() {
|
|
|
|
const classNames = {
|
|
|
|
handle: "mx_ResizeHandle",
|
|
|
|
vertical: "mx_ResizeHandle_vertical",
|
2018-10-31 11:20:10 +00:00
|
|
|
reverse: "mx_ResizeHandle_reverse",
|
2018-10-30 17:12:21 +00:00
|
|
|
};
|
|
|
|
const resizer = new Resizer(
|
|
|
|
this.resizeContainer,
|
|
|
|
FixedDistributor);
|
|
|
|
resizer.setClassNames(classNames);
|
2018-10-31 11:08:41 +00:00
|
|
|
const rhsSize = window.localStorage.getItem("mx_rhs_size");
|
|
|
|
if (rhsSize !== null) {
|
|
|
|
resizer.forHandleAt(0).resize(parseInt(rhsSize, 10));
|
|
|
|
}
|
|
|
|
|
|
|
|
resizer.attach();
|
|
|
|
this.resizer = resizer;
|
2018-10-30 17:12:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_setResizeContainerRef(div) {
|
|
|
|
this.resizeContainer = div;
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2018-10-31 11:08:41 +00:00
|
|
|
if (this.props.panel && !this.collapsedRhs) {
|
|
|
|
this._createResizer();
|
|
|
|
}
|
2018-10-30 17:12:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2018-10-31 11:17:13 +00:00
|
|
|
if (this.resizer) {
|
|
|
|
this.resizer.detach();
|
|
|
|
this.resizer = null;
|
|
|
|
}
|
2018-10-31 11:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
const wasExpanded = !this.props.collapsedRhs && prevProps.collapsedRhs;
|
|
|
|
const wasCollapsed = this.props.collapsedRhs && !prevProps.collapsedRhs;
|
|
|
|
const wasPanelSet = this.props.panel && !prevProps.panel;
|
|
|
|
const wasPanelCleared = !this.props.panel && prevProps.panel;
|
|
|
|
|
|
|
|
if (wasExpanded || wasPanelSet) {
|
|
|
|
this._createResizer();
|
|
|
|
} else if (wasCollapsed || wasPanelCleared) {
|
|
|
|
this.resizer.detach();
|
|
|
|
this.resizer = null;
|
|
|
|
}
|
2018-10-30 17:12:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const bodyView = React.Children.only(this.props.children);
|
|
|
|
const panelView = this.props.panel;
|
|
|
|
|
|
|
|
if (this.props.collapsedRhs || !panelView) {
|
|
|
|
return bodyView;
|
|
|
|
} else {
|
|
|
|
return <div className="mx_MainSplit" ref={this._setResizeContainerRef}>
|
|
|
|
{ bodyView }
|
2018-10-31 11:08:41 +00:00
|
|
|
<ResizeHandle reverse={true} />
|
2018-10-30 17:12:21 +00:00
|
|
|
{ panelView }
|
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
}
|
2018-10-31 11:20:10 +00:00
|
|
|
}
|