dotlottie / player-component

https://dotlottie.io
MIT License
206 stars 28 forks source link

Add animationData as property #88

Closed gtolarc closed 1 year ago

gtolarc commented 1 year ago

For performance reasons, I'd like to load the dotLottie files in advance and use them immediately when needed. For now, there doesn't seem to be a workaround other than to hide dotlottie-player before use.

https://github.com/dotlottie/player-component/blob/master/src/dotlottie-player.ts#L47 https://github.com/dotlottie/player-component/blob/master/src/dotlottie-player.ts#L318

If there is an animationData property, I think we could use the fetchPath function to fetch it in advance and use it when we want, is it possible to add this feature?

samuelOsborne commented 1 year ago

@gtolarc If you're fetching the dotLotties yourself, you could do something like this:

<Fetch files etc...>
        if (playerRef.current) {
          playerRef.current.load(animationData);
        }

        return({
                {lottieData && (
            <dotlottie-player
              ref={playerRef}
              autoplay
              loop
            >
            </dotlottie-player>
        )
        }
    })
gtolarc commented 1 year ago

I know the way you're talking about from the documentation.

I want to do preloading without the dotlottie-player DOM being present, so it would be really useful to be able to take animationData as an property, what do you think?

gtolarc commented 1 year ago

I misunderstood what you said. I've verified that it works. @samuelOsborne