Skip to content

Commit b176a97

Browse files
committed
animation: unify lightning and thunderstorm components
Replace the old Lightning bolt renderer with the Thunderstorm component, which now supports both strike mode (single bolt for zaps) and full storm mode (clouds, fog, multiple bolts for wallet send success). - Add strike intensity that fires a single bolt without clouds/fog/flash - Convert StormBolt to ES class with configurable presets (BOLT_STORM vs BOLT_STRIKE) matching original visual behavior of each - Delta-time all animation: bolt growth, fade, flash, cloud drift, and strike chance are now frame-rate independent - Use Path2D for bolt segments instead of replaying all draw calls - Add ThunderstormProvider/useThunderstrike hook (replaces class-based LightningProvider) - useAnimationEnabled defaults to off when prefers-reduced-motion is active; useAnimation respects the same default - Reduced-motion users get immediate dismiss for all intensities - Recursive isTreeDone check prevents grandchild bolts from vanishing mid-fade - Stabilize onDone via ref to prevent spurious re-fires - Delete components/animation/lightning.js
1 parent 87fe98d commit b176a97

5 files changed

Lines changed: 635 additions & 175 deletions

File tree

components/animation/index.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,37 @@ import { useCallback, useEffect, useState } from 'react'
22
import { useMe } from '@/components/me'
33
import { randInRange } from '@/lib/rand'
44

5-
import { LightningProvider, useLightning } from './lightning'
6-
// import { SnowProvider, useSnow } from './snow'
7-
8-
const [SelectedAnimationProvider, useSelectedAnimation] = [
9-
LightningProvider, useLightning
10-
// SnowProvider, useSnow // TODO: the snow animation doesn't seem to work anymore
11-
]
5+
import { ThunderstormProvider, useThunderstrike } from '@/components/thunderstorm/provider'
126

137
export function AnimationProvider ({ children }) {
148
return (
15-
<SelectedAnimationProvider>
9+
<ThunderstormProvider>
1610
<AnimationHooks>
1711
{children}
1812
</AnimationHooks>
19-
</SelectedAnimationProvider>
13+
</ThunderstormProvider>
2014
)
2115
}
2216

2317
export function useAnimation () {
24-
const animate = useSelectedAnimation()
18+
const strike = useThunderstrike()
2519

2620
return useCallback(() => {
27-
const should = window.localStorage.getItem('lnAnimate') || 'yes'
28-
if (should !== 'yes') return false
29-
animate()
21+
if (!getAnimationDefault()) return false
22+
strike()
3023
return true
31-
}, [animate])
24+
}, [strike])
3225
}
3326

34-
export function useAnimationEnabled () {
35-
const [enabled, setEnabled] = useState(undefined)
27+
function getAnimationDefault () {
28+
if (typeof window === 'undefined') return undefined
29+
const stored = window.localStorage.getItem('lnAnimate')
30+
if (stored) return stored === 'yes'
31+
return !window.matchMedia('(prefers-reduced-motion: reduce)').matches
32+
}
3633

37-
useEffect(() => {
38-
const enabled = window.localStorage.getItem('lnAnimate') || 'yes'
39-
setEnabled(enabled === 'yes')
40-
}, [])
34+
export function useAnimationEnabled () {
35+
const [enabled, setEnabled] = useState(getAnimationDefault)
4136

4237
const toggleEnabled = useCallback(() => {
4338
setEnabled(enabled => {

components/animation/lightning.js

Lines changed: 0 additions & 155 deletions
This file was deleted.

0 commit comments

Comments
 (0)