Git Product home page Git Product logo

Comments (4)

drcmda avatar drcmda commented on May 3, 2024

@AndreasFaust Each primitive can take in onRest and onFrame, the former triggers when the animation concludes, the latter triggers on every frame and gives you the current values. Keyframes are similar, internally they also just use these callbacks. The difference here is that keyframes can be awaited and chained, each promise yields the end-state values.

Try this:

console.log("start...")
return <Spring onFrame={v => console.log(v)} onRest={v => console.log("the end")} ...>

The start of the animation is yours anyway, since you are the one that triggers it by passing props to Spring.

As for transition, it has even deeper events:

<Transition
    keys={item => item.key}
    items={this.props.items}
    from={item => console.log(item, "starts"}
    enter={item => console.log(item, "enters"}
    leave={item => console.log(item, "leaves"}
    update={item => console.log(item, "updates"}
    onFrame={item, v => console.log(item, "animates to", v}
    onRest={item, v => console.log(item, "ends"} ...>

from react-spring.

AndreasFaust avatar AndreasFaust commented on May 3, 2024

Thank you very much for the quick reply!
I didn't know, that onFrame and onRest also apply to Transition. But how can I bind these events to certain Transition states only? I want to create a routing transition, where the next route is faded in, when the previous has faded out. For that I want to dispatch a redux action ("hasLeft") on "Transition leave rest" (and not "Transition enter rest"). To differ these states I could use the styles-property (if opacity === 0 for example), but that is not ideal. Or am I missing something?
I am asking, because in "React Move", I have been using in this case so far, these events exist.

from react-spring.

drcmda avatar drcmda commented on May 3, 2024

Actually i got that wrong myself, you're supposed to return the animation values in from/enter/leave/update, so that makes it possible to return individual values or listen to app state:

<Transition items={...} keys={...} from={...} enter={item => {
    if (this.props.something) return ({ opacity: item.opacity })
    else if (this.props.somethingElse) return ({ opacity: item.opacity / 2 })
    else return ({ color: 'red' })
}} ...>

Transition.onRest generally is limited when it's being used in transitions since they doesn't really have an end and a beginning (they just watch lifecycles). You can use it, but Transition itself uses onRest when the element leaves, so it will overwrite your handler in that case. Play around with it all for a while and look if it fulfills your usecase already, if not we can probably think of something to make it possible.

If you don't get any further, a very reduced codesandbox focussed on the problem at hand would be a good starting point.

from react-spring.

AndreasFaust avatar AndreasFaust commented on May 3, 2024

Thanks for explaining, you helped me a lot!
Have a nice weekend!

from react-spring.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.