recharts / react-smooth

react animation
MIT License
277 stars 38 forks source link

<Animate> componentWillReceiveProps should trigger state update immediatly #2

Closed zimond closed 8 years ago

zimond commented 8 years ago

Currently <Animate/> 's componentWillReceiveProps will start the manager to load the animation. In which a setTimeout is added to change styles.

A common situation could be:

  1. set <Animate> 's to -> state1, some static (out of the animation) value to -> value1

    Animate.state.style is state1 now

  2. set <Animate>'s from -> state2, to -> state3, the static value -> value2

Now Animate.state.style is state1. Because the .state.style update is triggered in the animationManager in a setTimeout, so it will be updated after current react update loop.

So in this loop, the children state will be (value2, state1), which is not desirable( should be (value2, state2)).

I think it's better to trigger a state update in Animate.componentWillReceiveProps to set current state to props.from, or maybe I've missed something?

jasonHzq commented 8 years ago

Yes, when you update the static value (out of the animation), react-smooth will not update the animation state immediately but in a setTimeout callback. I have fixed this now but I wonder why this is not desirable.

btw, the animationManager pattern is too complicated so I will refactor it soon using a simpler pattern.

Thank you very much!

zimond commented 8 years ago

Also may I ask why this module uses setTimeout instead of requestAnimationFrame?

jasonHzq commented 8 years ago

react-smooth use setTimeout to complete css animation and use requestAnimationFrame to complete js animation.

Thanks very much!

zimond commented 8 years ago

Thanks for the quick reply