use ResizeNotifier as well to relayout room list

pull/21833/head
Bruno Windels 2019-03-12 18:00:05 +01:00
parent 58f26ee9b0
commit 9541cc175f
4 changed files with 16 additions and 6 deletions

View File

@ -234,7 +234,7 @@ const LeftPanel = React.createClass({
<CallPreview ConferenceHandler={VectorConferenceHandler} /> <CallPreview ConferenceHandler={VectorConferenceHandler} />
<RoomList <RoomList
ref={this.collectRoomList} ref={this.collectRoomList}
toolbarShown={this.props.toolbarShown} resizeNotifier={this.props.resizeNotifier}
collapsed={this.props.collapsed} collapsed={this.props.collapsed}
searchFilter={this.state.searchFilter} searchFilter={this.state.searchFilter}
ConferenceHandler={VectorConferenceHandler} /> ConferenceHandler={VectorConferenceHandler} />

View File

@ -543,7 +543,7 @@ const LoggedInView = React.createClass({
<DragDropContext onDragEnd={this._onDragEnd}> <DragDropContext onDragEnd={this._onDragEnd}>
<div ref={this._setResizeContainerRef} className={bodyClasses}> <div ref={this._setResizeContainerRef} className={bodyClasses}>
<LeftPanel <LeftPanel
toolbarShown={!!topBar} resizeNotifier={this.props.resizeNotifier}
collapsed={this.props.collapseLhs || false} collapsed={this.props.collapseLhs || false}
disabled={this.props.leftDisabled} disabled={this.props.leftDisabled}
/> />

View File

@ -212,7 +212,7 @@ module.exports = React.createClass({
this._checkSubListsOverflow(); this._checkSubListsOverflow();
this.resizer.attach(); this.resizer.attach();
window.addEventListener("resize", this.onWindowResize); this.props.resizeNotifier.on("leftPanelResized", this.onResize);
this.mounted = true; this.mounted = true;
}, },
@ -260,7 +260,6 @@ module.exports = React.createClass({
componentWillUnmount: function() { componentWillUnmount: function() {
this.mounted = false; this.mounted = false;
window.removeEventListener("resize", this.onWindowResize);
dis.unregister(this.dispatcherRef); dis.unregister(this.dispatcherRef);
if (MatrixClientPeg.get()) { if (MatrixClientPeg.get()) {
MatrixClientPeg.get().removeListener("Room", this.onRoom); MatrixClientPeg.get().removeListener("Room", this.onRoom);
@ -272,6 +271,8 @@ module.exports = React.createClass({
MatrixClientPeg.get().removeListener("Group.myMembership", this._onGroupMyMembership); MatrixClientPeg.get().removeListener("Group.myMembership", this._onGroupMyMembership);
MatrixClientPeg.get().removeListener("RoomState.events", this.onRoomStateEvents); MatrixClientPeg.get().removeListener("RoomState.events", this.onRoomStateEvents);
} }
this.props.resizeNotifier.removeListener("leftPanelResized", this.onResize);
if (this._tagStoreToken) { if (this._tagStoreToken) {
this._tagStoreToken.remove(); this._tagStoreToken.remove();
@ -293,13 +294,14 @@ module.exports = React.createClass({
this._delayedRefreshRoomList.cancelPendingCall(); this._delayedRefreshRoomList.cancelPendingCall();
}, },
onWindowResize: function() {
onResize: function() {
if (this.mounted && this._layout && this.resizeContainer && if (this.mounted && this._layout && this.resizeContainer &&
Array.isArray(this._layoutSections) Array.isArray(this._layoutSections)
) { ) {
this._layout.update( this._layout.update(
this._layoutSections, this._layoutSections,
this.resizeContainer.offsetHeight this.resizeContainer.offsetHeight,
); );
} }
}, },

View File

@ -31,11 +31,13 @@ export default class ResizeNotifier extends EventEmitter {
} }
notifyBannersChanged() { notifyBannersChanged() {
this.emit("leftPanelResized");
this.emit("middlePanelResized"); this.emit("middlePanelResized");
} }
// can be called in quick succession // can be called in quick succession
notifyLeftHandleResized() { notifyLeftHandleResized() {
// don't emit event for own region
this._throttledMiddlePanel(); this._throttledMiddlePanel();
} }
@ -46,6 +48,12 @@ export default class ResizeNotifier extends EventEmitter {
// can be called in quick succession // can be called in quick succession
notifyWindowResized() { notifyWindowResized() {
// no need to throttle this one,
// also it could make scrollbars appear for
// a split second when the room list manual layout is now
// taller than the available space
this.emit("leftPanelResized");
this._throttledMiddlePanel(); this._throttledMiddlePanel();
} }
} }