Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/components/Lottie/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -19,6 +19,12 @@ function Lottie({source, webStyle, ...props}: Props, ref: ForwardedRef<LottieVie

useNetwork({onReconnect: () => setIsError(false)});

const [animationFile, setAnimationFile] = useState<string | AnimationObject | {uri: string}>();

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
Expand All @@ -28,17 +34,17 @@ function Lottie({source, webStyle, ...props}: Props, ref: ForwardedRef<LottieVie
return <View style={[aspectRatioStyle, props.style]} />;
}

return (
return animationFile ? (
<LottieView
Comment on lines +37 to 38

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return animationFile ? (
<LottieView
if (!animationFile) {
return null;
}

We can update it to early return

// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
source={source.file}
source={animationFile}
ref={ref}
style={[aspectRatioStyle, props.style]}
webStyle={{...aspectRatioStyle, ...webStyle}}
onAnimationFailure={() => setIsError(true)}
/>
);
) : null;
}

Lottie.displayName = 'Lottie';
Expand Down