I am using the react-bodymovin package (https://www.npmjs.com/package/react-bodymovin) to embed a Bodymovin animation, but I wanted to loop a section of the animation after it has played through once.
I can see is simple using the HTML version of Bodymovin, as you simply use the relevant methods to do this, for example, (assuming the div has ID bodymovin
:
const params = {
container: document.getElementById('bodymovin'),
renderer: 'svg',
loop: false,
autoplay: false,
animationData: animationData,
}
const anim = bodymovin.loadAnimation(params)
anim.playSegments([[0, 65]], true)
However, I am not sure how to access these same methods when using the React component. Here is my component:
import React from 'react'
import ReactBodymovin from 'react-bodymovin'
import animation from './animation.json'
const App = () => {
const bodymovinOptions = {
loop: true,
autoplay: true,
prerender: true,
animationData: animation
}
return (
<div>
<ReactBodymovin options={bodymovinOptions} />
</div>
)
}
I have a feeling that due to the nature of the way this React wrapper works with Bodymovin, it may not be possible to access the methods within the file, but if anyone knows a way to do this, i would love to hear it. Thanks.