Skip to content

Commit

Permalink
reusing onThrottledResize on window resize events
Browse files Browse the repository at this point in the history
  • Loading branch information
wuweiweiwu committed Mar 11, 2018
1 parent 65329d3 commit f515154
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 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 } from 'global';
import { localStorage, window } from 'global';
import PropTypes from 'prop-types';
import React from 'react';
import SplitPane from 'react-split-pane';
Expand Down Expand Up @@ -141,6 +141,14 @@ class Layout extends React.Component {
this.onDragEnd = this.onDragEnd.bind(this);
}

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

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

onDragStart() {
this.setState({ isDragging: true });
}
Expand All @@ -150,8 +158,10 @@ class Layout extends React.Component {
}

onResize(pane, mode, size) {
this.layerSizes[pane][mode] = size;
saveSizes(this.layerSizes);
if (pane && mode && size) {
this.layerSizes[pane][mode] = size;
saveSizes(this.layerSizes);
}

const { clientWidth, clientHeight } = this.previewPanelRef;
this.setState({
Expand Down

0 comments on commit f515154

Please sign in to comment.