From 843118176fd06e71f1eb8fc55a48df7df450c069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Sun, 23 Sep 2018 12:23:29 +0100 Subject: [PATCH] fix(ui): better navbar hiding when idle Don't destroy navbar since modals are mounted on it + update visibility after transition so animations work as expected --- ui/src/Components/NavBar/index.js | 55 +++++++++++++++++++++----- ui/src/Components/NavBar/index.test.js | 40 ++++++++++++------- 2 files changed, 70 insertions(+), 25 deletions(-) diff --git a/ui/src/Components/NavBar/index.js b/ui/src/Components/NavBar/index.js index 215b9e34c..28f633e68 100644 --- a/ui/src/Components/NavBar/index.js +++ b/ui/src/Components/NavBar/index.js @@ -22,10 +22,6 @@ import "./index.css"; const DesktopIdleTimeout = 1000 * 60 * 3; const MobileIdleTimeout = 1000 * 5; -const NavbarOnResize = function(width, height) { - document.body.style["padding-top"] = `${height + 4}px`; -}; - const NavBar = observer( class NavBar extends Component { static propTypes = { @@ -34,24 +30,63 @@ const NavBar = observer( silenceFormStore: PropTypes.instanceOf(SilenceFormStore).isRequired }; + elementSize = observable( + { + width: 0, + height: 0, + setSize(width, height) { + this.width = width; + this.height = height; + } + }, + { setSize: action } + ); + activityStatus = observable( { idle: false, + className: "visible", setIdle() { this.idle = true; }, setActive() { this.idle = false; + }, + hide() { + this.className = "invisible"; + }, + show() { + this.className = "visible"; } }, { setIdle: action.bound, - setActive: action.bound + setActive: action.bound, + hide: action.bound, + show: action.bound } ); + updateBodyPaddingTop = () => { + const paddingTop = this.activityStatus.idle + ? 0 + : this.elementSize.height + 4; + document.body.style["padding-top"] = `${paddingTop}px`; + }; + onHide = () => { - NavbarOnResize(0, 0); + this.activityStatus.hide(); + this.updateBodyPaddingTop(); + }; + + onShow = () => { + this.updateBodyPaddingTop(); + this.activityStatus.show(); + }; + + onResize = (width, height) => { + this.elementSize.setSize(width, height); + this.updateBodyPaddingTop(); }; render() { @@ -76,12 +111,12 @@ const NavBar = observer( -
+