I wrote a wrapper for <Motion/>, where it gets easy to build enter and leaving animations on single elements when prop changes.
It remember the prevProps and when the component receive newProps, it will render with prevProps, make the leaving animations, render again with newProps on enter animation.
-> component receive newProps
-> render with prevProps and execute leaving animation
-> render with newProps and execute enter animation
Related idea from #311 but different implementation I guess.
import {spring} from 'react-motion'; // probably you will use spring...
import MotionWrapper from 'path/to/MotionWrapper"';
<MotionWrapper
motionKey={...}
defaultEnterStyle={...}
enterStyle={...}
defaultLeaveStyle={...}
leaveStyle={...}
>
{interpolatingStyle => <div style={interpolatingStyle} />} //same children as in regular <Motion />
</MotionWrapper>
Improvement need
Rather then call setState inside a setTimeout, would be a lot better to call a callback in onRest when open === false and call setState inside it.
The problem was that I couldnt get it to rerender after call setState inside it.
Motivation
I wrote a wrapper for
<Motion/>
, where it gets easy to build enter and leaving animations on single elements when prop changes.It remember the prevProps and when the component receive newProps, it will render with prevProps, make the leaving animations, render again with newProps on enter animation.
Related idea from #311 but different implementation I guess.
Code
Usage
Improvement need
Rather then call
setState
inside asetTimeout
, would be a lot better to call a callback inonRest
whenopen === false
and callsetState
inside it.The problem was that I couldnt get it to rerender after call
setState
inside it.like the problem in #322
like this:
it actually will work if remove
motionKey
from this leaving component, but will be a big delay between end animation and setState, I didnt understand!Any ideas?
Update
Did find out that the delay was caused by precision 0.1, increasing precision, there is no delay.