Change window resize handler to switch to/from mobile layout as soon as needed (#11656)

lolsob-rspec
ThibG 2019-08-25 15:48:50 +02:00 committed by Eugen Rochko
parent eaa759ffd4
commit 15a82d48ea
1 changed files with 14 additions and 4 deletions

View File

@ -141,14 +141,24 @@ class SwitchingColumnsArea extends React.PureComponent {
return location.state !== previewMediaState && location.state !== previewVideoState;
}
handleResize = debounce(() => {
handleLayoutChange = debounce(() => {
// The cached heights are no longer accurate, invalidate
this.props.onLayoutChange();
this.setState({ mobile: isMobile(window.innerWidth) });
}, 500, {
trailing: true,
});
})
handleResize = () => {
const mobile = isMobile(window.innerWidth);
if (mobile !== this.state.mobile) {
this.handleLayoutChange.cancel();
this.props.onLayoutChange();
this.setState({ mobile });
} else {
this.handleLayoutChange();
}
}
setRef = c => {
this.node = c.getWrappedInstance();