LottiePlayer
LottiePlayer is a thin wrapper around the lottie-react (opens in a new tab) library. It provides a convenient and easy way to integrate Lottie animations into your React application.
Importing
To use the LottiePlayer component, import it as follows:
_10import { LottiePlayer } from '@ef-global/backpack/LottiePlayer';
Props
The LottiePlayer component accepts the following props:
| Prop | Type | Description |
| src | string | LottieJson | Lottie animation source data or URL. |
| autoplay | boolean | Whether the animation should autoplay. Default is false. |
| loop | boolean | number | Whether the animation should loop. Default is false. |
| keepLastFrame | boolean | Whether to keep the last frame when the animation is stopped. Default is false. |
| speed | number | Animation playback speed. Default is 1. |
| onEvent | (event: LottieEvent) => void | undefined | Event listener for Lottie animation events. |
Usage
Here are some examples of how to use the LottiePlayer component:
Default
_10<LottiePlayer src={Attention} />
Autoplay
_10<LottiePlayer src={House} autoplay={true} />
Loop
_10<LottiePlayer src={AirplaneWindow} autoplay={true} loop={true} />
External Controls
_12import React, { useRef } from 'react';_12import { LottiePlayer } from '@/src/components/LottiePlayer';_12import { Button, ButtonGroup } from '@/src/components/Button';_12_12const playerRef = useRef(null);_12_12<LottiePlayer ref={playerRef} src={Bicycle} autoplay={true} loop={true} />_12<ButtonGroup align={'center'}>_12 <Button as={'button'} onPress={() => playerRef.current.play()}>Play</Button>_12 <Button as={'button'} onPress={() => playerRef.current.pause()}>Pause</Button>_12 <Button as={'button'} onPress={() => playerRef.current.stop()}>Stop</Button>_12</ButtonGroup>
Keep Last Frame
_10<LottiePlayer src={Bookshelf} autoplay={true} keepLastFrame={true} />
Set Speed
_10<LottiePlayer src={Bus} autoplay={true} loop={true} speed={2} />
Log Events
_10<LottiePlayer_10 src={Backpacker}_10 autoplay={true}_10 loop={true}_10 onEvent={(event) => {_10 if (event !== 'frame') console.log(event);_10 }}_10/>