Skip to content

Commit

Permalink
fix(lottie-react): create component to render lottie on client only
Browse files Browse the repository at this point in the history
  • Loading branch information
rockingrohit9639 committed Dec 13, 2024
1 parent aa15985 commit 3c5fcfd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
12 changes: 12 additions & 0 deletions app/components/zxing-scanner/success-animation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Lottie from "lottie-react";
import successfullScanAnimation from "../../lottie/success-scan.json";

export default function SuccessAnimation() {
return (
<Lottie
animationData={successfullScanAnimation}
loop={false}
style={{ width: 200, height: 200 }}
/>
);
}
14 changes: 5 additions & 9 deletions app/components/zxing-scanner/zxing-scanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import {
useNavigation,
useRouteLoaderData,
} from "@remix-run/react";
import Lottie from "lottie-react";
import { useZxing } from "react-zxing";

import { ClientOnly } from "remix-utils/client-only";
import type { LayoutLoaderResponse } from "~/routes/_layout+/_layout";
import { ShelfError } from "~/utils/error";
import { isFormProcessing } from "~/utils/form";
import { isQrId } from "~/utils/id";
import { tw } from "~/utils/tw";
import SuccessAnimation from "./success-animation";
import {
Select,
SelectContent,
Expand All @@ -22,7 +23,6 @@ import {
} from "../forms/select";
import Icon from "../icons/icon";
import { Spinner } from "../shared/spinner";
import successfullScanAnimation from "./../../lottie/success-scan.json";

type ZXingScannerProps = {
onQrDetectionSuccess?: (qrId: string, error?: string) => void | Promise<void>;
Expand Down Expand Up @@ -205,13 +205,9 @@ export const ZXingScanner = ({
{paused && (
<div className="flex h-full flex-col items-center justify-center p-4 text-center">
<h5>Code detected</h5>
<div>
<Lottie
animationData={successfullScanAnimation}
loop={false}
style={{ width: 200, height: 200 }}
/>
</div>
<ClientOnly fallback={null}>
{() => <SuccessAnimation />}
</ClientOnly>
<p>Scanner paused</p>
</div>
)}
Expand Down

0 comments on commit 3c5fcfd

Please sign in to comment.