Add feature to ResizeNotifier to maintain isResizing state and use it to skip onScroll handling
This commit is contained in:
parent
6178b3c0e2
commit
cffe902504
9 changed files with 51 additions and 13 deletions
|
@ -1335,7 +1335,7 @@ export default createReactClass({
|
||||||
</div>
|
</div>
|
||||||
<GroupHeaderButtons />
|
<GroupHeaderButtons />
|
||||||
</div>
|
</div>
|
||||||
<MainSplit panel={rightPanel}>
|
<MainSplit panel={rightPanel} resizeNotifier={this.props.resizeNotifier}>
|
||||||
<AutoHideScrollbar className="mx_GroupView_body">
|
<AutoHideScrollbar className="mx_GroupView_body">
|
||||||
{ this._getMembershipSection() }
|
{ this._getMembershipSection() }
|
||||||
{ this._getGroupSection() }
|
{ this._getGroupSection() }
|
||||||
|
|
|
@ -257,6 +257,12 @@ class LoggedInView extends React.Component<IProps, IState> {
|
||||||
window.localStorage.setItem("mx_lhs_size", '' + size);
|
window.localStorage.setItem("mx_lhs_size", '' + size);
|
||||||
this.props.resizeNotifier.notifyLeftHandleResized();
|
this.props.resizeNotifier.notifyLeftHandleResized();
|
||||||
},
|
},
|
||||||
|
onResizeStart: () => {
|
||||||
|
this.props.resizeNotifier.startResizing();
|
||||||
|
},
|
||||||
|
onResizeStop: () => {
|
||||||
|
this.props.resizeNotifier.stopResizing();
|
||||||
|
},
|
||||||
};
|
};
|
||||||
const resizer = new Resizer(
|
const resizer = new Resizer(
|
||||||
this._resizeContainer.current,
|
this._resizeContainer.current,
|
||||||
|
@ -650,12 +656,13 @@ class LoggedInView extends React.Component<IProps, IState> {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PageTypes.UserView:
|
case PageTypes.UserView:
|
||||||
pageElement = <UserView userId={this.props.currentUserId} />;
|
pageElement = <UserView userId={this.props.currentUserId} resizeNotifier={this.props.resizeNotifier} />;
|
||||||
break;
|
break;
|
||||||
case PageTypes.GroupView:
|
case PageTypes.GroupView:
|
||||||
pageElement = <GroupView
|
pageElement = <GroupView
|
||||||
groupId={this.props.currentGroupId}
|
groupId={this.props.currentGroupId}
|
||||||
isNew={this.props.currentGroupIsNew}
|
isNew={this.props.currentGroupIsNew}
|
||||||
|
resizeNotifier={this.props.resizeNotifier}
|
||||||
/>;
|
/>;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,18 @@ import React from 'react';
|
||||||
import { Resizable } from 're-resizable';
|
import { Resizable } from 're-resizable';
|
||||||
|
|
||||||
export default class MainSplit extends React.Component {
|
export default class MainSplit extends React.Component {
|
||||||
_onResized = (event, direction, refToElement, delta) => {
|
_onResizeStart = () => {
|
||||||
|
this.props.resizeNotifier.startResizing();
|
||||||
|
};
|
||||||
|
|
||||||
|
_onResize = () => {
|
||||||
|
this.props.resizeNotifier.notifyRightHandleResized();
|
||||||
|
};
|
||||||
|
|
||||||
|
_onResizeStop = (event, direction, refToElement, delta) => {
|
||||||
|
this.props.resizeNotifier.stopResizing();
|
||||||
window.localStorage.setItem("mx_rhs_size", this._loadSidePanelSize().width + delta.width);
|
window.localStorage.setItem("mx_rhs_size", this._loadSidePanelSize().width + delta.width);
|
||||||
}
|
};
|
||||||
|
|
||||||
_loadSidePanelSize() {
|
_loadSidePanelSize() {
|
||||||
let rhsSize = parseInt(window.localStorage.getItem("mx_rhs_size"), 10);
|
let rhsSize = parseInt(window.localStorage.getItem("mx_rhs_size"), 10);
|
||||||
|
@ -58,7 +67,9 @@ export default class MainSplit extends React.Component {
|
||||||
bottomLeft: false,
|
bottomLeft: false,
|
||||||
topLeft: false,
|
topLeft: false,
|
||||||
}}
|
}}
|
||||||
onResizeStop={this._onResized}
|
onResizeStart={this._onResizeStart}
|
||||||
|
onResize={this._onResize}
|
||||||
|
onResizeStop={this._onResizeStop}
|
||||||
className="mx_RightPanel_ResizeWrapper"
|
className="mx_RightPanel_ResizeWrapper"
|
||||||
handleClasses={{left: "mx_RightPanel_ResizeHandle"}}
|
handleClasses={{left: "mx_RightPanel_ResizeHandle"}}
|
||||||
>
|
>
|
||||||
|
|
|
@ -2096,10 +2096,7 @@ export default createReactClass({
|
||||||
onLeaveClick={(myMembership === "join") ? this.onLeaveClick : null}
|
onLeaveClick={(myMembership === "join") ? this.onLeaveClick : null}
|
||||||
e2eStatus={this.state.e2eStatus}
|
e2eStatus={this.state.e2eStatus}
|
||||||
/>
|
/>
|
||||||
<MainSplit
|
<MainSplit panel={rightPanel} resizeNotifier={this.props.resizeNotifier}>
|
||||||
panel={rightPanel}
|
|
||||||
resizeNotifier={this.props.resizeNotifier}
|
|
||||||
>
|
|
||||||
<div className={fadableSectionClasses}>
|
<div className={fadableSectionClasses}>
|
||||||
{auxPanel}
|
{auxPanel}
|
||||||
<div className={timelineClasses}>
|
<div className={timelineClasses}>
|
||||||
|
|
|
@ -166,7 +166,7 @@ export default createReactClass({
|
||||||
this._pendingFillRequests = {b: null, f: null};
|
this._pendingFillRequests = {b: null, f: null};
|
||||||
|
|
||||||
if (this.props.resizeNotifier) {
|
if (this.props.resizeNotifier) {
|
||||||
this.props.resizeNotifier.on("middlePanelResized", this.onResize);
|
this.props.resizeNotifier.on("middlePanelResizedNoisy", this.onResize);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.resetScrollState();
|
this.resetScrollState();
|
||||||
|
@ -196,11 +196,12 @@ export default createReactClass({
|
||||||
this.unmounted = true;
|
this.unmounted = true;
|
||||||
|
|
||||||
if (this.props.resizeNotifier) {
|
if (this.props.resizeNotifier) {
|
||||||
this.props.resizeNotifier.removeListener("middlePanelResized", this.onResize);
|
this.props.resizeNotifier.removeListener("middlePanelResizedNoisy", this.onResize);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onScroll: function(ev) {
|
onScroll: function(ev) {
|
||||||
|
if (this.props.resizeNotifier.isResizing) return; // skip scroll events caused by resizing
|
||||||
debuglog("onScroll", this._getScrollNode().scrollTop);
|
debuglog("onScroll", this._getScrollNode().scrollTop);
|
||||||
this._scrollTimeout.restart();
|
this._scrollTimeout.restart();
|
||||||
this._saveScrollState();
|
this._saveScrollState();
|
||||||
|
|
|
@ -80,7 +80,9 @@ export default class UserView extends React.Component {
|
||||||
const RightPanel = sdk.getComponent('structures.RightPanel');
|
const RightPanel = sdk.getComponent('structures.RightPanel');
|
||||||
const MainSplit = sdk.getComponent('structures.MainSplit');
|
const MainSplit = sdk.getComponent('structures.MainSplit');
|
||||||
const panel = <RightPanel user={this.state.member} />;
|
const panel = <RightPanel user={this.state.member} />;
|
||||||
return (<MainSplit panel={panel}><HomePage /></MainSplit>);
|
return (<MainSplit panel={panel} resizeNotifier={this.props.resizeNotifier}>
|
||||||
|
<HomePage />
|
||||||
|
</MainSplit>);
|
||||||
} else {
|
} else {
|
||||||
return (<div />);
|
return (<div />);
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,6 +252,7 @@ const PersistentVResizer = ({
|
||||||
maxHeight={maxHeight}
|
maxHeight={maxHeight}
|
||||||
onResizeStart={() => {
|
onResizeStart={() => {
|
||||||
if (!resizing) setResizing(true);
|
if (!resizing) setResizing(true);
|
||||||
|
resizeNotifier.startResizing();
|
||||||
}}
|
}}
|
||||||
onResize={() => {
|
onResize={() => {
|
||||||
resizeNotifier.notifyTimelineHeightChanged();
|
resizeNotifier.notifyTimelineHeightChanged();
|
||||||
|
@ -259,7 +260,7 @@ const PersistentVResizer = ({
|
||||||
onResizeStop={(e, dir, ref, d) => {
|
onResizeStop={(e, dir, ref, d) => {
|
||||||
setHeight(height + d.height);
|
setHeight(height + d.height);
|
||||||
if (resizing) setResizing(false);
|
if (resizing) setResizing(false);
|
||||||
resizeNotifier.notifyTimelineHeightChanged();
|
resizeNotifier.stopResizing();
|
||||||
}}
|
}}
|
||||||
handleWrapperClass={handleWrapperClass}
|
handleWrapperClass={handleWrapperClass}
|
||||||
handleClasses={{bottom: handleClass}}
|
handleClasses={{bottom: handleClass}}
|
||||||
|
|
|
@ -105,6 +105,9 @@ export default class Resizer {
|
||||||
if (this.classNames.resizing) {
|
if (this.classNames.resizing) {
|
||||||
this.container.classList.add(this.classNames.resizing);
|
this.container.classList.add(this.classNames.resizing);
|
||||||
}
|
}
|
||||||
|
if (this.config.onResizeStart) {
|
||||||
|
this.config.onResizeStart();
|
||||||
|
}
|
||||||
|
|
||||||
const {sizer, distributor} = this._createSizerAndDistributor(resizeHandle);
|
const {sizer, distributor} = this._createSizerAndDistributor(resizeHandle);
|
||||||
distributor.start();
|
distributor.start();
|
||||||
|
@ -119,6 +122,9 @@ export default class Resizer {
|
||||||
if (this.classNames.resizing) {
|
if (this.classNames.resizing) {
|
||||||
this.container.classList.remove(this.classNames.resizing);
|
this.container.classList.remove(this.classNames.resizing);
|
||||||
}
|
}
|
||||||
|
if (this.config.onResizeStop) {
|
||||||
|
this.config.onResizeStop();
|
||||||
|
}
|
||||||
distributor.finish();
|
distributor.finish();
|
||||||
body.removeEventListener("mouseup", finishResize, false);
|
body.removeEventListener("mouseup", finishResize, false);
|
||||||
document.removeEventListener("mouseleave", finishResize, false);
|
document.removeEventListener("mouseleave", finishResize, false);
|
||||||
|
|
|
@ -31,6 +31,19 @@ export default class ResizeNotifier extends EventEmitter {
|
||||||
// with default options, will call fn once at first call, and then every x ms
|
// with default options, will call fn once at first call, and then every x ms
|
||||||
// if there was another call in that timespan
|
// if there was another call in that timespan
|
||||||
this._throttledMiddlePanel = throttle(() => this.emit("middlePanelResized"), 200);
|
this._throttledMiddlePanel = throttle(() => this.emit("middlePanelResized"), 200);
|
||||||
|
this._isResizing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
get isResizing() {
|
||||||
|
return this._isResizing;
|
||||||
|
}
|
||||||
|
|
||||||
|
startResizing() {
|
||||||
|
this._isResizing = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
stopResizing() {
|
||||||
|
this._isResizing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_noisyMiddlePanel() {
|
_noisyMiddlePanel() {
|
||||||
|
|
Loading…
Reference in a new issue