Skip to content

Commit

Permalink
fix: convert sphere animation to user lottie web rather than react lo…
Browse files Browse the repository at this point in the history
…ttie
  • Loading branch information
tobi-bams committed Oct 7, 2024
1 parent 0569852 commit fb9a7d5
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/components/App/Splash/SpiningSphere/index.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
import { useEffect, useState } from 'react'
import Lottie from 'react-lottie'
import lottie, { AnimationItem } from 'lottie-web'
import { Flex } from '~/components/common/Flex'
import * as preloadData from './preloader.json'

import { useEffect, useRef } from 'react'
import preloadData from './preloader.json'

export const SphereAnimation = () => {
const [isReady, setIsReady] = useState(false)
const lottieRef = useRef<AnimationItem | null>(null)

useEffect(() => {
setIsReady(true)
const container = document.getElementById('lottie-sphere-animation')

if (container) {
lottieRef.current = lottie.loadAnimation({
container,
animationData: preloadData,
loop: true,
autoplay: true,
rendererSettings: {
preserveAspectRatio: 'xMidYMid slice',
},
})
}

return () => {
setIsReady(false)
if (lottieRef.current) {
lottieRef?.current?.destroy()
}
}
}, [])

if (!isReady) {
return <></>
}

return (
<Flex style={{ width: '167px', height: '167px', opacity: 0.5 }}>
<Lottie
<Flex id="lottie-sphere-animation" style={{ width: '167px', height: '167px', opacity: 0.5 }}>
{/* <Lottie
height={167}
options={{
loop: true,
Expand All @@ -31,7 +42,7 @@ export const SphereAnimation = () => {
},
}}
width={167}
/>
/> */}
</Flex>
)
}

0 comments on commit fb9a7d5

Please sign in to comment.