Skip to content

Commit

Permalink
fix: render Lottie dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
tobi-bams committed Oct 7, 2024
1 parent e0835c4 commit 6de765c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
49 changes: 33 additions & 16 deletions src/components/App/Splash/SpiningSphere/index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
import { useEffect, useState } from 'react'
import Lottie from 'react-lottie'
import { Flex } from '~/components/common/Flex'
import preloadData from './preloader.json'

export const SphereAnimation = () => (
<Flex style={{ width: '167px', height: '167px', opacity: 0.5 }}>
<Lottie
height={167}
options={{
loop: true,
autoplay: true,
animationData: preloadData,
rendererSettings: {
preserveAspectRatio: 'xMidYMid slice',
},
}}
width={167}
/>
</Flex>
)
export const SphereAnimation = () => {
const [isReady, setIsReady] = useState(false)

useEffect(() => {
setIsReady(true)

return () => {
setIsReady(false)
}
}, [])

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

return (
<Flex style={{ width: '167px', height: '167px', opacity: 0.5 }}>
<Lottie
height={167}
options={{
loop: true,
autoplay: true,
animationData: preloadData,
rendererSettings: {
preserveAspectRatio: 'xMidYMid slice',
},
}}
width={167}
/>
</Flex>
)
}
3 changes: 2 additions & 1 deletion src/components/App/Splash/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useDataStore } from '~/stores/useDataStore'
import { colors, formatSplashMessage, formatStatsResponse } from '~/utils'
import { AnimatedTextContent } from './animated'
import { initialMessageData, Message } from './constants'
import { SphereAnimation } from './SpiningSphere'

export const Splash = () => {
const [message, setMessage] = useState<Message>(initialMessageData)
Expand Down Expand Up @@ -69,7 +70,7 @@ export const Splash = () => {
return (
<SplashWrapper>
<Wrapper align="center" direction="row" justify="center">
{/* <SphereAnimation /> */}
<SphereAnimation />
<Flex style={{ color: colors.white }}>
<TitleWrapper>
<Text className="title">{appMetaData?.title}</Text>
Expand Down

0 comments on commit 6de765c

Please sign in to comment.