From 524c0b2b20c74f3d5d64678144b04157944bcfcd Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 28 Dec 2020 23:00:03 -0500 Subject: Improve element hiding (#1171) * Use multi-line definition for transition * Update how PopupElement visibility is controlled --- ext/bg/css/settings2.css | 42 +++++++++++++++++++------------- ext/bg/js/settings/popup-elements.js | 47 +++++++++++++++--------------------- ext/bg/settings2.html | 40 +++++++++++++++--------------- 3 files changed, 65 insertions(+), 64 deletions(-) (limited to 'ext') diff --git a/ext/bg/css/settings2.css b/ext/bg/css/settings2.css index 42201174..89359309 100644 --- a/ext/bg/css/settings2.css +++ b/ext/bg/css/settings2.css @@ -1447,18 +1447,22 @@ button.icon-button:active { background-color: var(--dim-background-color); outline: none; z-index: 100; + opacity: 1; + visibility: visible; + transition: + opacity var(--animation-duration2) ease-out, + visibility 0s linear; +} +.modal-container[hidden] { opacity: 0; visibility: hidden; - transition: opacity var(--animation-duration2) ease-in, visibility 0s linear var(--animation-duration2); + transition: + opacity var(--animation-duration2) ease-in, + visibility 0s linear var(--animation-duration2); } -.modal-container:not(.modal-container-open):not(.modal-container-opening):not(.modal-container-closing) { +.modal-container[hidden]:not(.hidden-animating) { display: none; } -.modal-container.modal-container-open { - opacity: 1; - visibility: visible; - transition: opacity var(--animation-duration2) ease-out, visibility 0s linear; -} .modal-content { max-width: 100%; max-height: 100%; @@ -1467,9 +1471,9 @@ button.icon-button:active { background-color: var(--background-color-light); flex: 0 1 auto; border-radius: 0.5em; - transform: translate(0, var(--modal-transition-offset)); + transform: translate(0, 0); transition: - transform 0s linear var(--animation-duration2), + transform var(--animation-duration2) ease-out, width var(--animation-duration2) ease-in-out, height var(--animation-duration2) ease-in-out, border-radius var(--animation-duration2) ease-in-out; @@ -1478,7 +1482,7 @@ button.icon-button:active { flex-flow: column nowrap; overflow: hidden; } -.modal-container:not(.modal-container-open) .modal-content { +.modal-container[hidden] .modal-content { pointer-events: none; } .modal-content.modal-content-small { @@ -1493,10 +1497,10 @@ button.icon-button:active { transform: translate(0, 0); border-radius: 0; } -.modal-container.modal-container-open .modal-content { - transform: translate(0, 0); +.modal-container[hidden] .modal-content { + transform: translate(0, var(--modal-transition-offset)); transition: - transform var(--animation-duration2) ease-out, + transform 0s linear var(--animation-duration2), width var(--animation-duration2) ease-in-out, height var(--animation-duration2) ease-in-out, border-radius var(--animation-duration2) ease-in-out; @@ -1756,14 +1760,18 @@ button.popup-menu-item:disabled { border-radius: var(--settings-group-border-radius) var(--settings-group-border-radius) 0 0; transform: none; opacity: 1; - transition: transform var(--animation-duration) ease-out, opacity var(--animation-duration) ease-out; + transition: + transform var(--animation-duration) ease-out, + opacity var(--animation-duration) ease-out; } -.status-footer-container:not(.status-footer-container-open) .status-footer { +.status-footer-container[hidden] .status-footer { transform: translate(0, 100%); opacity: 0; - transition: transform var(--animation-duration) ease-in, opacity var(--animation-duration) ease-in; + transition: + transform var(--animation-duration) ease-in, + opacity var(--animation-duration) ease-in; } -.status-footer-container:not(.status-footer-container-open):not(.status-footer-container-opening):not(.status-footer-container-closing) { +.status-footer-container[hidden]:not(.hidden-animating) { display: none; } .status-footer-header { diff --git a/ext/bg/js/settings/popup-elements.js b/ext/bg/js/settings/popup-elements.js index 930f02cd..21a557bb 100644 --- a/ext/bg/js/settings/popup-elements.js +++ b/ext/bg/js/settings/popup-elements.js @@ -16,13 +16,11 @@ */ class PopupElement extends EventDispatcher { - constructor({node, visibleClassName, openingClassName, closingClassName, closingAnimationDuration}) { + constructor({node, closingAnimationDuration}) { super(); this._node = node; - this._visibleClassName = visibleClassName; - this._openingClassName = openingClassName; - this._closingClassName = closingClassName; this._closingAnimationDuration = closingAnimationDuration; + this._hiddenAnimatingClass = 'hidden-animating'; this._mutationObserver = null; this._visible = false; this._closeTimer = null; @@ -33,30 +31,31 @@ class PopupElement extends EventDispatcher { } isVisible() { - return this._node.classList.contains(this._visibleClassName); + return !this._node.hidden; } setVisible(value, animate=true) { value = !!value; - const {classList} = this._node; - if (classList.contains(this._visibleClassName) === value) { return; } + if (this.isVisible() === value) { return; } if (this._closeTimer !== null) { clearTimeout(this._closeTimer); - this._completeClose(classList, true); + this._completeClose(true); } + const node = this._node; + const {classList} = node; if (value) { - if (animate) { classList.add(this._openingClassName); } - getComputedStyle(this._node).getPropertyValue('display'); // Force update of CSS display property, allowing animation - classList.add(this._visibleClassName); - if (animate) { classList.remove(this._openingClassName); } - this._node.focus(); + if (animate) { classList.add(this._hiddenAnimatingClass); } + getComputedStyle(node).getPropertyValue('display'); // Force update of CSS display property, allowing animation + classList.remove(this._hiddenAnimatingClass); + node.hidden = false; + node.focus(); } else { - if (animate) { classList.add(this._closingClassName); } - classList.remove(this._visibleClassName); + if (animate) { classList.add(this._hiddenAnimatingClass); } + node.hidden = true; if (animate) { - this._closeTimer = setTimeout(() => this._completeClose(classList, false), this._closingAnimationDuration); + this._closeTimer = setTimeout(() => this._completeClose(false), this._closingAnimationDuration); } } } @@ -64,11 +63,11 @@ class PopupElement extends EventDispatcher { on(eventName, callback) { if (eventName === 'visibilityChanged') { if (this._mutationObserver === null) { - this._visible = this._node.classList.contains(this._visibleClassName); + this._visible = this.isVisible(); this._mutationObserver = new MutationObserver(this._onMutation.bind(this)); this._mutationObserver.observe(this._node, { attributes: true, - attributeFilter: ['class'], + attributeFilter: ['hidden'], attributeOldValue: true }); } @@ -90,15 +89,15 @@ class PopupElement extends EventDispatcher { // Private _onMutation() { - const visible = this._node.classList.contains(this._visibleClassName); + const visible = this.isVisible(); if (this._visible === visible) { return; } this._visible = visible; this.trigger('visibilityChanged', {visible}); } - _completeClose(classList, reopening) { + _completeClose(reopening) { this._closeTimer = null; - classList.remove(this._closingClassName); + this._node.classList.remove(this._hiddenAnimatingClass); this.trigger('closeCompleted', {reopening}); } } @@ -107,9 +106,6 @@ class Modal extends PopupElement { constructor(node) { super({ node, - visibleClassName: 'modal-container-open', - openingClassName: 'modal-container-opening', - closingClassName: 'modal-container-closing', closingAnimationDuration: 375 // Milliseconds; includes buffer }); this._contentNode = null; @@ -170,9 +166,6 @@ class StatusFooter extends PopupElement { constructor(node) { super({ node, - visibleClassName: 'status-footer-container-open', - openingClassName: 'status-footer-container-opening', - closingClassName: 'status-footer-container-closing', closingAnimationDuration: 375 // Milliseconds; includes buffer }); this._body = node.querySelector('.status-footer'); diff --git a/ext/bg/settings2.html b/ext/bg/settings2.html index ee2ae27e..a11383b5 100644 --- a/ext/bg/settings2.html +++ b/ext/bg/settings2.html @@ -1491,7 +1491,7 @@ -