Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(mobile): keep the launch bar frosted during a tab swipe
Elian Doranfb5a22be502a
diff --git a/apps/client/src/widgets/mobile_widgets/TabSwitcher.css b/apps/client/src/widgets/mobile_widgets/TabSwitcher.cssindex 230f77096c..c3bfc33eb0 100644--- a/apps/client/src/widgets/mobile_widgets/TabSwitcher.css+++ b/apps/client/src/widgets/mobile_widgets/TabSwitcher.css@@ -30,6 +30,28 @@ html[data-tab-slide] {view-transition-name: tab-launch-bar;}+ body.ios {+ #mobile-bottom-bar {+ view-transition-name: none;+ }++ #mobile-bottom-bar > #launcher-pane {+ view-transition-name: tab-launch-bar;+ }+ }++ &::view-transition-group(tab-launch-bar) {+ animation: none;+ }++ &::view-transition-old(tab-launch-bar) {+ display: none;+ }++ &::view-transition-new(tab-launch-bar) {+ animation: none;+ }+&::view-transition-group(tab-content) {background: color-mix(in srgb, var(--main-text-color) 20%, var(--main-background-color));}@@ -43,6 +65,17 @@ html[data-tab-slide] {}}+/* Safari bakes the bar's own `backdrop-filter` into its snapshot, so the group blurs the sliding content instead. */+html[data-tab-slide-captured] body.ios #mobile-bottom-bar > #launcher-pane {+ backdrop-filter: none;+}++html[data-tab-slide]:has(body.ios:not(.backdrop-effects-disabled))::view-transition-group(tab-launch-bar) {+ border-radius: calc(var(--launcher-pane-horiz-size) / 2);+ /* Must match `--dropdown-backdrop-filter` in theme-next/ios.css. */+ backdrop-filter: blur(16px) saturate(1.5) brightness(1.15);+}+html[data-tab-slide="left"] {&::view-transition-old(tab-content) { animation-name: tab-slide-out-left; }&::view-transition-new(tab-content) { animation-name: tab-slide-in-from-right; }diff --git a/apps/client/src/widgets/mobile_widgets/tab_swipe.spec.ts b/apps/client/src/widgets/mobile_widgets/tab_swipe.spec.tsindex 6f0a861e30..d66ad13619 100644--- a/apps/client/src/widgets/mobile_widgets/tab_swipe.spec.ts+++ b/apps/client/src/widgets/mobile_widgets/tab_swipe.spec.ts@@ -60,15 +60,20 @@ describe("TabSwipe", () => {const unrelated = animation(document.body, "");document.getAnimations = () => [ outgoing, incoming, unrelated ] as unknown as Animation[];+ /** Whether `data-tab-slide-captured` is set as the transition starts and as its hold ends. */+ const captured: string[] = [];+ const isCaptured = () => root.dataset.tabSlideCaptured !== undefined;let end = () => {};const finished = new Promise<void>((resolve) => { end = resolve; });document.documentElement.animate = vi.fn(() => ({cancel() {+ captured.push(`at end: ${isCaptured()}`);log.push("end");end();}})) as unknown as typeof root.animate;document.startViewTransition = ((update: () => Promise<void>) => {+ captured.push(`at start: ${isCaptured()}`);const updated = update();if (skipped) updated.then(end);return {@@ -76,17 +81,19 @@ describe("TabSwipe", () => {finished};}) as unknown as typeof document.startViewTransition;- return { outgoing, incoming, unrelated, finished };+ return { outgoing, incoming, unrelated, finished, captured, isCaptured };}it("follows the finger, then plays on to the other tab once released far enough", async () => {- const { outgoing, incoming, unrelated, finished } = fakeTransition();+ const { outgoing, incoming, unrelated, finished, captured, isCaptured } = fakeTransition();const swipe = new TabSwipe("next");expect(document.documentElement.dataset.tabSlide).toBe("left");expect(isTabSwipeActive()).toBe(true);await vi.waitFor(() => expect(outgoing.paused).toBe(true));expect(log).toEqual([ "activateNextTab" ]);+ // Marked only once the old state is captured, so the live page never paints with it.+ expect(isCaptured()).toBe(true);swipe.move(0.5);expect([ outgoing.currentTime, incoming.currentTime, unrelated.currentTime ]).toEqual([ 125, 125, 0 ]);@@ -108,6 +115,9 @@ describe("TabSwipe", () => {await vi.waitFor(() => expect(isTabSwipeActive()).toBe(false));expect(log).toEqual([ "activateNextTab", "end" ]);expect(document.documentElement.dataset.tabSlide).toBeUndefined();+ // Kept as the hold ends, since the snapshots stay up until the next frame removes them.+ expect(captured).toEqual([ "at start: false", "at end: true" ]);+ expect(isCaptured()).toBe(false);});it("runs back and switches back to the first tab, before the slide ends, when released short", async () => {diff --git a/apps/client/src/widgets/mobile_widgets/tab_swipe.ts b/apps/client/src/widgets/mobile_widgets/tab_swipe.tsindex f82375bf95..6c870f9880 100644--- a/apps/client/src/widgets/mobile_widgets/tab_swipe.ts+++ b/apps/client/src/widgets/mobile_widgets/tab_swipe.ts@@ -74,6 +74,8 @@ export class TabSwipe {// The browser renders no frames until the update finishes, so it must not wait for one; what// Preact renders later still shows, as the incoming side of the slide is live.const transition = document.startViewTransition(async () => {+ // Styles that only the snapshots can show, as the page behind the transition no longer paints.+ root.dataset.tabSlideCaptured = "";await appContext.triggerCommand(getCommand(this.direction));});this.transition = transition;@@ -87,6 +89,7 @@ export class TabSwipe {const cleanUp = () => {if (activeTransition !== transition) return;delete root.dataset.tabSlide;+ delete root.dataset.tabSlideCaptured;activeTransition = undefined;};transition.finished.then(cleanUp, cleanUp);@@ -128,6 +131,9 @@ export class TabSwipe {await new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));}this.hold?.cancel();+ // The snapshots stay up until the next frame removes them, and that frame paints the+ // revealed page after its `requestAnimationFrame()` callbacks run.+ requestAnimationFrame(() => delete document.documentElement.dataset.tabSlideCaptured);}/** Moves the slide to `target` on a critically damped spring, which settles without bouncing. */