Last active
September 22, 2016 17:59
-
-
Save devknoll/b4aefa3155f60da9c05e to your computer and use it in GitHub Desktop.
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
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(); | |
} | |
} |
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
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