Skip to content

Commit 88b70b8

Browse files
authored
Improve drop wave animation. (#3443)
* Improve drop wave animation. * Prettier
1 parent b3927ec commit 88b70b8

File tree

9 files changed

+86
-59
lines changed

9 files changed

+86
-59
lines changed

src/frontend/src/lib/components/backgrounds/FlairCanvas.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export interface FlairAnimationOptions {
2929
size: "large" | "medium" | "small" | number;
3030
nImpulses: "single" | "double";
3131
impulseEasing?: keyof typeof easingFunctions;
32-
containerHeight?: "h-full" | "h-[640px]";
3332
}
3433

3534
export interface FlairCanvasProps {
@@ -67,6 +66,7 @@ export interface FlairCanvasProps {
6766
maskWaveOneWay?: boolean;
6867
customColor?: string;
6968
customColorMode?: "all" | "moving";
69+
containerHeight?: string;
7070
triggerAnimation?: (opts: FlairAnimationOptions) => Promise<void>;
7171
clearAnimation?: () => void;
7272
}

src/frontend/src/lib/components/backgrounds/FlairCanvas.svelte

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import type { FlairCanvasProps, NodeMotion } from "./FlairCanvas";
2424
import { onMount } from "svelte";
2525
import * as easingFunctions from "svelte/easing";
26-
import { nonNullish } from "@dfinity/utils";
2726
2827
let {
2928
bgType = "dots",
@@ -54,12 +53,12 @@
5453
maskWaveOneWay = false,
5554
customColor,
5655
customColorMode,
56+
containerHeight,
5757
triggerAnimation = $bindable(),
5858
clearAnimation = $bindable(),
5959
}: FlairCanvasProps = $props();
6060
6161
// State for dynamic height during animations
62-
let animationHeight = $state<string | null>(null);
6362
let defaultHeight = "h-full"; // Default height
6463
6564
let backgroundRef = $state<HTMLDivElement>();
@@ -271,14 +270,8 @@
271270
size,
272271
nImpulses,
273272
impulseEasing,
274-
containerHeight,
275273
} = opts;
276274
277-
// Check whether the container height needs to change for this animation.
278-
if (nonNullish(containerHeight)) {
279-
animationHeight = containerHeight;
280-
}
281-
282275
let easingFunction = impulseEasing
283276
? easingFunctions[impulseEasing]
284277
: undefined;
@@ -588,8 +581,6 @@
588581
}
589582
590583
await Promise.all(promises);
591-
// Reset animation height to default after animation is done
592-
animationHeight = null;
593584
}
594585
};
595586
@@ -856,7 +847,7 @@
856847
</script>
857848

