[feat]: trail onComplete event

Open
#1,986 0 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
react, typescript
Domain
frontend

Research direction

Start by tracing the useTrail API and its existing onRest behavior, using the linked CodeSandbox as the behavioral example. Define completion for a trail as the point when all springs from one trail have reached rest, and verify that the new event fires once for that condition.

Written by the indexing model from the issue text.

Description

template: request
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

Dominant language
TypeScript
Stars
29.3k
Forks
1.2k
Avg merge
3d 15h
Merged PRs (30d)
17

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pmndrs/react-spring

All issues in pmndrs/react-spring

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.