Skip to content

Instantly share code, notes, and snippets.

@devknoll
Last active September 22, 2016 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devknoll/b4aefa3155f60da9c05e to your computer and use it in GitHub Desktop.
Save devknoll/b4aefa3155f60da9c05e to your computer and use it in GitHub Desktop.
class BounceOnMount extends React.Component {
constructor(props: any) {
super(props);
this.state = {
bounceValue: new Animated.Value(props.start),
};
}
render(): ReactElement {
return this.props.children(this.state.bounceValue);
}
componentDidMount() {
Animated.spring(
this.state.bounceValue,
{
toValue: this.props.end,
friction: this.props.friction,
}
).start();
}
}
class Playground extends React.Component {
render(): ReactElement {
return (
<BounceOnMount start={1.5} end={0.8} friction={0.8}>
{bounceValue => (
<Animated.Image
source={{uri: 'http://i.imgur.com/XMKOH81.jpg'}}
style={{
flex: 1,
transform: [
{scale: bounceValue},
]
}}
/>
)}
</Bounce>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment