From ff3e35ac2a37470e3ffe3dec4579ce51786d2b4a Mon Sep 17 00:00:00 2001 From: ShridharGoel <35566748+ShridharGoel@users.noreply.github.com> Date: Thu, 11 Jul 2024 02:00:21 +0530 Subject: [PATCH 1/2] Fix page stability issue on animation load --- src/components/Lottie/index.tsx | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/components/Lottie/index.tsx b/src/components/Lottie/index.tsx index 6395a715f339..a49fdbd3690b 100644 --- a/src/components/Lottie/index.tsx +++ b/src/components/Lottie/index.tsx @@ -1,7 +1,7 @@ -import type {LottieViewProps} from 'lottie-react-native'; +import type {AnimationObject, LottieViewProps} from 'lottie-react-native'; import LottieView from 'lottie-react-native'; import type {ForwardedRef} from 'react'; -import React, {forwardRef} from 'react'; +import React, {forwardRef, useEffect, useState} from 'react'; import {View} from 'react-native'; import type DotLottieAnimation from '@components/LottieAnimations/types'; import useAppState from '@hooks/useAppState'; @@ -19,6 +19,12 @@ function Lottie({source, webStyle, ...props}: Props, ref: ForwardedRef setIsError(false)}); + const [animationFile, setAnimationFile] = useState(); + + useEffect(() => { + setAnimationFile(source.file); + }, [setAnimationFile, source.file]); + const aspectRatioStyle = styles.aspectRatioLottie(source); // If the image fails to load or app is in background state, we'll just render an empty view @@ -28,17 +34,15 @@ function Lottie({source, webStyle, ...props}: Props, ref: ForwardedRef; } - return ( - setIsError(true)} - /> - ); + return animationFile ? setIsError(true)} + /> : null } Lottie.displayName = 'Lottie'; From e50197aa788ff51f940590c8cc512dd14df34acf Mon Sep 17 00:00:00 2001 From: ShridharGoel <35566748+ShridharGoel@users.noreply.github.com> Date: Thu, 11 Jul 2024 02:27:33 +0530 Subject: [PATCH 2/2] Lint fixes --- src/components/Lottie/index.tsx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/components/Lottie/index.tsx b/src/components/Lottie/index.tsx index a49fdbd3690b..a9b223a87a54 100644 --- a/src/components/Lottie/index.tsx +++ b/src/components/Lottie/index.tsx @@ -34,15 +34,17 @@ function Lottie({source, webStyle, ...props}: Props, ref: ForwardedRef; } - return animationFile ? setIsError(true)} - /> : null + return animationFile ? ( + setIsError(true)} + /> + ) : null; } Lottie.displayName = 'Lottie';