Skip to content

Commit

Permalink
delaying update of height and width until after stop dragging 50ms
Browse files Browse the repository at this point in the history
  • Loading branch information
Wei-Wei Wu committed Mar 9, 2018
1 parent 7b2fdde commit cebb1d2
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions lib/ui/src/modules/ui/components/layout/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { localStorage, window } from 'global';
import { localStorage } from 'global';
import PropTypes from 'prop-types';
import React from 'react';
import SplitPane from 'react-split-pane';
Expand Down Expand Up @@ -140,14 +140,6 @@ class Layout extends React.Component {
this.onDragEnd = this.onDragEnd.bind(this);
}

componentDidMount() {
window.addEventListener('resize', this.onResize);
}

componentWillUnmount() {
window.removeEventListener('resize', this.onResize);
}

onDragStart() {
this.setState({ isDragging: true });
}
Expand All @@ -157,18 +149,22 @@ class Layout extends React.Component {
}

onResize(pane, mode) {
return size => {
this.layerSizes[pane][mode] = size;
saveSizes(this.layerSizes);

const { clientWidth, clientHeight } = this.previewPanelRef;
let resizeTimeout;

this.setState({
previewPanelDimensions: {
width: clientWidth,
height: clientHeight,
},
});
return size => {
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(() => {
this.layerSizes[pane][mode] = size;
saveSizes(this.layerSizes);

const { clientWidth, clientHeight } = this.previewPanelRef;
this.setState({
previewPanelDimensions: {
width: clientWidth,
height: clientHeight,
},
});
}, 50);
};
}

Expand Down

0 comments on commit cebb1d2

Please sign in to comment.