diff options
author | ThibG <thib@sitedethib.com> | 2019-08-25 15:48:50 +0200 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2019-08-29 17:32:22 +0200 |
commit | 6ee2501991886f0c1f1c89a9b5724d61fc4fc719 (patch) | |
tree | 2b13bbd8c92104462dbd3ba50091f4e22bcf1cc5 /app/javascript/flavours | |
parent | b90bd31cfdc812da770ec3abd3a1a3a597d85a04 (diff) |
[Glitch] Change window resize handler to switch to/from mobile layout as soon as needed
Port bd4099d976b52f7ec00e00b23cfe6e2766ff1e4d to glitch-soc Signed-off-by: Thibaut Girka <thib@sitedethib.com>
Diffstat (limited to 'app/javascript/flavours')
-rw-r--r-- | app/javascript/flavours/glitch/features/ui/index.js | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/app/javascript/flavours/glitch/features/ui/index.js b/app/javascript/flavours/glitch/features/ui/index.js index dbfaf1220..33625581d 100644 --- a/app/javascript/flavours/glitch/features/ui/index.js +++ b/app/javascript/flavours/glitch/features/ui/index.js @@ -138,14 +138,24 @@ class SwitchingColumnsArea extends React.PureComponent { window.removeEventListener('resize', this.handleResize); } - handleResize = debounce(() => { + handleLayoutChange = debounce(() => { // The cached heights are no longer accurate, invalidate this.props.onLayoutChange(); - - this.setState({ mobile: isMobile(window.innerWidth, this.props.layout) }); }, 500, { trailing: true, - }); + }) + + handleResize = () => { + const mobile = isMobile(window.innerWidth, this.props.layout); + + if (mobile !== this.state.mobile) { + this.handleLayoutChange.cancel(); + this.props.onLayoutChange(); + this.setState({ mobile }); + } else { + this.handleLayoutChange(); + } + } setRef = c => { this.node = c.getWrappedInstance(); |