From 097404b3d1e9a9960d416afdfed388486ff4f7d6 Mon Sep 17 00:00:00 2001 From: "mr. M" Date: Sat, 11 Jan 2025 17:25:42 +0100 Subject: [PATCH] Refactor tab animation logic to improve workspace transitions and remove unused CSS animations --- .../content/zen-styles/zen-animations.css | 22 ------- .../zen-styles/zen-tabs/vertical-tabs.css | 17 ----- .../zen-components/ZenGradientGenerator.mjs | 2 +- .../base/zen-components/ZenWorkspaces.mjs | 66 +++++++++++++++---- 4 files changed, 53 insertions(+), 54 deletions(-) diff --git a/src/browser/base/content/zen-styles/zen-animations.css b/src/browser/base/content/zen-styles/zen-animations.css index 05341ea00..09b31494c 100644 --- a/src/browser/base/content/zen-styles/zen-animations.css +++ b/src/browser/base/content/zen-styles/zen-animations.css @@ -100,28 +100,6 @@ } } -@keyframes zen-slide-in { - from { - transform: translateX(-150%); - opacity: 0; - } - to { - transform: translateX(0); - opacity: 1; - } -} - -@keyframes zen-slide-in-reverse { - from { - transform: translateX(150%); - opacity: 0; - } - to { - transform: translateX(0); - opacity: 1; - } -} - @keyframes zen-deck-fadeIn { 0% { transform: scale(0.9); diff --git a/src/browser/base/content/zen-styles/zen-tabs/vertical-tabs.css b/src/browser/base/content/zen-styles/zen-tabs/vertical-tabs.css index 3842d0db9..10cabe683 100644 --- a/src/browser/base/content/zen-styles/zen-tabs/vertical-tabs.css +++ b/src/browser/base/content/zen-styles/zen-tabs/vertical-tabs.css @@ -242,23 +242,6 @@ & .tabbrowser-tab { transition: scale 0.07s ease; #tabbrowser-tabs &:not([zen-essential='true']) { - #tabbrowser-tabs[zen-workspace-animation='previous'] & { - animation: zen-slide-in; - } - - #tabbrowser-tabs[zen-workspace-animation='next'] & { - animation: zen-slide-in-reverse; - } - - #tabbrowser-tabs[zen-workspace-animation] & { - opacity: 0; - transform: translateX(-100%); - animation-delay: 0.2s; - animation-fill-mode: forwards; - animation-duration: 0.2s; - animation-timing-function: ease; - } - #tabbrowser-tabs[dont-animate-tabs] & { opacity: 0; } diff --git a/src/browser/base/zen-components/ZenGradientGenerator.mjs b/src/browser/base/zen-components/ZenGradientGenerator.mjs index 15b22e43b..24b1c53d0 100644 --- a/src/browser/base/zen-components/ZenGradientGenerator.mjs +++ b/src/browser/base/zen-components/ZenGradientGenerator.mjs @@ -658,7 +658,7 @@ setTimeout(() => { // Reactivate the transition after the animation appWrapper.removeAttribute('post-animating'); - }); + }, 100); }, 700); }); } diff --git a/src/browser/base/zen-components/ZenWorkspaces.mjs b/src/browser/base/zen-components/ZenWorkspaces.mjs index b217a2b60..6540a7b19 100644 --- a/src/browser/base/zen-components/ZenWorkspaces.mjs +++ b/src/browser/base/zen-components/ZenWorkspaces.mjs @@ -1292,6 +1292,19 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature { // Refresh tab cache this.tabContainer._invalidateCachedTabs(); + let animationDirection; + if (previousWorkspace && !onInit && !this._animatingChange) { + animationDirection = ( + workspaces.workspaces.findIndex((w) => w.uuid === previousWorkspace.uuid) < + workspaces.workspaces.findIndex((w) => w.uuid === window.uuid) + ) ? 'right' : 'left'; + } + if (animationDirection) { + // Animate tabs out of view before changing workspace, therefor we + // need to animate in the opposite direction + await this._animateTabs(animationDirection === 'left' ? 'right' : 'left', true); + } + // First pass: Handle tab visibility and workspace ID assignment const visibleTabs = this._processTabVisibility(window.uuid, containerId, workspaces); @@ -1301,23 +1314,48 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature { // Update UI and state await this._updateWorkspaceState(window, onInit); - // Animate acordingly - if (previousWorkspace && !this._animatingChange) { - // we want to know if we are moving forward or backward in sense of animation - let isNextWorkspace = - onInit || - workspaces.workspaces.findIndex((w) => w.uuid === previousWorkspace.uuid) < - workspaces.workspaces.findIndex((w) => w.uuid === window.uuid); - gBrowser.tabContainer.setAttribute('zen-workspace-animation', isNextWorkspace ? 'next' : 'previous'); - this.tabContainer.removeAttribute('dont-animate-tabs'); - this._animatingChange = true; - setTimeout(() => { - this._animatingChange = false; - gBrowser.tabContainer.removeAttribute('zen-workspace-animation'); - }, 600); + if (animationDirection) { + await this._animateTabs(animationDirection); } } + async _animateTabs(direction, out = false) { + const tabs = gBrowser.visibleTabs.filter((tab) => !tab.hasAttribute('zen-essential')); + return new Promise((resolve) => { + let count = 0; + const onAnimationEnd = () => { + count++; + if (count >= tabs.length) { + resolve(); + } + }; + this.tabContainer.removeAttribute('dont-animate-tabs'); + if (out) { + for (let tab of tabs) { + tab.animate([ + { transform: 'translateX(0)' }, + { transform: `translateX(${direction === 'left' ? '-' : ''}100%)` }, + ], { + duration: 150, + easing: 'ease', + fill: 'both', + }).onfinish = onAnimationEnd; + } + return; + } + for (let tab of tabs) { + tab.animate([ + { transform: `translateX(${direction === 'left' ? '-' : ''}100%)` }, + { transform: 'translateX(0)' }, + ], { + duration: 150, + easing: 'ease', + fill: 'both', + }).onfinish = onAnimationEnd; + } + }); + } + _processTabVisibility(workspaceUuid, containerId, workspaces) { const visibleTabs = new Set(); const lastSelectedTab = this._lastSelectedWorkspaceTabs[workspaceUuid];