858849
<div
859-
class={`${animationHeight ?? defaultHeight} absolute inset-0
850+
class={`${containerHeight ?? defaultHeight} absolute inset-0
860851
-z-50 w-full select-none`}
861852
aria-hidden="true"
862853
bind:this={backgroundRef}

src/frontend/src/lib/components/backgrounds/WaveCanvas.svelte

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,28 @@
2323
});
2424
</script>
2525

26-
{#if !$isMobile}
27-
<FlairCanvas
28-
spacing="medium"
29-
aspect="ultrawide"
30-
dotSize="small"
31-
vignette="none"
32-
visibility="maskwave"
33-
maskWaveRampIn={0.001}
34-
maskWaveRampOut={0.5}
35-
maskWaveThickness="large"
36-
maskWaveMinValue={0}
37-
maskWaveSpeedMultiplier={2}
38-
maskWavePauseValue={0.25}
39-
maskWaveOneWay={true}
40-
enableRandomPointSize
41-
enableRandomOpacity={false}
42-
pointSizeNoiseScale="medium"
43-
pointSizeNoiseMultiplier="medium"
44-
springOrTween={{
45-
type: "spring",
46-
stiffness: "medium",
47-
dampening: "medium",
48-
}}
49-
bind:triggerAnimation
50-
bind:clearAnimation
51-
/>
52-
{/if}
26+
<FlairCanvas
27+
spacing="medium"
28+
aspect="ultrawide"
29+
dotSize="small"
30+
vignette="none"
31+
visibility="maskwave"
32+
maskWaveRampIn={0.001}
33+
maskWaveRampOut={0.5}
34+
maskWaveThickness="large"
35+
maskWaveMinValue={0}
36+
maskWaveSpeedMultiplier={2}
37+
maskWavePauseValue={0.25}
38+
maskWaveOneWay={true}
39+
enableRandomPointSize
40+
enableRandomOpacity={false}
41+
pointSizeNoiseScale="medium"
42+
pointSizeNoiseMultiplier="medium"
43+
springOrTween={{
44+
type: "spring",
45+
stiffness: "medium",
46+
dampening: "medium",
47+
}}
48+
bind:triggerAnimation
49+
bind:clearAnimation
50+
/>

src/frontend/src/lib/components/backgrounds/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ export const DROP_WAVE_ANIMATION: FlairAnimationOptions = {
99
nImpulses: "single",
1010
size: "large",
1111
impulseEasing: "cubicIn",
12-
containerHeight: "h-full",
1312
};

src/frontend/src/lib/components/layout/Header.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99

1010
<header
1111
{...props}
12-
class={["flex items-center px-3 md:px-6 lg:px-8", className]}
12+
class={[
13+
"from-bg-primary flex items-center bg-gradient-to-b to-transparent px-3 md:px-6 lg:px-8",
14+
className,
15+
]}
1316
>
1417
<div class="flex h-16 flex-1 items-center gap-4">
1518
<a href="/" class="flex items-center gap-4">

src/frontend/src/lib/components/layout/LandingHeader.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
<header
1010
{...props}
11-
class={["bg-bg-primary flex items-center px-0 md:px-6 lg:px-8", className]}
11+
class={[
12+
"to-bg-primary from-bg-primary flex items-center bg-gradient-to-b px-0 md:to-transparent md:px-6 lg:px-8",
13+
className,
14+
]}
1215
>
1316
<div class="flex min-h-16 flex-1 items-center gap-4">
1417
<Logo class="text-fg-primary h-5.5" />

src/frontend/src/routes/(new-styling)/+layout.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@
1313
</svelte:head>
1414

1515
{@render children()}
16-
<WaveCanvas />
16+
<!-- Hide global wave canvas on mobile -->
17+
<div class="max-md:hidden">
18+
<WaveCanvas />
19+
</div>
1720
<Toaster />

src/frontend/src/routes/(new-styling)/+page.svelte

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<script lang="ts">
22
import Footer from "$lib/components/layout/Footer.svelte";
3-
import { onMount } from "svelte";
4-
import {
5-
clearDropWaveAnimation,
6-
triggerDropWaveAnimation,
7-
} from "$lib/utils/animation-dispatcher";
83
import Button from "$lib/components/ui/Button.svelte";
94
import TextFade from "$lib/components/ui/TextFade.svelte";
105
import FullControlIllustration from "$lib/components/illustrations/landing/FullControlIllustration.svelte";
@@ -21,27 +16,59 @@
2116
import { t } from "$lib/stores/locale.store";
2217
import { LanguageSelector, Trans } from "$lib/components/locale";
2318
import { MinusCircleIcon, PlusCircleIcon } from "@lucide/svelte";
19+
import FlairCanvas from "$lib/components/backgrounds/FlairCanvas.svelte";
20+
import { DROP_WAVE_ANIMATION } from "$lib/components/backgrounds/constants";
21+
import type { FlairAnimationOptions } from "$lib/components/backgrounds/FlairCanvas";
2422
2523
// Add rerouting back on this SSG route
2624
manuallyReroute();
2725
28-
// Only trigger the drop wave animation 100ms after the page has loaded,
29-
// so we can cancel it if navigated to another route in that time window.
30-
onMount(() => {
31-
let cancelled = false;
32-
setTimeout(() => {
33-
if (!cancelled) {
34-
void triggerDropWaveAnimation({ containerHeight: "h-[640px]" });
35-
}
36-
}, 100);
26+
let triggerAnimation =
27+
$state<(opts: FlairAnimationOptions) => Promise<void>>();
28+
let clearAnimation = $state<() => void>();
29+
30+
$effect(() => {
31+
triggerAnimation?.(DROP_WAVE_ANIMATION);
3732
return () => {
38-
cancelled = true;
39-
void clearDropWaveAnimation();
33+
clearAnimation?.();
4034
};
4135
});
4236
</script>
4337

4438
<div class="flex min-h-[100dvh] flex-col">
39+
<div class="sm absolute top-0 right-0 left-0 -z-1 h-[640px] max-md:hidden">
40+
<!-- Render animation specific to landing page here instead of using global instance -->
41+
<FlairCanvas
42+
spacing="medium"
43+
aspect="ultrawide"
44+
dotSize="small"
45+
vignette="none"
46+
visibility="maskwave"
47+
maskWaveRampIn={0.001}
48+
maskWaveRampOut={0.5}
49+
maskWaveThickness="large"
50+
maskWaveMinValue={0}
51+
maskWaveSpeedMultiplier={2}
52+
maskWavePauseValue={0.25}
53+
maskWaveOneWay={true}
54+
enableRandomPointSize
55+
enableRandomOpacity={false}
56+
pointSizeNoiseScale="medium"
57+
pointSizeNoiseMultiplier="medium"
58+
springOrTween={{
59+
type: "spring",
60+
stiffness: "medium",
61+
dampening: "medium",
62+
}}
63+
containerHeight="h-[640px]"
64+
bind:triggerAnimation
65+
bind:clearAnimation
66+
/>
67+
<!-- This div fades out the bottom end of the background wave animation -->
68+
<div
69+
class="from-bg-primary pointer-events-none absolute right-0 bottom-0 left-0 h-[200px] bg-gradient-to-t to-transparent"
70+
></div>
71+
</div>
4572
<div class="h-[env(safe-area-inset-top)]"></div>
4673
<LandingHeader class="w-full flex-col md:flex-row">
4774
<div

src/frontend/src/routes/(new-styling)/authorize/(panel)/continue/+page.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import { slide, fade, scale } from "svelte/transition";
3333
import Dialog from "$lib/components/ui/Dialog.svelte";
3434
import EditAccount from "$lib/components/views/EditAccount.svelte";
35+
import { triggerDropWaveAnimation } from "$lib/utils/animation-dispatcher";
3536
import ProgressRing from "$lib/components/ui/ProgressRing.svelte";
3637
3738
const PRIMARY_ACCOUNT_NUMBER = undefined;
@@ -91,6 +92,7 @@
9192
}
9293
const { identityNumber, actor } = $authenticationStore!;
9394
const { effectiveOrigin } = $authorizationContextStore;
95+
void triggerDropWaveAnimation();
9496
await authorizationStore.authorize(
9597
defaultAccountNumber === null
9698
? actor
@@ -107,6 +109,7 @@
107109
accountNumber: AccountNumber | typeof PRIMARY_ACCOUNT_NUMBER,
108110
) => {
109111
try {
112+
void triggerDropWaveAnimation();
110113
await authorizationStore.authorize(accountNumber);
111114
} catch (error) {
112115
handleError(error);

0 commit comments

Comments
 (0)