Created
July 13, 2015 18:58
-
-
Save bsansouci/0d3c0830173918d65e08 to your computer and use it in GitHub Desktop.
Example of how to have two animations back to back
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component} from 'react'; | |
import {TransitionSpring} from '../Spring'; | |
import {clone} from '../utils'; | |
const defaultTickAmount = 100; | |
const constConfig = [120, 10]; | |
class Demo extends Component { | |
state = { | |
someData: ["a", "b", "c", "d"] | |
} | |
onClick() { | |
this.setState({ | |
someData: ["b", "c"] | |
}); | |
} | |
willLeaveOutter(key, endValue, currVals, currVelocity) { | |
if(currVals[key].top.val === defaultTickAmount && currVelocity[key].top.val === 0) { | |
return null; | |
} | |
return { | |
top: {val: defaultTickAmount, config: constConfig} | |
}; | |
} | |
willLeaveInner(key, endValue, currVals) { | |
if(currVals[key].opacity.val === 0) { | |
return null; | |
} | |
return { | |
...currVals[key], | |
opacity: {val: 0} | |
}; | |
} | |
endValueOutter() { | |
let {someData} = this.state; | |
let config = {}; | |
someData.map(key => { | |
config[key] = { | |
top: {val: 0, config: constConfig} | |
}; | |
}); | |
return config; | |
} | |
render() { | |
return ( | |
<TransitionSpring | |
endValue={::this.endValueOutter} | |
willLeave={::this.willLeaveOutter}> | |
{outterCurrVals => | |
<TransitionSpring | |
endValue={() => { | |
let config = {}; | |
Object.keys(outterCurrVals).map(key => { | |
config[key] = { | |
...outterCurrVals[key], | |
opacity: {val: 1} | |
}; | |
}); | |
return config; | |
}} | |
willLeave={::this.willLeaveInner}> | |
{innerCurrVals => | |
Object.keys(innerCurrVals).map((key, i) => | |
<div | |
key={key} | |
onClick={::this.onClick} | |
style={{ | |
opacity: innerCurrVals[key].opacity.val, | |
left: (innerCurrVals[key].top ? innerCurrVals[key].top.val : defaultTickAmount) + 100, | |
top: i * 20 + 100, | |
position: "absolute" | |
}}> | |
{key} | |
</div> | |
) | |
} | |
</TransitionSpring> | |
} | |
</TransitionSpring> | |
); | |
} | |
} | |
export default Demo; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment