react-spring
react-spring copied to clipboard
[feat]: trail onComplete event
A clear and concise description of what the feature is
A onComplete (or similar) event that triggers when ALL parts of a trail has completed. This is analogous to the onRest event on a single spring.
Why should this feature be included?
The onRest is a useful event for single springs. It would be great to have a similar event on trails.
Please provide an example for how this would work
onComplete should trigger when all springs from a single trail has reached rest.
I am achieving a similar effect by using the following code today.
const onComplete = () => console.log('trail completed')
const trail = useTrail(baseSquares.length, {
to: {"rotation-x": -Math.PI / 2},
from: {"rotation-x": 0},
onRest: (_, w) => {
if (w.springs["rotation-x"]._priority === offsets.length - 1) onComplete()
},
})
CSB https://codesandbox.io/s/quirky-visvesvaraya-8kbukr?file=/src/App.js