Skip to content

Instantly share code, notes, and snippets.

@kyle-ssg
Created February 20, 2017 10:17
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 kyle-ssg/cb6d0d4d805a3fb74b68b88196e1ff00 to your computer and use it in GitHub Desktop.
Save kyle-ssg/cb6d0d4d805a3fb74b68b88196e1ff00 to your computer and use it in GitHub Desktop.
animates opacity on press
const Animation = class extends Component {
displayName: 'Animation'
constructor (props, context) {
super(props, context);
this.state = { opacity: 1 };
}
toggleFade = () => {
//toggle opacity
this.animate(this.state.opacity ? 0.5 : 1)
}
animate = (toValue) => {
LayoutAnimation.easeInEaseOut();
this.setState({ opacity: toValue })
}
render () {
return (
<TouchableOpacity activeOpacity={1} onPressIn={this.toggleFade}>
<Text style={{opacity:this.state.opacity}}>
Hi
</Text>
</TouchableOpacity>
);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment