Backpack UI
Components
Lottie Player

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:


_10
import { LottiePlayer } from '@ef-global/backpack/LottiePlayer';

Props

The LottiePlayer component accepts the following props:

PropTypeDescription
srcstring | LottieJsonLottie animation source data or URL.
autoplaybooleanWhether the animation should autoplay. Default is false.
loopboolean | numberWhether the animation should loop. Default is false.
keepLastFramebooleanWhether to keep the last frame when the animation is stopped. Default is false.
speednumberAnimation playback speed. Default is 1.
onEvent(event: LottieEvent) => void | undefinedEvent 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


_12
import React, { useRef } from 'react';
_12
import { LottiePlayer } from '@/src/components/LottiePlayer';
_12
import { Button, ButtonGroup } from '@/src/components/Button';
_12
_12
const 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
/>